LibGfx/OpenType: Return metrics from hmtx even if there is no glyf entry

This fixes an issue with some typefaces where the space character has an
advance width, but no glyf entry (and thus no ascent/descent). Before
this change, we'd render whitespace with zero advance in such cases.
This commit is contained in:
Andreas Kling 2023-08-02 18:33:10 +02:00
parent 58e3b8cf58
commit 9e5c7abd94
Notes: sideshowbarker 2024-07-17 00:23:42 +09:00

View file

@ -671,11 +671,9 @@ 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);
if (!glyph.has_value())
return {};
return Gfx::ScaledGlyphMetrics {
.ascender = static_cast<float>(glyph->ascender()) * y_scale,
.descender = static_cast<float>(glyph->descender()) * y_scale,
.ascender = glyph.has_value() ? static_cast<float>(glyph->ascender()) * y_scale : 0,
.descender = glyph.has_value() ? static_cast<float>(glyph->descender()) * y_scale : 0,
.advance_width = static_cast<float>(horizontal_metrics.advance_width) * x_scale,
.left_side_bearing = static_cast<float>(horizontal_metrics.left_side_bearing) * x_scale,
};