From cea62ef73de2e8a447ccb7b48979fcf1c0f47471 Mon Sep 17 00:00:00 2001 From: PeterN Date: Sun, 13 Nov 2022 17:10:34 +0000 Subject: [PATCH] Fix #10161: Ignore ascender in FallbackLayouter for non-built-in fonts. (#10169) --- src/gfx_layout.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 8246e10aca..01b5421bcf 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -333,18 +333,25 @@ public: FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(Font *font, const WChar *chars, int char_count, int x) : font(font), glyph_count(char_count) { + const bool isbuiltin = font->fc->IsBuiltInFont(); + this->glyphs = MallocT(this->glyph_count); this->glyph_to_char = MallocT(this->glyph_count); /* Positions contains the location of the begin of each of the glyphs, and the end of the last one. */ this->positions = MallocT(this->glyph_count * 2 + 2); this->positions[0] = x; - this->positions[1] = font->fc->GetAscender(); for (int i = 0; i < this->glyph_count; i++) { this->glyphs[i] = font->fc->MapCharToGlyph(chars[i]); + if (isbuiltin) { + this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. + } else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) { + this->positions[2 * i + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. + } else { + this->positions[2 * i + 1] = 0; // No ascender adjustment. + } this->positions[2 * i + 2] = this->positions[2 * i] + font->fc->GetGlyphWidth(this->glyphs[i]); - this->positions[2 * i + 3] = font->fc->GetAscender(); this->glyph_to_char[i] = i; } }