Wrap up multiple font styles into EpdFontFamily

This commit is contained in:
Dave Allie
2025-12-06 00:34:16 +11:00
parent fa0f27df6a
commit 05a027e2bf
13 changed files with 184 additions and 129 deletions

View File

@@ -107,11 +107,11 @@ void Section::renderPage() {
delete p;
} else if (pageCount == 0) {
Serial.println("No pages to render");
const int width = renderer->getTextWidth("Empty chapter", true);
renderer->drawText((renderer->getPageWidth() - width) / 2, 300, "Empty chapter", true);
const int width = renderer->getTextWidth("Empty chapter", BOLD);
renderer->drawText((renderer->getPageWidth() - width) / 2, 300, "Empty chapter", 1, BOLD);
} else {
Serial.printf("Page out of bounds: %d (max %d)\n", currentPage, pageCount);
const int width = renderer->getTextWidth("Out of bounds", true);
renderer->drawText((renderer->getPageWidth() - width) / 2, 300, "Out of bounds", true);
const int width = renderer->getTextWidth("Out of bounds", BOLD);
renderer->drawText((renderer->getPageWidth() - width) / 2, 300, "Out of bounds", 1, BOLD);
}
}

View File

@@ -56,7 +56,17 @@ std::list<TextBlock*> TextBlock::splitIntoLines(const EpdRenderer* renderer) {
uint16_t wordWidths[totalWordCount];
for (int i = 0; i < words.size(); i++) {
// measure the word
const int width = renderer->getTextWidth(words[i].c_str(), wordStyles[i] & BOLD_SPAN, wordStyles[i] & ITALIC_SPAN);
EpdFontStyle fontStyle = REGULAR;
if (wordStyles[i] & BOLD_SPAN) {
if (wordStyles[i] & ITALIC_SPAN) {
fontStyle = BOLD_ITALIC;
} else {
fontStyle = BOLD;
}
} else if (wordStyles[i] & ITALIC_SPAN) {
fontStyle = ITALIC;
}
const int width = renderer->getTextWidth(words[i].c_str(), fontStyle);
wordWidths[i] = width;
}
@@ -182,7 +192,18 @@ void TextBlock::render(const EpdRenderer* renderer, const int x, const int y) co
// get the style
const uint8_t wordStyle = wordStyles[i];
// render the word
renderer->drawText(x + wordXpos[i], y, words[i].c_str(), wordStyle & BOLD_SPAN, wordStyle & ITALIC_SPAN);
EpdFontStyle fontStyle = REGULAR;
if (wordStyles[i] & BOLD_SPAN) {
if (wordStyles[i] & ITALIC_SPAN) {
fontStyle = BOLD_ITALIC;
} else {
fontStyle = BOLD;
}
} else if (wordStyles[i] & ITALIC_SPAN) {
fontStyle = ITALIC;
}
renderer->drawText(x + wordXpos[i], y, words[i].c_str(), 1, fontStyle);
}
}