diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-23 14:10:35 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-23 14:13:15 +0100 |
commit | 632928a11e23339bdc124535c3c8676ab0d8a4f0 (patch) | |
tree | 9442f168e38edcc1e64af026e47fe02d0ebf70fc /Userland/Libraries/LibWeb | |
parent | bf7b51a56948e9b87db9fc41ae34a2da261aac17 (diff) | |
download | serenity-632928a11e23339bdc124535c3c8676ab0d8a4f0.zip |
LibWeb: Pass font sizes in pt rather than px to Gfx::FontDatabase
Our font database uses point sizes for fonts, and we were passing it
px sizes. This caused all fonts to be 1.333x larger than they should
be on the web. Of course it wasn't always noticeable with bitmap fonts,
but noticeable everywhere with scalable fonts.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 8e36372b58..0e97ec6596 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -774,7 +774,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele bool bold = weight > Gfx::FontWeight::Regular; - int size = 10; + float font_size_in_px = 10; if (font_size->is_identifier()) { switch (static_cast<const IdentifierStyleValue&>(*font_size).id()) { @@ -783,14 +783,14 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele case CSS::ValueID::Small: case CSS::ValueID::Medium: // FIXME: Should be based on "user's default font size" - size = 10; + font_size_in_px = 10; break; case CSS::ValueID::Large: case CSS::ValueID::XLarge: case CSS::ValueID::XxLarge: case CSS::ValueID::XxxLarge: // FIXME: Should be based on "user's default font size" - size = 12; + font_size_in_px = 12; break; case CSS::ValueID::Smaller: case CSS::ValueID::Larger: @@ -810,14 +810,14 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele auto parent_font_size = [&]() -> float { if (!parent_element || !parent_element->computed_css_values()) - return size; + return font_size_in_px; auto value = parent_element->computed_css_values()->property(CSS::PropertyID::FontSize).value(); if (value->is_length()) { auto length = static_cast<LengthStyleValue const&>(*value).to_length(); if (length.is_absolute() || length.is_relative()) - return length.to_px(viewport_rect(), font_metrics, size, root_font_size); + return length.to_px(viewport_rect(), font_metrics, font_size_in_px, root_font_size); } - return size; + return font_size_in_px; }; Optional<Length> maybe_length; @@ -837,7 +837,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele if (!maybe_length->is_calculated()) { auto px = maybe_length.value().to_px(viewport_rect(), font_metrics, parent_font_size(), root_font_size); if (px != 0) - size = px; + font_size_in_px = px; } } } @@ -865,12 +865,13 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele bool monospace = false; auto find_font = [&](String const& family) -> RefPtr<Gfx::Font> { - font_selector = { family, size, weight, slope }; + int font_size_in_pt = roundf(font_size_in_px * 0.75f); + font_selector = { family, font_size_in_pt, weight, slope }; if (auto found_font = FontCache::the().get(font_selector)) return found_font; - if (auto found_font = Gfx::FontDatabase::the().get(family, size, weight, slope, Gfx::Font::AllowInexactSizeMatch::Yes)) + if (auto found_font = Gfx::FontDatabase::the().get(family, font_size_in_pt, weight, slope, Gfx::Font::AllowInexactSizeMatch::Yes)) return found_font; return {}; @@ -926,7 +927,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele FontCache::the().set(font_selector, *found_font); - style.set_property(CSS::PropertyID::FontSize, LengthStyleValue::create(CSS::Length::make_px(size))); + style.set_property(CSS::PropertyID::FontSize, LengthStyleValue::create(CSS::Length::make_px(font_size_in_px))); style.set_property(CSS::PropertyID::FontWeight, NumericStyleValue::create_integer(weight)); style.set_computed_font(found_font.release_nonnull()); |