From 8bd1854406a29e345c69d662836a9173987f36b7 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 27 Jan 2022 15:54:38 +0000 Subject: [PATCH] LibWeb+Base: Enable calc() for font-weight property :^) Modified the test-page because FontDatabase looks for exact font-weight matches, so requesting weight 800 in a font that only has 700, causes it to return the default font instead. So, we ask for 700 here. The actual fix is to improve our font-matching but I am trying not to get distracted today. :^) --- Base/res/html/misc/fonts.html | 4 ++-- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Base/res/html/misc/fonts.html b/Base/res/html/misc/fonts.html index 99f5a1387f..02381a9f7f 100644 --- a/Base/res/html/misc/fonts.html +++ b/Base/res/html/misc/fonts.html @@ -37,8 +37,8 @@

font-family: 'Liberation Serif', cursive; font-size: calc(120% + 10px);

font: calc(120% + 10px) 'Liberation Serif', cursive;

-

font-family: 'Liberation Serif', cursive; font-weight: calc(200 * 4);

-

font: calc(200 * 4) 20px 'Liberation Serif', cursive;

+

font-family: 'Liberation Serif', cursive; font-weight: calc((200 * 3) + 100);

+

font: calc((200 * 3) + 100) 20px 'Liberation Serif', cursive;

Fallback

diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 41325d09ea..61617cdce0 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -714,8 +714,11 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele weight = Gfx::FontWeight::Bold; else weight = Gfx::FontWeight::Black; + } else if (font_weight->is_calculated()) { + auto maybe_weight = font_weight->as_calculated().resolve_integer(); + if (maybe_weight.has_value()) + weight = maybe_weight.value(); } - // FIXME: calc() for font-weight bool bold = weight > Gfx::FontWeight::Regular; @@ -777,6 +780,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele } if (maybe_length.has_value()) { // FIXME: Support font-size: calc(...) + // Theoretically we can do this now, but to resolve it we need a layout_node which we might not have. :^( if (!maybe_length->is_calculated()) { auto px = maybe_length.value().to_px(viewport_rect, font_metrics, root_font_size); if (px != 0)