diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-08-12 17:36:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-18 10:32:32 +0200 |
commit | ceece1c75e18fdfffb41670a1500b5c333f2f309 (patch) | |
tree | f7fde499702cae97f5a4806d5228d9974a5c2ce5 | |
parent | 3c541452b7af5109c84c9a6e444c58f8ac4b39cb (diff) | |
download | serenity-ceece1c75e18fdfffb41670a1500b5c333f2f309.zip |
LibWeb: Handle numeric font-weights
The code was assuming the font-weight would be a Length, apparently
since NumericStyleValue didn't exist at the time. Now, it's always a
numeric value, so treat it as such.
We also replace the hardcoded numbers with references to the FontWeight
enum.
Also, it was always setting the weight to 900, so that has been fixed.
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleProperties.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index e02eb24e77..90d34e9567 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -102,7 +102,6 @@ void StyleProperties::load_font(Layout::Node const& node) const auto family = family_parts[0]; auto monospace = false; - auto bold = false; if (family.is_one_of("monospace", "ui-monospace")) { monospace = true; @@ -111,37 +110,38 @@ void StyleProperties::load_font(Layout::Node const& node) const family = "Katica"; } - int weight = 400; + int weight = Gfx::FontWeight::Regular; if (font_weight->is_identifier()) { switch (static_cast<const IdentifierStyleValue&>(*font_weight).id()) { case CSS::ValueID::Normal: - weight = 400; + weight = Gfx::FontWeight::Regular; break; case CSS::ValueID::Bold: - weight = 700; + weight = Gfx::FontWeight::Bold; break; case CSS::ValueID::Lighter: // FIXME: This should be relative to the parent. - weight = 400; + weight = Gfx::FontWeight::Regular; break; case CSS::ValueID::Bolder: // FIXME: This should be relative to the parent. - weight = 700; + weight = Gfx::FontWeight::Bold; break; default: break; } - } else if (font_weight->is_length()) { - // FIXME: This isn't really a length, it's a numeric value.. - int font_weight_integer = font_weight->to_length().raw_value(); - if (font_weight_integer <= 400) - weight = 400; - if (font_weight_integer <= 700) - weight = 700; - weight = 900; + } else if (font_weight->is_numeric()) { + int font_weight_integer = roundf(static_cast<NumericStyleValue const&>(*font_weight).value()); + if (font_weight_integer <= Gfx::FontWeight::Regular) + weight = Gfx::FontWeight::Regular; + else if (font_weight_integer <= Gfx::FontWeight::Bold) + weight = Gfx::FontWeight::Bold; + else + weight = Gfx::FontWeight::Black; } + // FIXME: calc() for font-weight - bold = weight > 400; + bool bold = weight > Gfx::FontWeight::Regular; int size = 10; auto parent_font_size = node.parent() == nullptr ? size : node.parent()->font_size(); |