From 9e5c7abd94ef8b77dc4a7ae3bedba3b980c93d7d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 2 Aug 2023 18:33:10 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/Font/OpenType/Font.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 6b47f85997..869f2b5fd7 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -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(glyph->ascender()) * y_scale, - .descender = static_cast(glyph->descender()) * y_scale, + .ascender = glyph.has_value() ? static_cast(glyph->ascender()) * y_scale : 0, + .descender = glyph.has_value() ? static_cast(glyph->descender()) * y_scale : 0, .advance_width = static_cast(horizontal_metrics.advance_width) * x_scale, .left_side_bearing = static_cast(horizontal_metrics.left_side_bearing) * x_scale, };