From 8cea9fe56d6308d4ce50167d0d4f370bc982e26f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 2 Jan 2023 21:11:25 +0100 Subject: [PATCH] LibGfx/Font: Make ScaledGlyphMetrics floating point By rounding the scaled glyph metrics, we were losing valuable precision, especially at smaller sizes. --- Userland/Libraries/LibGfx/Font/OpenType/Font.cpp | 10 ++++------ Userland/Libraries/LibGfx/Font/VectorFont.h | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 94b12a3df1..bc0b7fc1af 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -538,13 +538,11 @@ Gfx::ScaledGlyphMetrics Font::glyph_metrics(u32 glyph_id, float x_scale, float y auto horizontal_metrics = m_hmtx.get_glyph_horizontal_metrics(glyph_id); auto glyph_offset = m_loca.get_glyph_offset(glyph_id); auto glyph = m_glyf.glyph(glyph_offset); - int ascender = glyph.ascender(); - int descender = glyph.descender(); return Gfx::ScaledGlyphMetrics { - .ascender = (int)roundf(ascender * y_scale), - .descender = (int)roundf(descender * y_scale), - .advance_width = (int)roundf(horizontal_metrics.advance_width * x_scale), - .left_side_bearing = (int)roundf(horizontal_metrics.left_side_bearing * x_scale), + .ascender = static_cast(glyph.ascender()) * y_scale, + .descender = static_cast(glyph.descender()) * y_scale, + .advance_width = static_cast(horizontal_metrics.advance_width) * x_scale, + .left_side_bearing = static_cast(horizontal_metrics.left_side_bearing) * x_scale, }; } diff --git a/Userland/Libraries/LibGfx/Font/VectorFont.h b/Userland/Libraries/LibGfx/Font/VectorFont.h index fd3a8abe27..ddcef366a2 100644 --- a/Userland/Libraries/LibGfx/Font/VectorFont.h +++ b/Userland/Libraries/LibGfx/Font/VectorFont.h @@ -24,10 +24,10 @@ struct ScaledFontMetrics { }; struct ScaledGlyphMetrics { - int ascender; - int descender; - int advance_width; - int left_side_bearing; + float ascender; + float descender; + float advance_width; + float left_side_bearing; }; class VectorFont : public RefCounted {