1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +00:00

LibGfx/Font: Make ScaledGlyphMetrics floating point

By rounding the scaled glyph metrics, we were losing valuable precision,
especially at smaller sizes.
This commit is contained in:
Andreas Kling 2023-01-02 21:11:25 +01:00
parent 15b920c730
commit 8cea9fe56d
2 changed files with 8 additions and 10 deletions

View file

@ -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,
};
}

View file

@ -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> {