From 13fc8b94b0fbce0b0a38ea53959fe32e8bdbd186 Mon Sep 17 00:00:00 2001 From: Zach Nelson Date: Mon, 23 Feb 2026 06:32:50 -0600 Subject: [PATCH] refactor: Simplify REPLACEMENT_GLYPH fallback (#1119) ## Summary **What is the goal of this PR?** Consolidated repeated logic to fall back to REPLACEMENT_GLYPH. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO**_ --- lib/EpdFont/EpdFont.cpp | 9 +++------ lib/GfxRenderer/GfxRenderer.cpp | 21 --------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/lib/EpdFont/EpdFont.cpp b/lib/EpdFont/EpdFont.cpp index 6d777a3e..0b89806a 100644 --- a/lib/EpdFont/EpdFont.cpp +++ b/lib/EpdFont/EpdFont.cpp @@ -25,11 +25,6 @@ void EpdFont::getTextBounds(const char* string, const int startX, const int star uint32_t cp; while ((cp = utf8NextCodepoint(reinterpret_cast(&string)))) { const EpdGlyph* glyph = getGlyph(cp); - - if (!glyph) { - glyph = getGlyph(REPLACEMENT_GLYPH); - } - if (!glyph) { // TODO: Better handle this? continue; @@ -95,6 +90,8 @@ const EpdGlyph* EpdFont::getGlyph(const uint32_t cp) const { return &data->glyph[interval->offset + (cp - interval->first)]; } } - + if (cp != REPLACEMENT_GLYPH) { + return getGlyph(REPLACEMENT_GLYPH); + } return nullptr; } diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index 02ce8362..7c03faf3 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -68,10 +68,6 @@ static void renderCharImpl(const GfxRenderer& renderer, GfxRenderer::RenderMode const EpdFontFamily& fontFamily, const uint32_t cp, int* cursorX, int* cursorY, const bool pixelState, const EpdFontFamily::Style style) { const EpdGlyph* glyph = fontFamily.getGlyph(cp, style); - if (!glyph) { - glyph = fontFamily.getGlyph(REPLACEMENT_GLYPH, style); - } - if (!glyph) { LOG_ERR("GFX", "No glyph for codepoint %d", cp); return; @@ -237,10 +233,6 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha while ((cp = utf8NextCodepoint(reinterpret_cast(&text)))) { if (utf8IsCombiningMark(cp) && hasBaseGlyph) { const EpdGlyph* combiningGlyph = font.getGlyph(cp, style); - if (!combiningGlyph) { - combiningGlyph = font.getGlyph(REPLACEMENT_GLYPH, style); - } - int raiseBy = 0; if (combiningGlyph) { const int currentGap = combiningGlyph->top - combiningGlyph->height - lastBaseTop; @@ -256,10 +248,6 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha } const EpdGlyph* glyph = font.getGlyph(cp, style); - if (!glyph) { - glyph = font.getGlyph(REPLACEMENT_GLYPH, style); - } - if (!utf8IsCombiningMark(cp)) { lastBaseX = xpos; lastBaseY = yPos; @@ -909,7 +897,6 @@ int GfxRenderer::getTextAdvanceX(const int fontId, const char* text, const EpdFo continue; } const EpdGlyph* glyph = font.getGlyph(cp, style); - if (!glyph) glyph = font.getGlyph(REPLACEMENT_GLYPH, style); if (glyph) width += glyph->advanceX; } return width; @@ -972,10 +959,6 @@ void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y while ((cp = utf8NextCodepoint(reinterpret_cast(&text)))) { if (utf8IsCombiningMark(cp) && hasBaseGlyph) { const EpdGlyph* combiningGlyph = font.getGlyph(cp, style); - if (!combiningGlyph) { - combiningGlyph = font.getGlyph(REPLACEMENT_GLYPH, style); - } - int raiseBy = 0; if (combiningGlyph) { const int currentGap = combiningGlyph->top - combiningGlyph->height - lastBaseTop; @@ -991,10 +974,6 @@ void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y } const EpdGlyph* glyph = font.getGlyph(cp, style); - if (!glyph) { - glyph = font.getGlyph(REPLACEMENT_GLYPH, style); - } - if (!utf8IsCombiningMark(cp)) { lastBaseX = xPos; lastBaseY = yPos;