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.

Use sane smaller data types for data in section.bin (#188)

## Summary

* Update EpdFontFamily::Style to be u8 instead of u32 (saving 3 bytes
per word)
* Update layout width/height to be u16 from int
* Update page element count to be u16 from u32
* Update text block element count to be u16 from u32
* Bumped section bin version to version 8

authored by

Dave Allie and committed by
GitHub
6e9ba100 40f9ed48

+132 -128
+5 -5
lib/EpdFont/EpdFontFamily.cpp
··· 1 1 #include "EpdFontFamily.h" 2 2 3 - const EpdFont* EpdFontFamily::getFont(const EpdFontStyle style) const { 3 + const EpdFont* EpdFontFamily::getFont(const Style style) const { 4 4 if (style == BOLD && bold) { 5 5 return bold; 6 6 } ··· 22 22 return regular; 23 23 } 24 24 25 - void EpdFontFamily::getTextDimensions(const char* string, int* w, int* h, const EpdFontStyle style) const { 25 + void EpdFontFamily::getTextDimensions(const char* string, int* w, int* h, const Style style) const { 26 26 getFont(style)->getTextDimensions(string, w, h); 27 27 } 28 28 29 - bool EpdFontFamily::hasPrintableChars(const char* string, const EpdFontStyle style) const { 29 + bool EpdFontFamily::hasPrintableChars(const char* string, const Style style) const { 30 30 return getFont(style)->hasPrintableChars(string); 31 31 } 32 32 33 - const EpdFontData* EpdFontFamily::getData(const EpdFontStyle style) const { return getFont(style)->data; } 33 + const EpdFontData* EpdFontFamily::getData(const Style style) const { return getFont(style)->data; } 34 34 35 - const EpdGlyph* EpdFontFamily::getGlyph(const uint32_t cp, const EpdFontStyle style) const { 35 + const EpdGlyph* EpdFontFamily::getGlyph(const uint32_t cp, const Style style) const { 36 36 return getFont(style)->getGlyph(cp); 37 37 };
+13 -13
lib/EpdFont/EpdFontFamily.h
··· 1 1 #pragma once 2 2 #include "EpdFont.h" 3 3 4 - enum EpdFontStyle { REGULAR, BOLD, ITALIC, BOLD_ITALIC }; 5 - 6 4 class EpdFontFamily { 7 - const EpdFont* regular; 8 - const EpdFont* bold; 9 - const EpdFont* italic; 10 - const EpdFont* boldItalic; 11 - 12 - const EpdFont* getFont(EpdFontStyle style) const; 5 + public: 6 + enum Style : uint8_t { REGULAR = 0, BOLD = 1, ITALIC = 2, BOLD_ITALIC = 3 }; 13 7 14 - public: 15 8 explicit EpdFontFamily(const EpdFont* regular, const EpdFont* bold = nullptr, const EpdFont* italic = nullptr, 16 9 const EpdFont* boldItalic = nullptr) 17 10 : regular(regular), bold(bold), italic(italic), boldItalic(boldItalic) {} 18 11 ~EpdFontFamily() = default; 19 - void getTextDimensions(const char* string, int* w, int* h, EpdFontStyle style = REGULAR) const; 20 - bool hasPrintableChars(const char* string, EpdFontStyle style = REGULAR) const; 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 + const EpdFontData* getData(Style style = REGULAR) const; 15 + const EpdGlyph* getGlyph(uint32_t cp, Style style = REGULAR) const; 21 16 22 - const EpdFontData* getData(EpdFontStyle style = REGULAR) const; 23 - const EpdGlyph* getGlyph(uint32_t cp, EpdFontStyle style = REGULAR) const; 17 + private: 18 + const EpdFont* regular; 19 + const EpdFont* bold; 20 + const EpdFont* italic; 21 + const EpdFont* boldItalic; 22 + 23 + const EpdFont* getFont(Style style) const; 24 24 };
+3 -3
lib/Epub/Epub/Page.cpp
··· 32 32 } 33 33 34 34 bool Page::serialize(FsFile& file) const { 35 - const uint32_t count = elements.size(); 35 + const uint16_t count = elements.size(); 36 36 serialization::writePod(file, count); 37 37 38 38 for (const auto& el : elements) { ··· 49 49 std::unique_ptr<Page> Page::deserialize(FsFile& file) { 50 50 auto page = std::unique_ptr<Page>(new Page()); 51 51 52 - uint32_t count; 52 + uint16_t count; 53 53 serialization::readPod(file, count); 54 54 55 - for (uint32_t i = 0; i < count; i++) { 55 + for (uint16_t i = 0; i < count; i++) { 56 56 uint8_t tag; 57 57 serialization::readPod(file, tag); 58 58
+3 -3
lib/Epub/Epub/ParsedText.cpp
··· 10 10 11 11 constexpr int MAX_COST = std::numeric_limits<int>::max(); 12 12 13 - void ParsedText::addWord(std::string word, const EpdFontStyle fontStyle) { 13 + void ParsedText::addWord(std::string word, const EpdFontFamily::Style fontStyle) { 14 14 if (word.empty()) return; 15 15 16 16 words.push_back(std::move(word)); ··· 18 18 } 19 19 20 20 // Consumes data to minimize memory usage 21 - void ParsedText::layoutAndExtractLines(const GfxRenderer& renderer, const int fontId, const int viewportWidth, 21 + void ParsedText::layoutAndExtractLines(const GfxRenderer& renderer, const int fontId, const uint16_t viewportWidth, 22 22 const std::function<void(std::shared_ptr<TextBlock>)>& processLine, 23 23 const bool includeLastLine) { 24 24 if (words.empty()) { ··· 188 188 // *** CRITICAL STEP: CONSUME DATA USING SPLICE *** 189 189 std::list<std::string> lineWords; 190 190 lineWords.splice(lineWords.begin(), words, words.begin(), wordEndIt); 191 - std::list<EpdFontStyle> lineWordStyles; 191 + std::list<EpdFontFamily::Style> lineWordStyles; 192 192 lineWordStyles.splice(lineWordStyles.begin(), wordStyles, wordStyles.begin(), wordStyleEndIt); 193 193 194 194 processLine(std::make_shared<TextBlock>(std::move(lineWords), std::move(lineXPos), std::move(lineWordStyles), style));
+7 -7
lib/Epub/Epub/ParsedText.h
··· 14 14 15 15 class ParsedText { 16 16 std::list<std::string> words; 17 - std::list<EpdFontStyle> wordStyles; 18 - TextBlock::BLOCK_STYLE style; 17 + std::list<EpdFontFamily::Style> wordStyles; 18 + TextBlock::Style style; 19 19 bool extraParagraphSpacing; 20 20 21 21 std::vector<size_t> computeLineBreaks(int pageWidth, int spaceWidth, const std::vector<uint16_t>& wordWidths) const; ··· 25 25 std::vector<uint16_t> calculateWordWidths(const GfxRenderer& renderer, int fontId); 26 26 27 27 public: 28 - explicit ParsedText(const TextBlock::BLOCK_STYLE style, const bool extraParagraphSpacing) 28 + explicit ParsedText(const TextBlock::Style style, const bool extraParagraphSpacing) 29 29 : style(style), extraParagraphSpacing(extraParagraphSpacing) {} 30 30 ~ParsedText() = default; 31 31 32 - void addWord(std::string word, EpdFontStyle fontStyle); 33 - void setStyle(const TextBlock::BLOCK_STYLE style) { this->style = style; } 34 - TextBlock::BLOCK_STYLE getStyle() const { return style; } 32 + void addWord(std::string word, EpdFontFamily::Style fontStyle); 33 + void setStyle(const TextBlock::Style style) { this->style = style; } 34 + TextBlock::Style getStyle() const { return style; } 35 35 size_t size() const { return words.size(); } 36 36 bool isEmpty() const { return words.empty(); } 37 - void layoutAndExtractLines(const GfxRenderer& renderer, int fontId, int viewportWidth, 37 + void layoutAndExtractLines(const GfxRenderer& renderer, int fontId, uint16_t viewportWidth, 38 38 const std::function<void(std::shared_ptr<TextBlock>)>& processLine, 39 39 bool includeLastLine = true); 40 40 };
+8 -7
lib/Epub/Epub/Section.cpp
··· 7 7 #include "parsers/ChapterHtmlSlimParser.h" 8 8 9 9 namespace { 10 - constexpr uint8_t SECTION_FILE_VERSION = 7; 11 - constexpr uint32_t HEADER_SIZE = sizeof(uint8_t) + sizeof(int) + sizeof(float) + sizeof(bool) + sizeof(int) + 12 - sizeof(int) + sizeof(int) + sizeof(uint32_t); 10 + constexpr uint8_t SECTION_FILE_VERSION = 8; 11 + constexpr uint32_t HEADER_SIZE = sizeof(uint8_t) + sizeof(int) + sizeof(float) + sizeof(bool) + sizeof(uint16_t) + 12 + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t); 13 13 } // namespace 14 14 15 15 uint32_t Section::onPageComplete(std::unique_ptr<Page> page) { ··· 30 30 } 31 31 32 32 void Section::writeSectionFileHeader(const int fontId, const float lineCompression, const bool extraParagraphSpacing, 33 - const int viewportWidth, const int viewportHeight) { 33 + const uint16_t viewportWidth, const uint16_t viewportHeight) { 34 34 if (!file) { 35 35 Serial.printf("[%lu] [SCT] File not open for writing header\n", millis()); 36 36 return; ··· 50 50 } 51 51 52 52 bool Section::loadSectionFile(const int fontId, const float lineCompression, const bool extraParagraphSpacing, 53 - const int viewportWidth, const int viewportHeight) { 53 + const uint16_t viewportWidth, const uint16_t viewportHeight) { 54 54 if (!SdMan.openFileForRead("SCT", filePath, file)) { 55 55 return false; 56 56 } ··· 66 66 return false; 67 67 } 68 68 69 - int fileFontId, fileViewportWidth, fileViewportHeight; 69 + int fileFontId; 70 + uint16_t fileViewportWidth, fileViewportHeight; 70 71 float fileLineCompression; 71 72 bool fileExtraParagraphSpacing; 72 73 serialization::readPod(file, fileFontId); ··· 108 109 } 109 110 110 111 bool Section::createSectionFile(const int fontId, const float lineCompression, const bool extraParagraphSpacing, 111 - const int viewportWidth, const int viewportHeight, 112 + const uint16_t viewportWidth, const uint16_t viewportHeight, 112 113 const std::function<void()>& progressSetupFn, 113 114 const std::function<void(int)>& progressFn) { 114 115 constexpr uint32_t MIN_SIZE_FOR_PROGRESS = 50 * 1024; // 50KB
+7 -7
lib/Epub/Epub/Section.h
··· 14 14 std::string filePath; 15 15 FsFile file; 16 16 17 - void writeSectionFileHeader(int fontId, float lineCompression, bool extraParagraphSpacing, int viewportWidth, 18 - int viewportHeight); 17 + void writeSectionFileHeader(int fontId, float lineCompression, bool extraParagraphSpacing, uint16_t viewportWidth, 18 + uint16_t viewportHeight); 19 19 uint32_t onPageComplete(std::unique_ptr<Page> page); 20 20 21 21 public: 22 - int pageCount = 0; 22 + uint16_t pageCount = 0; 23 23 int currentPage = 0; 24 24 25 25 explicit Section(const std::shared_ptr<Epub>& epub, const int spineIndex, GfxRenderer& renderer) ··· 28 28 renderer(renderer), 29 29 filePath(epub->getCachePath() + "/sections/" + std::to_string(spineIndex) + ".bin") {} 30 30 ~Section() = default; 31 - bool loadSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, int viewportWidth, 32 - int viewportHeight); 31 + bool loadSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint16_t viewportWidth, 32 + uint16_t viewportHeight); 33 33 bool clearCache() const; 34 - bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, int viewportWidth, 35 - int viewportHeight, const std::function<void()>& progressSetupFn = nullptr, 34 + bool createSectionFile(int fontId, float lineCompression, bool extraParagraphSpacing, uint16_t viewportWidth, 35 + uint16_t viewportHeight, const std::function<void()>& progressSetupFn = nullptr, 36 36 const std::function<void(int)>& progressFn = nullptr); 37 37 std::unique_ptr<Page> loadPageFromSectionFile(); 38 38 };
+4 -4
lib/Epub/Epub/blocks/TextBlock.cpp
··· 32 32 } 33 33 34 34 // Word data 35 - serialization::writePod(file, static_cast<uint32_t>(words.size())); 35 + serialization::writePod(file, static_cast<uint16_t>(words.size())); 36 36 for (const auto& w : words) serialization::writeString(file, w); 37 37 for (auto x : wordXpos) serialization::writePod(file, x); 38 38 for (auto s : wordStyles) serialization::writePod(file, s); ··· 44 44 } 45 45 46 46 std::unique_ptr<TextBlock> TextBlock::deserialize(FsFile& file) { 47 - uint32_t wc; 47 + uint16_t wc; 48 48 std::list<std::string> words; 49 49 std::list<uint16_t> wordXpos; 50 - std::list<EpdFontStyle> wordStyles; 51 - BLOCK_STYLE style; 50 + std::list<EpdFontFamily::Style> wordStyles; 51 + Style style; 52 52 53 53 // Word count 54 54 serialization::readPod(file, wc);
+8 -8
lib/Epub/Epub/blocks/TextBlock.h
··· 8 8 9 9 #include "Block.h" 10 10 11 - // represents a block of words in the html document 11 + // Represents a line of text on a page 12 12 class TextBlock final : public Block { 13 13 public: 14 - enum BLOCK_STYLE : uint8_t { 14 + enum Style : uint8_t { 15 15 JUSTIFIED = 0, 16 16 LEFT_ALIGN = 1, 17 17 CENTER_ALIGN = 2, ··· 21 21 private: 22 22 std::list<std::string> words; 23 23 std::list<uint16_t> wordXpos; 24 - std::list<EpdFontStyle> wordStyles; 25 - BLOCK_STYLE style; 24 + std::list<EpdFontFamily::Style> wordStyles; 25 + Style style; 26 26 27 27 public: 28 - explicit TextBlock(std::list<std::string> words, std::list<uint16_t> word_xpos, std::list<EpdFontStyle> word_styles, 29 - const BLOCK_STYLE style) 28 + explicit TextBlock(std::list<std::string> words, std::list<uint16_t> word_xpos, 29 + std::list<EpdFontFamily::Style> word_styles, const Style style) 30 30 : words(std::move(words)), wordXpos(std::move(word_xpos)), wordStyles(std::move(word_styles)), style(style) {} 31 31 ~TextBlock() override = default; 32 - void setStyle(const BLOCK_STYLE style) { this->style = style; } 33 - BLOCK_STYLE getStyle() const { return style; } 32 + void setStyle(const Style style) { this->style = style; } 33 + Style getStyle() const { return style; } 34 34 bool isEmpty() override { return words.empty(); } 35 35 void layout(GfxRenderer& renderer) override {}; 36 36 // given a renderer works out where to break the words into lines
+9 -9
lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
··· 42 42 } 43 43 44 44 // start a new text block if needed 45 - void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::BLOCK_STYLE style) { 45 + void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style) { 46 46 if (currentTextBlock) { 47 47 // already have a text block running and it is empty - just reuse it 48 48 if (currentTextBlock->isEmpty()) { ··· 116 116 return; 117 117 } 118 118 119 - EpdFontStyle fontStyle = REGULAR; 119 + EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR; 120 120 if (self->boldUntilDepth < self->depth && self->italicUntilDepth < self->depth) { 121 - fontStyle = BOLD_ITALIC; 121 + fontStyle = EpdFontFamily::BOLD_ITALIC; 122 122 } else if (self->boldUntilDepth < self->depth) { 123 - fontStyle = BOLD; 123 + fontStyle = EpdFontFamily::BOLD; 124 124 } else if (self->italicUntilDepth < self->depth) { 125 - fontStyle = ITALIC; 125 + fontStyle = EpdFontFamily::ITALIC; 126 126 } 127 127 128 128 for (int i = 0; i < len; i++) { ··· 172 172 matches(name, BOLD_TAGS, NUM_BOLD_TAGS) || matches(name, ITALIC_TAGS, NUM_ITALIC_TAGS) || self->depth == 1; 173 173 174 174 if (shouldBreakText) { 175 - EpdFontStyle fontStyle = REGULAR; 175 + EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR; 176 176 if (self->boldUntilDepth < self->depth && self->italicUntilDepth < self->depth) { 177 - fontStyle = BOLD_ITALIC; 177 + fontStyle = EpdFontFamily::BOLD_ITALIC; 178 178 } else if (self->boldUntilDepth < self->depth) { 179 - fontStyle = BOLD; 179 + fontStyle = EpdFontFamily::BOLD; 180 180 } else if (self->italicUntilDepth < self->depth) { 181 - fontStyle = ITALIC; 181 + fontStyle = EpdFontFamily::ITALIC; 182 182 } 183 183 184 184 self->partWordBuffer[self->partWordBufferIndex] = '\0';
+5 -5
lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h
··· 33 33 int fontId; 34 34 float lineCompression; 35 35 bool extraParagraphSpacing; 36 - int viewportWidth; 37 - int viewportHeight; 36 + uint16_t viewportWidth; 37 + uint16_t viewportHeight; 38 38 39 - void startNewTextBlock(TextBlock::BLOCK_STYLE style); 39 + void startNewTextBlock(TextBlock::Style style); 40 40 void makePages(); 41 41 // XML callbacks 42 42 static void XMLCALL startElement(void* userData, const XML_Char* name, const XML_Char** atts); ··· 45 45 46 46 public: 47 47 explicit ChapterHtmlSlimParser(const std::string& filepath, GfxRenderer& renderer, const int fontId, 48 - const float lineCompression, const bool extraParagraphSpacing, const int viewportWidth, 49 - const int viewportHeight, 48 + const float lineCompression, const bool extraParagraphSpacing, 49 + const uint16_t viewportWidth, const uint16_t viewportHeight, 50 50 const std::function<void(std::unique_ptr<Page>)>& completePageFn, 51 51 const std::function<void(int)>& progressFn = nullptr) 52 52 : filepath(filepath),
+8 -8
lib/GfxRenderer/GfxRenderer.cpp
··· 66 66 } 67 67 } 68 68 69 - int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontStyle style) const { 69 + int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontFamily::Style style) const { 70 70 if (fontMap.count(fontId) == 0) { 71 71 Serial.printf("[%lu] [GFX] Font %d not found\n", millis(), fontId); 72 72 return 0; ··· 78 78 } 79 79 80 80 void GfxRenderer::drawCenteredText(const int fontId, const int y, const char* text, const bool black, 81 - const EpdFontStyle style) const { 81 + const EpdFontFamily::Style style) const { 82 82 const int x = (getScreenWidth() - getTextWidth(fontId, text, style)) / 2; 83 83 drawText(fontId, x, y, text, black, style); 84 84 } 85 85 86 86 void GfxRenderer::drawText(const int fontId, const int x, const int y, const char* text, const bool black, 87 - const EpdFontStyle style) const { 87 + const EpdFontFamily::Style style) const { 88 88 const int yPos = y + getFontAscenderSize(fontId); 89 89 int xpos = x; 90 90 ··· 239 239 } 240 240 241 241 std::string GfxRenderer::truncatedText(const int fontId, const char* text, const int maxWidth, 242 - const EpdFontStyle style) const { 242 + const EpdFontFamily::Style style) const { 243 243 std::string item = text; 244 244 int itemWidth = getTextWidth(fontId, item.c_str(), style); 245 245 while (itemWidth > maxWidth && item.length() > 8) { ··· 284 284 return 0; 285 285 } 286 286 287 - return fontMap.at(fontId).getGlyph(' ', REGULAR)->advanceX; 287 + return fontMap.at(fontId).getGlyph(' ', EpdFontFamily::REGULAR)->advanceX; 288 288 } 289 289 290 290 int GfxRenderer::getFontAscenderSize(const int fontId) const { ··· 293 293 return 0; 294 294 } 295 295 296 - return fontMap.at(fontId).getData(REGULAR)->ascender; 296 + return fontMap.at(fontId).getData(EpdFontFamily::REGULAR)->ascender; 297 297 } 298 298 299 299 int GfxRenderer::getLineHeight(const int fontId) const { ··· 302 302 return 0; 303 303 } 304 304 305 - return fontMap.at(fontId).getData(REGULAR)->advanceY; 305 + return fontMap.at(fontId).getData(EpdFontFamily::REGULAR)->advanceY; 306 306 } 307 307 308 308 void GfxRenderer::drawButtonHints(const int fontId, const char* btn1, const char* btn2, const char* btn3, ··· 447 447 } 448 448 449 449 void GfxRenderer::renderChar(const EpdFontFamily& fontFamily, const uint32_t cp, int* x, const int* y, 450 - const bool pixelState, const EpdFontStyle style) const { 450 + const bool pixelState, const EpdFontFamily::Style style) const { 451 451 const EpdGlyph* glyph = fontFamily.getGlyph(cp, style); 452 452 if (!glyph) { 453 453 // TODO: Replace with fallback glyph property?
+8 -6
lib/GfxRenderer/GfxRenderer.h
··· 31 31 uint8_t* bwBufferChunks[BW_BUFFER_NUM_CHUNKS] = {nullptr}; 32 32 std::map<int, EpdFontFamily> fontMap; 33 33 void renderChar(const EpdFontFamily& fontFamily, uint32_t cp, int* x, const int* y, bool pixelState, 34 - EpdFontStyle style) const; 34 + EpdFontFamily::Style style) const; 35 35 void freeBwBufferChunks(); 36 36 void rotateCoordinates(int x, int y, int* rotatedX, int* rotatedY) const; 37 37 ··· 69 69 void drawBitmap(const Bitmap& bitmap, int x, int y, int maxWidth, int maxHeight) const; 70 70 71 71 // Text 72 - int getTextWidth(int fontId, const char* text, EpdFontStyle style = REGULAR) const; 73 - void drawCenteredText(int fontId, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const; 74 - void drawText(int fontId, int x, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const; 72 + int getTextWidth(int fontId, const char* text, EpdFontFamily::Style style = EpdFontFamily::REGULAR) const; 73 + void drawCenteredText(int fontId, int y, const char* text, bool black = true, 74 + EpdFontFamily::Style style = EpdFontFamily::REGULAR) const; 75 + void drawText(int fontId, int x, int y, const char* text, bool black = true, 76 + EpdFontFamily::Style style = EpdFontFamily::REGULAR) const; 75 77 int getSpaceWidth(int fontId) const; 76 78 int getFontAscenderSize(int fontId) const; 77 79 int getLineHeight(int fontId) const; 78 - std::string truncatedText(const int fontId, const char* text, const int maxWidth, 79 - const EpdFontStyle style = REGULAR) const; 80 + std::string truncatedText(int fontId, const char* text, int maxWidth, 81 + EpdFontFamily::Style style = EpdFontFamily::REGULAR) const; 80 82 81 83 // UI Components 82 84 void drawButtonHints(int fontId, const char* btn1, const char* btn2, const char* btn3, const char* btn4) const;
+1 -1
src/activities/boot_sleep/BootActivity.cpp
··· 13 13 14 14 renderer.clearScreen(); 15 15 renderer.drawImage(CrossLarge, (pageWidth + 128) / 2, (pageHeight - 128) / 2, 128, 128); 16 - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, BOLD); 16 + renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, EpdFontFamily::BOLD); 17 17 renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "BOOTING"); 18 18 renderer.drawCenteredText(SMALL_FONT_ID, pageHeight - 30, CROSSPOINT_VERSION); 19 19 renderer.displayBuffer();
+1 -1
src/activities/boot_sleep/SleepActivity.cpp
··· 129 129 130 130 renderer.clearScreen(); 131 131 renderer.drawImage(CrossLarge, (pageWidth + 128) / 2, (pageHeight - 128) / 2, 128, 128); 132 - renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, BOLD); 132 + renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, EpdFontFamily::BOLD); 133 133 renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "SLEEPING"); 134 134 135 135 // Make sleep screen dark unless light is selected in settings
+5 -5
src/activities/network/CrossPointWebServerActivity.cpp
··· 334 334 } else if (state == WebServerActivityState::AP_STARTING) { 335 335 renderer.clearScreen(); 336 336 const auto pageHeight = renderer.getScreenHeight(); 337 - renderer.drawCenteredText(UI_12_FONT_ID, pageHeight / 2 - 20, "Starting Hotspot...", true, BOLD); 337 + renderer.drawCenteredText(UI_12_FONT_ID, pageHeight / 2 - 20, "Starting Hotspot...", true, EpdFontFamily::BOLD); 338 338 renderer.displayBuffer(); 339 339 } 340 340 } ··· 365 365 // Use consistent line spacing 366 366 constexpr int LINE_SPACING = 28; // Space between lines 367 367 368 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "File Transfer", true, BOLD); 368 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "File Transfer", true, EpdFontFamily::BOLD); 369 369 370 370 if (isApMode) { 371 371 // AP mode display - center the content block 372 372 int startY = 55; 373 373 374 - renderer.drawCenteredText(UI_10_FONT_ID, startY, "Hotspot Mode", true, BOLD); 374 + renderer.drawCenteredText(UI_10_FONT_ID, startY, "Hotspot Mode", true, EpdFontFamily::BOLD); 375 375 376 376 std::string ssidInfo = "Network: " + connectedSSID; 377 377 renderer.drawCenteredText(UI_10_FONT_ID, startY + LINE_SPACING, ssidInfo.c_str()); ··· 387 387 startY += 6 * 29 + 3 * LINE_SPACING; 388 388 // Show primary URL (hostname) 389 389 std::string hostnameUrl = std::string("http://") + AP_HOSTNAME + ".local/"; 390 - renderer.drawCenteredText(UI_10_FONT_ID, startY + LINE_SPACING * 3, hostnameUrl.c_str(), true, BOLD); 390 + renderer.drawCenteredText(UI_10_FONT_ID, startY + LINE_SPACING * 3, hostnameUrl.c_str(), true, EpdFontFamily::BOLD); 391 391 392 392 // Show IP address as fallback 393 393 std::string ipUrl = "or http://" + connectedIP + "/"; ··· 412 412 413 413 // Show web server URL prominently 414 414 std::string webInfo = "http://" + connectedIP + "/"; 415 - renderer.drawCenteredText(UI_10_FONT_ID, startY + LINE_SPACING * 2, webInfo.c_str(), true, BOLD); 415 + renderer.drawCenteredText(UI_10_FONT_ID, startY + LINE_SPACING * 2, webInfo.c_str(), true, EpdFontFamily::BOLD); 416 416 417 417 // Also show hostname URL 418 418 std::string hostnameUrl = std::string("or http://") + AP_HOSTNAME + ".local/";
+1 -1
src/activities/network/NetworkModeSelectionActivity.cpp
··· 97 97 const auto pageHeight = renderer.getScreenHeight(); 98 98 99 99 // Draw header 100 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "File Transfer", true, BOLD); 100 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "File Transfer", true, EpdFontFamily::BOLD); 101 101 102 102 // Draw subtitle 103 103 renderer.drawCenteredText(UI_10_FONT_ID, 50, "How would you like to connect?");
+6 -6
src/activities/network/WifiSelectionActivity.cpp
··· 496 496 const auto pageHeight = renderer.getScreenHeight(); 497 497 498 498 // Draw header 499 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "WiFi Networks", true, BOLD); 499 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "WiFi Networks", true, EpdFontFamily::BOLD); 500 500 501 501 if (networks.empty()) { 502 502 // No networks found or scan failed ··· 577 577 if (state == WifiSelectionState::SCANNING) { 578 578 renderer.drawCenteredText(UI_10_FONT_ID, top, "Scanning..."); 579 579 } else { 580 - renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Connecting...", true, BOLD); 580 + renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Connecting...", true, EpdFontFamily::BOLD); 581 581 582 582 std::string ssidInfo = "to " + selectedSSID; 583 583 if (ssidInfo.length() > 25) { ··· 592 592 const auto height = renderer.getLineHeight(UI_10_FONT_ID); 593 593 const auto top = (pageHeight - height * 4) / 2; 594 594 595 - renderer.drawCenteredText(UI_12_FONT_ID, top - 30, "Connected!", true, BOLD); 595 + renderer.drawCenteredText(UI_12_FONT_ID, top - 30, "Connected!", true, EpdFontFamily::BOLD); 596 596 597 597 std::string ssidInfo = "Network: " + selectedSSID; 598 598 if (ssidInfo.length() > 28) { ··· 612 612 const auto height = renderer.getLineHeight(UI_10_FONT_ID); 613 613 const auto top = (pageHeight - height * 3) / 2; 614 614 615 - renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Connected!", true, BOLD); 615 + renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Connected!", true, EpdFontFamily::BOLD); 616 616 617 617 std::string ssidInfo = "Network: " + selectedSSID; 618 618 if (ssidInfo.length() > 28) { ··· 651 651 const auto height = renderer.getLineHeight(UI_10_FONT_ID); 652 652 const auto top = (pageHeight - height * 2) / 2; 653 653 654 - renderer.drawCenteredText(UI_12_FONT_ID, top - 20, "Connection Failed", true, BOLD); 654 + renderer.drawCenteredText(UI_12_FONT_ID, top - 20, "Connection Failed", true, EpdFontFamily::BOLD); 655 655 renderer.drawCenteredText(UI_10_FONT_ID, top + 20, connectionError.c_str()); 656 656 renderer.drawCenteredText(SMALL_FONT_ID, pageHeight - 30, "Press any button to continue"); 657 657 } ··· 662 662 const auto height = renderer.getLineHeight(UI_10_FONT_ID); 663 663 const auto top = (pageHeight - height * 3) / 2; 664 664 665 - renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Forget Network?", true, BOLD); 665 + renderer.drawCenteredText(UI_12_FONT_ID, top - 40, "Forget Network?", true, EpdFontFamily::BOLD); 666 666 667 667 std::string ssidInfo = "Network: " + selectedSSID; 668 668 if (ssidInfo.length() > 28) {
+5 -5
src/activities/reader/EpubReaderActivity.cpp
··· 244 244 // Show end of book screen 245 245 if (currentSpineIndex == epub->getSpineItemsCount()) { 246 246 renderer.clearScreen(); 247 - renderer.drawCenteredText(UI_12_FONT_ID, 300, "End of book", true, BOLD); 247 + renderer.drawCenteredText(UI_12_FONT_ID, 300, "End of book", true, EpdFontFamily::BOLD); 248 248 renderer.displayBuffer(); 249 249 return; 250 250 } ··· 263 263 Serial.printf("[%lu] [ERS] Loading file: %s, index: %d\n", millis(), filepath.c_str(), currentSpineIndex); 264 264 section = std::unique_ptr<Section>(new Section(epub, currentSpineIndex, renderer)); 265 265 266 - const auto viewportWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight; 267 - const auto viewportHeight = renderer.getScreenHeight() - orientedMarginTop - orientedMarginBottom; 266 + const uint16_t viewportWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight; 267 + const uint16_t viewportHeight = renderer.getScreenHeight() - orientedMarginTop - orientedMarginBottom; 268 268 269 269 if (!section->loadSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), 270 270 SETTINGS.extraParagraphSpacing, viewportWidth, viewportHeight)) { ··· 332 332 333 333 if (section->pageCount == 0) { 334 334 Serial.printf("[%lu] [ERS] No pages to render\n", millis()); 335 - renderer.drawCenteredText(UI_12_FONT_ID, 300, "Empty chapter", true, BOLD); 335 + renderer.drawCenteredText(UI_12_FONT_ID, 300, "Empty chapter", true, EpdFontFamily::BOLD); 336 336 renderStatusBar(orientedMarginRight, orientedMarginBottom, orientedMarginLeft); 337 337 renderer.displayBuffer(); 338 338 return; ··· 340 340 341 341 if (section->currentPage < 0 || section->currentPage >= section->pageCount) { 342 342 Serial.printf("[%lu] [ERS] Page out of bounds: %d (max %d)\n", millis(), section->currentPage, section->pageCount); 343 - renderer.drawCenteredText(UI_12_FONT_ID, 300, "Out of bounds", true, BOLD); 343 + renderer.drawCenteredText(UI_12_FONT_ID, 300, "Out of bounds", true, EpdFontFamily::BOLD); 344 344 renderStatusBar(orientedMarginRight, orientedMarginBottom, orientedMarginLeft); 345 345 renderer.displayBuffer(); 346 346 return;
+3 -2
src/activities/reader/EpubReaderChapterSelectionActivity.cpp
··· 121 121 const auto pageWidth = renderer.getScreenWidth(); 122 122 const int pageItems = getPageItems(); 123 123 124 - std::string title = renderer.truncatedText(UI_12_FONT_ID, epub->getTitle().c_str(), pageWidth - 40, BOLD); 125 - renderer.drawCenteredText(UI_12_FONT_ID, 15, title.c_str(), true, BOLD); 124 + const std::string title = 125 + renderer.truncatedText(UI_12_FONT_ID, epub->getTitle().c_str(), pageWidth - 40, EpdFontFamily::BOLD); 126 + renderer.drawCenteredText(UI_12_FONT_ID, 15, title.c_str(), true, EpdFontFamily::BOLD); 126 127 127 128 const auto pageStartIndex = selectorIndex / pageItems * pageItems; 128 129 renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30);
+1 -1
src/activities/reader/FileSelectionActivity.cpp
··· 173 173 renderer.clearScreen(); 174 174 175 175 const auto pageWidth = renderer.getScreenWidth(); 176 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "Books", true, BOLD); 176 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "Books", true, EpdFontFamily::BOLD); 177 177 178 178 // Help text 179 179 const auto labels = mappedInput.mapLabels("« Home", "Open", "", "");
+4 -4
src/activities/reader/ReaderActivity.cpp
··· 68 68 onGoToXtcReader(std::move(xtc)); 69 69 } else { 70 70 exitActivity(); 71 - enterNewActivity(new FullScreenMessageActivity(renderer, mappedInput, "Failed to load XTC", REGULAR, 72 - EInkDisplay::HALF_REFRESH)); 71 + enterNewActivity(new FullScreenMessageActivity(renderer, mappedInput, "Failed to load XTC", 72 + EpdFontFamily::REGULAR, EInkDisplay::HALF_REFRESH)); 73 73 delay(2000); 74 74 onGoToFileSelection(); 75 75 } ··· 80 80 onGoToEpubReader(std::move(epub)); 81 81 } else { 82 82 exitActivity(); 83 - enterNewActivity(new FullScreenMessageActivity(renderer, mappedInput, "Failed to load epub", REGULAR, 84 - EInkDisplay::HALF_REFRESH)); 83 + enterNewActivity(new FullScreenMessageActivity(renderer, mappedInput, "Failed to load epub", 84 + EpdFontFamily::REGULAR, EInkDisplay::HALF_REFRESH)); 85 85 delay(2000); 86 86 onGoToFileSelection(); 87 87 }
+3 -3
src/activities/reader/XtcReaderActivity.cpp
··· 165 165 if (currentPage >= xtc->getPageCount()) { 166 166 // Show end of book screen 167 167 renderer.clearScreen(); 168 - renderer.drawCenteredText(UI_12_FONT_ID, 300, "End of book", true, BOLD); 168 + renderer.drawCenteredText(UI_12_FONT_ID, 300, "End of book", true, EpdFontFamily::BOLD); 169 169 renderer.displayBuffer(); 170 170 return; 171 171 } ··· 194 194 if (!pageBuffer) { 195 195 Serial.printf("[%lu] [XTR] Failed to allocate page buffer (%lu bytes)\n", millis(), pageBufferSize); 196 196 renderer.clearScreen(); 197 - renderer.drawCenteredText(UI_12_FONT_ID, 300, "Memory error", true, BOLD); 197 + renderer.drawCenteredText(UI_12_FONT_ID, 300, "Memory error", true, EpdFontFamily::BOLD); 198 198 renderer.displayBuffer(); 199 199 return; 200 200 } ··· 205 205 Serial.printf("[%lu] [XTR] Failed to load page %lu\n", millis(), currentPage); 206 206 free(pageBuffer); 207 207 renderer.clearScreen(); 208 - renderer.drawCenteredText(UI_12_FONT_ID, 300, "Page load error", true, BOLD); 208 + renderer.drawCenteredText(UI_12_FONT_ID, 300, "Page load error", true, EpdFontFamily::BOLD); 209 209 renderer.displayBuffer(); 210 210 return; 211 211 }
+1 -1
src/activities/reader/XtcReaderChapterSelectionActivity.cpp
··· 130 130 131 131 const auto pageWidth = renderer.getScreenWidth(); 132 132 const int pageItems = getPageItems(); 133 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "Select Chapter", true, BOLD); 133 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "Select Chapter", true, EpdFontFamily::BOLD); 134 134 135 135 const auto& chapters = xtc->getChapters(); 136 136 if (chapters.empty()) {
+7 -7
src/activities/settings/OtaUpdateActivity.cpp
··· 127 127 const auto pageWidth = renderer.getScreenWidth(); 128 128 129 129 renderer.clearScreen(); 130 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "Update", true, BOLD); 130 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "Update", true, EpdFontFamily::BOLD); 131 131 132 132 if (state == CHECKING_FOR_UPDATE) { 133 - renderer.drawCenteredText(UI_10_FONT_ID, 300, "Checking for update...", true, BOLD); 133 + renderer.drawCenteredText(UI_10_FONT_ID, 300, "Checking for update...", true, EpdFontFamily::BOLD); 134 134 renderer.displayBuffer(); 135 135 return; 136 136 } 137 137 138 138 if (state == WAITING_CONFIRMATION) { 139 - renderer.drawCenteredText(UI_10_FONT_ID, 200, "New update available!", true, BOLD); 139 + renderer.drawCenteredText(UI_10_FONT_ID, 200, "New update available!", true, EpdFontFamily::BOLD); 140 140 renderer.drawText(UI_10_FONT_ID, 20, 250, "Current Version: " CROSSPOINT_VERSION); 141 141 renderer.drawText(UI_10_FONT_ID, 20, 270, ("New Version: " + updater.getLatestVersion()).c_str()); 142 142 ··· 147 147 } 148 148 149 149 if (state == UPDATE_IN_PROGRESS) { 150 - renderer.drawCenteredText(UI_10_FONT_ID, 310, "Updating...", true, BOLD); 150 + renderer.drawCenteredText(UI_10_FONT_ID, 310, "Updating...", true, EpdFontFamily::BOLD); 151 151 renderer.drawRect(20, 350, pageWidth - 40, 50); 152 152 renderer.fillRect(24, 354, static_cast<int>(updaterProgress * static_cast<float>(pageWidth - 44)), 42); 153 153 renderer.drawCenteredText(UI_10_FONT_ID, 420, ··· 160 160 } 161 161 162 162 if (state == NO_UPDATE) { 163 - renderer.drawCenteredText(UI_10_FONT_ID, 300, "No update available", true, BOLD); 163 + renderer.drawCenteredText(UI_10_FONT_ID, 300, "No update available", true, EpdFontFamily::BOLD); 164 164 renderer.displayBuffer(); 165 165 return; 166 166 } 167 167 168 168 if (state == FAILED) { 169 - renderer.drawCenteredText(UI_10_FONT_ID, 300, "Update failed", true, BOLD); 169 + renderer.drawCenteredText(UI_10_FONT_ID, 300, "Update failed", true, EpdFontFamily::BOLD); 170 170 renderer.displayBuffer(); 171 171 return; 172 172 } 173 173 174 174 if (state == FINISHED) { 175 - renderer.drawCenteredText(UI_10_FONT_ID, 300, "Update complete", true, BOLD); 175 + renderer.drawCenteredText(UI_10_FONT_ID, 300, "Update complete", true, EpdFontFamily::BOLD); 176 176 renderer.drawCenteredText(UI_10_FONT_ID, 350, "Press and hold power button to turn back on"); 177 177 renderer.displayBuffer(); 178 178 state = SHUTTING_DOWN;
+1 -1
src/activities/settings/SettingsActivity.cpp
··· 163 163 const auto pageHeight = renderer.getScreenHeight(); 164 164 165 165 // Draw header 166 - renderer.drawCenteredText(UI_12_FONT_ID, 15, "Settings", true, BOLD); 166 + renderer.drawCenteredText(UI_12_FONT_ID, 15, "Settings", true, EpdFontFamily::BOLD); 167 167 168 168 // Draw selection 169 169 renderer.fillRect(0, 60 + selectedSettingIndex * 30 - 2, pageWidth - 1, 30);
+2 -2
src/activities/util/FullScreenMessageActivity.h
··· 9 9 10 10 class FullScreenMessageActivity final : public Activity { 11 11 std::string text; 12 - EpdFontStyle style; 12 + EpdFontFamily::Style style; 13 13 EInkDisplay::RefreshMode refreshMode; 14 14 15 15 public: 16 16 explicit FullScreenMessageActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string text, 17 - const EpdFontStyle style = REGULAR, 17 + const EpdFontFamily::Style style = EpdFontFamily::REGULAR, 18 18 const EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) 19 19 : Activity("FullScreenMessage", renderer, mappedInput), 20 20 text(std::move(text)),
+3 -3
src/main.cpp
··· 151 151 const auto start = millis(); 152 152 bool abort = false; 153 153 // It takes us some time to wake up from deep sleep, so we need to subtract that from the duration 154 - uint16_t calibration = 29; 155 - uint16_t calibratedPressDuration = 154 + constexpr uint16_t calibration = 29; 155 + const uint16_t calibratedPressDuration = 156 156 (calibration < SETTINGS.getPowerButtonDuration()) ? SETTINGS.getPowerButtonDuration() - calibration : 1; 157 157 158 158 inputManager.update(); ··· 271 271 Serial.printf("[%lu] [ ] SD card initialization failed\n", millis()); 272 272 setupDisplayAndFonts(); 273 273 exitActivity(); 274 - enterNewActivity(new FullScreenMessageActivity(renderer, mappedInputManager, "SD card error", BOLD)); 274 + enterNewActivity(new FullScreenMessageActivity(renderer, mappedInputManager, "SD card error", EpdFontFamily::BOLD)); 275 275 return; 276 276 } 277 277