From 448a77f02b100eaf68242452874c4241d3fd9de7 Mon Sep 17 00:00:00 2001 From: Zach Nelson Date: Thu, 19 Feb 2026 04:58:09 -0600 Subject: [PATCH] perf: Remove hasPrintableChars pass (#971) ## Summary **What is the goal of this PR?** `hasPrintableChars` does a pass over text before rendering. It looks up glyphs in the font and measures dimensions, returning early if the text results in zero size. This additional pass doesn't offer any benefit over moving straight to rendering the text, because the rendering loop already gracefully handles missing glyphs. This change saves an extra pass over all rendered text. Note that both `hasPrintableChars` and `renderChar` replace missing glyphs with `glyph = getGlyph(REPLACEMENT_GLYPH)`, so there's no difference for characters which are not present in the font. --- ### 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 | 8 -------- lib/EpdFont/EpdFont.h | 1 - lib/EpdFont/EpdFontFamily.cpp | 4 ---- lib/EpdFont/EpdFontFamily.h | 1 - lib/GfxRenderer/GfxRenderer.cpp | 10 ---------- 5 files changed, 24 deletions(-) diff --git a/lib/EpdFont/EpdFont.cpp b/lib/EpdFont/EpdFont.cpp index 8550cba4..5b770462 100644 --- a/lib/EpdFont/EpdFont.cpp +++ b/lib/EpdFont/EpdFont.cpp @@ -47,14 +47,6 @@ void EpdFont::getTextDimensions(const char* string, int* w, int* h) const { *h = maxY - minY; } -bool EpdFont::hasPrintableChars(const char* string) const { - int w = 0, h = 0; - - getTextDimensions(string, &w, &h); - - return w > 0 || h > 0; -} - const EpdGlyph* EpdFont::getGlyph(const uint32_t cp) const { const EpdUnicodeInterval* intervals = data->intervals; const int count = data->intervalCount; diff --git a/lib/EpdFont/EpdFont.h b/lib/EpdFont/EpdFont.h index c8473fc0..5b0e2f9b 100644 --- a/lib/EpdFont/EpdFont.h +++ b/lib/EpdFont/EpdFont.h @@ -9,7 +9,6 @@ class EpdFont { explicit EpdFont(const EpdFontData* data) : data(data) {} ~EpdFont() = default; void getTextDimensions(const char* string, int* w, int* h) const; - bool hasPrintableChars(const char* string) const; const EpdGlyph* getGlyph(uint32_t cp) const; }; diff --git a/lib/EpdFont/EpdFontFamily.cpp b/lib/EpdFont/EpdFontFamily.cpp index 821153e3..5a1f8cef 100644 --- a/lib/EpdFont/EpdFontFamily.cpp +++ b/lib/EpdFont/EpdFontFamily.cpp @@ -22,10 +22,6 @@ void EpdFontFamily::getTextDimensions(const char* string, int* w, int* h, const getFont(style)->getTextDimensions(string, w, h); } -bool EpdFontFamily::hasPrintableChars(const char* string, const Style style) const { - return getFont(style)->hasPrintableChars(string); -} - const EpdFontData* EpdFontFamily::getData(const Style style) const { return getFont(style)->data; } const EpdGlyph* EpdFontFamily::getGlyph(const uint32_t cp, const Style style) const { diff --git a/lib/EpdFont/EpdFontFamily.h b/lib/EpdFont/EpdFontFamily.h index 64fd9953..746cc507 100644 --- a/lib/EpdFont/EpdFontFamily.h +++ b/lib/EpdFont/EpdFontFamily.h @@ -10,7 +10,6 @@ class EpdFontFamily { : regular(regular), bold(bold), italic(italic), boldItalic(boldItalic) {} ~EpdFontFamily() = default; void getTextDimensions(const char* string, int* w, int* h, Style style = REGULAR) const; - bool hasPrintableChars(const char* string, Style style = REGULAR) const; const EpdFontData* getData(Style style = REGULAR) const; const EpdGlyph* getGlyph(uint32_t cp, Style style = REGULAR) const; diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp index 8b8c9eac..77dd810c 100644 --- a/lib/GfxRenderer/GfxRenderer.cpp +++ b/lib/GfxRenderer/GfxRenderer.cpp @@ -120,11 +120,6 @@ void GfxRenderer::drawText(const int fontId, const int x, const int y, const cha } const auto& font = fontIt->second; - // no printable characters - if (!font.hasPrintableChars(text, style)) { - return; - } - uint32_t cp; while ((cp = utf8NextCodepoint(reinterpret_cast(&text)))) { renderChar(font, cp, &xpos, &yPos, black, style); @@ -812,11 +807,6 @@ void GfxRenderer::drawTextRotated90CW(const int fontId, const int x, const int y const auto& font = fontIt->second; - // No printable characters - if (!font.hasPrintableChars(text, style)) { - return; - } - // For 90° clockwise rotation: // Original (glyphX, glyphY) -> Rotated (glyphY, -glyphX) // Text reads from bottom to top