## 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**_
30 lines
898 B
C++
30 lines
898 B
C++
#include "EpdFontFamily.h"
|
|
|
|
const EpdFont* EpdFontFamily::getFont(const Style style) const {
|
|
// Extract font style bits (ignore UNDERLINE bit for font selection)
|
|
const bool hasBold = (style & BOLD) != 0;
|
|
const bool hasItalic = (style & ITALIC) != 0;
|
|
|
|
if (hasBold && hasItalic) {
|
|
if (boldItalic) return boldItalic;
|
|
if (bold) return bold;
|
|
if (italic) return italic;
|
|
} else if (hasBold && bold) {
|
|
return bold;
|
|
} else if (hasItalic && italic) {
|
|
return italic;
|
|
}
|
|
|
|
return regular;
|
|
}
|
|
|
|
void EpdFontFamily::getTextDimensions(const char* string, int* w, int* h, const Style style) const {
|
|
getFont(style)->getTextDimensions(string, w, h);
|
|
}
|
|
|
|
const EpdFontData* EpdFontFamily::getData(const Style style) const { return getFont(style)->data; }
|
|
|
|
const EpdGlyph* EpdFontFamily::getGlyph(const uint32_t cp, const Style style) const {
|
|
return getFont(style)->getGlyph(cp);
|
|
};
|