From b625a5d7e491e64293529f71f22da0c1898e25c9 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Wed, 13 Dec 2023 00:12:48 +0100 Subject: [PATCH] style: Fix font-size: {inherit,unset} For all other properties, these keywords are handled by StyledNode::get_raw_property, but font-size is special as it needs to know the node its value originated from. --- style/styled_node.cpp | 2 +- style/styled_node_test.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/style/styled_node.cpp b/style/styled_node.cpp index 42d63086..27adb8c4 100644 --- a/style/styled_node.cpp +++ b/style/styled_node.cpp @@ -437,7 +437,7 @@ int StyledNode::get_font_size_property() const { auto it = std::ranges::find_if(rbegin(n->properties), rend(n->properties), [](auto const &v) { return v.first == css::PropertyId::FontSize; }); - if (it != rend(n->properties)) { + if (it != rend(n->properties) && it->second != "inherit" && it->second != "unset") { return {{it->second, n}}; } } diff --git a/style/styled_node_test.cpp b/style/styled_node_test.cpp index 34faacec..86e65d28 100644 --- a/style/styled_node_test.cpp +++ b/style/styled_node_test.cpp @@ -190,6 +190,12 @@ int main() { expect_eq(child.get_property(), 10); expect_eq(root.get_property(), 50); + // inherit, unset + child.properties[0] = {css::PropertyId::FontSize, "unset"}; + expect_eq(child.get_property(), 50); + child.properties[0] = {css::PropertyId::FontSize, "inherit"}; + expect_eq(child.get_property(), 50); + // % child.properties[0] = {css::PropertyId::FontSize, "100%"}; expect_eq(child.get_property(), 50);