From d5bba91a16eeb5cd2c927dbf0c08a4ab1bbe8631 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 26 Mar 2022 23:55:11 +0100 Subject: [PATCH] LibWeb: Don't round font sizes when looking them up We previously had a rounding error which sometimes led to asking LibGfx for fonts with slightly wrong sizes. --- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 2 +- Userland/Libraries/LibWeb/FontCache.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 59e6f6e4a9..0ec3d4e3c6 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -877,7 +877,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele bool monospace = false; auto find_font = [&](String const& family) -> RefPtr { - int font_size_in_pt = roundf(font_size_in_px * 0.75f); + float font_size_in_pt = font_size_in_px * 0.75f; font_selector = { family, font_size_in_pt, weight, slope }; if (auto found_font = FontCache::the().get(font_selector)) diff --git a/Userland/Libraries/LibWeb/FontCache.h b/Userland/Libraries/LibWeb/FontCache.h index 44ad38063f..f36411570f 100644 --- a/Userland/Libraries/LibWeb/FontCache.h +++ b/Userland/Libraries/LibWeb/FontCache.h @@ -14,20 +14,20 @@ struct FontSelector { FlyString family; - int size { 0 }; + float point_size { 0 }; int weight { 0 }; int slope { 0 }; bool operator==(const FontSelector& other) const { - return family == other.family && size == other.size && weight == other.weight && slope == other.slope; + return family == other.family && point_size == other.point_size && weight == other.weight && slope == other.slope; } }; namespace AK { template<> struct Traits : public GenericTraits { - static unsigned hash(const FontSelector& key) { return pair_int_hash(pair_int_hash(key.family.hash(), key.weight), key.size); } + static unsigned hash(const FontSelector& key) { return pair_int_hash(pair_int_hash(key.family.hash(), key.weight), key.point_size); } }; }