diff options
author | Andreas Kling <kling@serenityos.org> | 2023-03-15 11:00:11 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-03-15 11:43:54 +0100 |
commit | 664f30a2c91b5f4faee99361df2e154d70856682 (patch) | |
tree | adf883301399e6a24f2e3fe75cb53588e45330e5 /Userland/Libraries/LibWeb/Painting | |
parent | a4927f523ba57856db1e401d7175b9b2b146ee95 (diff) | |
download | serenity-664f30a2c91b5f4faee99361df2e154d70856682.zip |
LibWeb: Don't truncate font sizes before scaling them to device pixels
This fixes an issue where fonts would often paint at the wrong sizes
with device pixel ratios other than 1.0.
Diffstat (limited to 'Userland/Libraries/LibWeb/Painting')
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/PaintContext.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/PaintableBox.cpp | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/PaintContext.h b/Userland/Libraries/LibWeb/Painting/PaintContext.h index 32128bbc57..cfa1c89903 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintContext.h +++ b/Userland/Libraries/LibWeb/Painting/PaintContext.h @@ -59,6 +59,8 @@ public: return clone; } + float device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; } + private: Gfx::Painter& m_painter; Palette m_palette; diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 3a3d3b4fb0..c625efbec0 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -527,13 +527,13 @@ static void paint_text_fragment(PaintContext& context, Layout::TextNode const& t auto& font = fragment.layout_node().font(); auto scaled_font = [&]() -> RefPtr<Gfx::Font const> { - auto device_font_pt_size = context.enclosing_device_pixels(font.presentation_size()); - FontSelector font_selector = { FlyString::from_deprecated_fly_string(font.family()).release_value_but_fixme_should_propagate_errors(), static_cast<float>(device_font_pt_size.value()), font.weight(), font.width(), font.slope() }; + auto device_font_pt_size = font.point_size() * context.device_pixels_per_css_pixel(); + FontSelector font_selector = { FlyString::from_deprecated_fly_string(font.family()).release_value_but_fixme_should_propagate_errors(), device_font_pt_size, font.weight(), font.width(), font.slope() }; if (auto cached_font = FontCache::the().get(font_selector)) { return cached_font; } - if (auto font_with_device_pt_size = font.with_size(static_cast<float>(device_font_pt_size.value()))) { + if (auto font_with_device_pt_size = font.with_size(device_font_pt_size)) { FontCache::the().set(font_selector, *font_with_device_pt_size); return font_with_device_pt_size; } |