From 0f6dd8c62b4df4fc4cdde288865a5c99c20093bb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 28 Mar 2022 12:01:10 +0200 Subject: [PATCH] LibGfx: Make Gfx::FontMetrics include the advance of '0' instead of 'M' CSS actually wants the advance of the ASCII '0' character for its "ch" units, so let's include that instead of the arbitrarily chosen 'M'. --- Userland/Libraries/LibGfx/BitmapFont.cpp | 2 +- Userland/Libraries/LibGfx/Font.h | 2 +- Userland/Libraries/LibWeb/CSS/Length.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/BitmapFont.cpp b/Userland/Libraries/LibGfx/BitmapFont.cpp index 155b22de289..ddcc99dc644 100644 --- a/Userland/Libraries/LibGfx/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/BitmapFont.cpp @@ -377,7 +377,7 @@ FontMetrics Font::metrics() const return FontMetrics { .size = (float)presentation_size(), .x_height = (float)x_height(), - .glyph_width = (float)glyph_width('M'), + .advance_of_ascii_zero = (float)glyph_width('0'), .glyph_spacing = (float)glyph_spacing(), }; } diff --git a/Userland/Libraries/LibGfx/Font.h b/Userland/Libraries/LibGfx/Font.h index 139ff23218f..89a9fa4d023 100644 --- a/Userland/Libraries/LibGfx/Font.h +++ b/Userland/Libraries/LibGfx/Font.h @@ -89,7 +89,7 @@ private: struct FontMetrics { float size { 0 }; float x_height { 0 }; - float glyph_width { 0 }; + float advance_of_ascii_zero { 0 }; float glyph_spacing { 0 }; }; diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index a350a59fbde..42d19cca3ee 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -76,7 +76,7 @@ float Length::relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::Font return m_value * font_size; case Type::Ch: // FIXME: Use layout_node.font().glyph_height() when writing-mode is not horizontal-tb (it has to be implemented first) - return m_value * (font_metrics.glyph_width + font_metrics.glyph_spacing); + return m_value * (font_metrics.advance_of_ascii_zero + font_metrics.glyph_spacing); case Type::Rem: return m_value * root_font_size; case Type::Vw: