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:
@@ -25,11 +25,6 @@ void EpdFont::getTextBounds(const char* string, const int startX, const int star
|
|||||||
uint32_t cp;
|
uint32_t cp;
|
||||||
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&string)))) {
|
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&string)))) {
|
||||||
const EpdGlyph* glyph = getGlyph(cp);
|
const EpdGlyph* glyph = getGlyph(cp);
|
||||||
|
|
||||||
if (!glyph) {
|
|
||||||
glyph = getGlyph(REPLACEMENT_GLYPH);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!glyph) {
|
if (!glyph) {
|
||||||
// TODO: Better handle this?
|
// TODO: Better handle this?
|
||||||
continue;
|
continue;
|
||||||
@@ -95,6 +90,8 @@ const EpdGlyph* EpdFont::getGlyph(const uint32_t cp) const {
|
|||||||
return &data->glyph[interval->offset + (cp - interval->first)];
|
return &data->glyph[interval->offset + (cp - interval->first)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cp != REPLACEMENT_GLYPH) {
|
||||||
|
return getGlyph(REPLACEMENT_GLYPH);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,10 +68,6 @@ static void renderCharImpl(const GfxRenderer& renderer, GfxRenderer::RenderMode
|
|||||||
const EpdFontFamily& fontFamily, const uint32_t cp, int* cursorX, int* cursorY,
|
const EpdFontFamily& fontFamily, const uint32_t cp, int* cursorX, int* cursorY,
|
||||||
const bool pixelState, const EpdFontFamily::Style style) {
|
const bool pixelState, const EpdFontFamily::Style style) {
|
||||||
const EpdGlyph* glyph = fontFamily.getGlyph(cp, style);
|
const EpdGlyph* glyph = fontFamily.getGlyph(cp, style);
|
||||||
if (!glyph) {
|
|
||||||
glyph = fontFamily.getGlyph(REPLACEMENT_GLYPH, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!glyph) {
|
if (!glyph) {
|
||||||
LOG_ERR("GFX", "No glyph for codepoint %d", cp);
|
LOG_ERR("GFX", "No glyph for codepoint %d", cp);
|
||||||
return;
|
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)))) {
|
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) {
|
||||||
if (utf8IsCombiningMark(cp) && hasBaseGlyph) {
|
if (utf8IsCombiningMark(cp) && hasBaseGlyph) {
|
||||||
const EpdGlyph* combiningGlyph = font.getGlyph(cp, style);
|
const EpdGlyph* combiningGlyph = font.getGlyph(cp, style);
|
||||||
if (!combiningGlyph) {
|
|
||||||
combiningGlyph = font.getGlyph(REPLACEMENT_GLYPH, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
int raiseBy = 0;
|
int raiseBy = 0;
|
||||||
if (combiningGlyph) {
|
if (combiningGlyph) {
|
||||||
const int currentGap = combiningGlyph->top - combiningGlyph->height - lastBaseTop;
|
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);
|
const EpdGlyph* glyph = font.getGlyph(cp, style);
|
||||||
if (!glyph) {
|
|
||||||
glyph = font.getGlyph(REPLACEMENT_GLYPH, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!utf8IsCombiningMark(cp)) {
|
if (!utf8IsCombiningMark(cp)) {
|
||||||
lastBaseX = xpos;
|
lastBaseX = xpos;
|
||||||
lastBaseY = yPos;
|
lastBaseY = yPos;
|
||||||
@@ -909,7 +897,6 @@ int GfxRenderer::getTextAdvanceX(const int fontId, const char* text, const EpdFo
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const EpdGlyph* glyph = font.getGlyph(cp, style);
|
const EpdGlyph* glyph = font.getGlyph(cp, style);
|
||||||
if (!glyph) glyph = font.getGlyph(REPLACEMENT_GLYPH, style);
|
|
||||||
if (glyph) width += glyph->advanceX;
|
if (glyph) width += glyph->advanceX;
|
||||||
}
|
}
|
||||||
return width;
|
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)))) {
|
while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) {
|
||||||
if (utf8IsCombiningMark(cp) && hasBaseGlyph) {
|
if (utf8IsCombiningMark(cp) && hasBaseGlyph) {
|
||||||
const EpdGlyph* combiningGlyph = font.getGlyph(cp, style);
|
const EpdGlyph* combiningGlyph = font.getGlyph(cp, style);
|
||||||
if (!combiningGlyph) {
|
|
||||||
combiningGlyph = font.getGlyph(REPLACEMENT_GLYPH, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
int raiseBy = 0;
|
int raiseBy = 0;
|
||||||
if (combiningGlyph) {
|
if (combiningGlyph) {
|
||||||
const int currentGap = combiningGlyph->top - combiningGlyph->height - lastBaseTop;
|
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);
|
const EpdGlyph* glyph = font.getGlyph(cp, style);
|
||||||
if (!glyph) {
|
|
||||||
glyph = font.getGlyph(REPLACEMENT_GLYPH, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!utf8IsCombiningMark(cp)) {
|
if (!utf8IsCombiningMark(cp)) {
|
||||||
lastBaseX = xPos;
|
lastBaseX = xPos;
|
||||||
lastBaseY = yPos;
|
lastBaseY = yPos;
|
||||||
|
|||||||
Reference in New Issue
Block a user