Parcourir la source

LibGfx/Font: Make ScaledGlyphMetrics floating point

By rounding the scaled glyph metrics, we were losing valuable precision,
especially at smaller sizes.
Andreas Kling il y a 2 ans
Parent
commit
8cea9fe56d

+ 4 - 6
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<float>(glyph.ascender()) * y_scale,
+        .descender = static_cast<float>(glyph.descender()) * y_scale,
+        .advance_width = static_cast<float>(horizontal_metrics.advance_width) * x_scale,
+        .left_side_bearing = static_cast<float>(horizontal_metrics.left_side_bearing) * x_scale,
     };
 }
 

+ 4 - 4
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<VectorFont> {