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**_
This commit is contained in:
Zach Nelson
2026-02-23 06:32:50 -06:00
committed by GitHub
parent 410c70ab89
commit 13fc8b94b0
2 changed files with 3 additions and 27 deletions

View File

@@ -25,11 +25,6 @@ void EpdFont::getTextBounds(const char* string, const int startX, const int star
uint32_t cp;
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&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;
}

View File

@@ -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<const uint8_t**>(&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<const uint8_t**>(&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;