A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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**_

authored by

Zach Nelson and committed by
GitHub
448a77f0 e1074a84

-24
-8
lib/EpdFont/EpdFont.cpp
··· 47 47 *h = maxY - minY; 48 48 } 49 49 50 - bool EpdFont::hasPrintableChars(const char* string) const { 51 - int w = 0, h = 0; 52 - 53 - getTextDimensions(string, &w, &h); 54 - 55 - return w > 0 || h > 0; 56 - } 57 - 58 50 const EpdGlyph* EpdFont::getGlyph(const uint32_t cp) const { 59 51 const EpdUnicodeInterval* intervals = data->intervals; 60 52 const int count = data->intervalCount;
-1
lib/EpdFont/EpdFont.h
··· 9 9 explicit EpdFont(const EpdFontData* data) : data(data) {} 10 10 ~EpdFont() = default; 11 11 void getTextDimensions(const char* string, int* w, int* h) const; 12 - bool hasPrintableChars(const char* string) const; 13 12 14 13 const EpdGlyph* getGlyph(uint32_t cp) const; 15 14 };
-4
lib/EpdFont/EpdFontFamily.cpp
··· 22 22 getFont(style)->getTextDimensions(string, w, h); 23 23 } 24 24 25 - bool EpdFontFamily::hasPrintableChars(const char* string, const Style style) const { 26 - return getFont(style)->hasPrintableChars(string); 27 - } 28 - 29 25 const EpdFontData* EpdFontFamily::getData(const Style style) const { return getFont(style)->data; } 30 26 31 27 const EpdGlyph* EpdFontFamily::getGlyph(const uint32_t cp, const Style style) const {
-1
lib/EpdFont/EpdFontFamily.h
··· 10 10 : regular(regular), bold(bold), italic(italic), boldItalic(boldItalic) {} 11 11 ~EpdFontFamily() = default; 12 12 void getTextDimensions(const char* string, int* w, int* h, Style style = REGULAR) const; 13 - bool hasPrintableChars(const char* string, Style style = REGULAR) const; 14 13 const EpdFontData* getData(Style style = REGULAR) const; 15 14 const EpdGlyph* getGlyph(uint32_t cp, Style style = REGULAR) const; 16 15
-10
lib/GfxRenderer/GfxRenderer.cpp
··· 120 120 } 121 121 const auto& font = fontIt->second; 122 122 123 - // no printable characters 124 - if (!font.hasPrintableChars(text, style)) { 125 - return; 126 - } 127 - 128 123 uint32_t cp; 129 124 while ((cp = utf8NextCodepoint(reinterpret_cast<const uint8_t**>(&text)))) { 130 125 renderChar(font, cp, &xpos, &yPos, black, style); ··· 811 806 } 812 807 813 808 const auto& font = fontIt->second; 814 - 815 - // No printable characters 816 - if (!font.hasPrintableChars(text, style)) { 817 - return; 818 - } 819 809 820 810 // For 90° clockwise rotation: 821 811 // Original (glyphX, glyphY) -> Rotated (glyphY, -glyphX)