clang-format-fix

This commit is contained in:
Uri Tauber 2026-01-26 16:46:16 +02:00
parent 4f227ec277
commit e97bcb717e
11 changed files with 81 additions and 91 deletions

View File

@ -690,8 +690,8 @@ int Epub::addVirtualSpineItem(const std::string& path) {
} }
bool Epub::isVirtualSpineItem(int spineIndex) const { bool Epub::isVirtualSpineItem(int spineIndex) const {
int currentSpineSize = bookMetadataCache ? bookMetadataCache->getSpineCount() : 0; int currentSpineSize = bookMetadataCache ? bookMetadataCache->getSpineCount() : 0;
return spineIndex >= currentSpineSize; return spineIndex >= currentSpineSize;
} }
int Epub::findVirtualSpineIndex(const std::string& filename) const { int Epub::findVirtualSpineIndex(const std::string& filename) const {

View File

@ -53,7 +53,6 @@ bool Page::serialize(FsFile& file) const {
file.write(&isInlineFlag, 1); file.write(&isInlineFlag, 1);
} }
return true; return true;
} }

View File

@ -1,7 +1,7 @@
#include <SdFat.h> #include <SdFat.h>
#include <vector>
#include <utility> #include <utility>
#include <vector>
#include "FootnoteEntry.h" #include "FootnoteEntry.h"
#include "blocks/TextBlock.h" #include "blocks/TextBlock.h"
@ -44,7 +44,7 @@ class Page {
entry.number[2] = '\0'; entry.number[2] = '\0';
strncpy(entry.href, href, 63); strncpy(entry.href, href, 63);
entry.href[63] = '\0'; entry.href[63] = '\0';
entry.isInline = false; // Default entry.isInline = false; // Default
footnotes.push_back(entry); footnotes.push_back(entry);
} }

View File

@ -163,8 +163,6 @@ bool Section::loadSectionFile(const int fontId, const float lineCompression, con
return true; return true;
} }
bool Section::clearCache() const { bool Section::clearCache() const {
if (!SdMan.exists(filePath.c_str())) { if (!SdMan.exists(filePath.c_str())) {
Serial.printf("[%lu] [SCT] Cache does not exist, no action needed\n", millis()); Serial.printf("[%lu] [SCT] Cache does not exist, no action needed\n", millis());
@ -203,33 +201,33 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c
std::string fileToParse = tmpHtmlPath; std::string fileToParse = tmpHtmlPath;
if (isVirtual) { if (isVirtual) {
Serial.printf("[%lu] [SCT] Processing virtual spine item: %s\n", millis(), localPath.c_str()); Serial.printf("[%lu] [SCT] Processing virtual spine item: %s\n", millis(), localPath.c_str());
// For virtual items, the path is already on SD, e.g. /sd/cache/... // For virtual items, the path is already on SD, e.g. /sd/cache/...
// But we need to make sure the parser can read it. // But we need to make sure the parser can read it.
// If it starts with /sd/, we might need to strip it if using SdFat with root? // If it starts with /sd/, we might need to strip it if using SdFat with root?
// Assuming absolute path is fine. // Assuming absolute path is fine.
fileToParse = localPath; fileToParse = localPath;
success = true; success = true;
fileSize = 0; // Don't check size for progress bar on virtual items fileSize = 0; // Don't check size for progress bar on virtual items
} else { } else {
// Normal file - stream from zip // Normal file - stream from zip
for (int attempt = 0; attempt < 3 && !success; attempt++) { for (int attempt = 0; attempt < 3 && !success; attempt++) {
if (attempt > 0) delay(50); if (attempt > 0) delay(50);
if (SdMan.exists(tmpHtmlPath.c_str())) SdMan.remove(tmpHtmlPath.c_str()); if (SdMan.exists(tmpHtmlPath.c_str())) SdMan.remove(tmpHtmlPath.c_str());
FsFile tmpHtml; FsFile tmpHtml;
if (!SdMan.openFileForWrite("SCT", tmpHtmlPath, tmpHtml)) continue; if (!SdMan.openFileForWrite("SCT", tmpHtmlPath, tmpHtml)) continue;
success = epub->readItemContentsToStream(localPath, tmpHtml, 1024); success = epub->readItemContentsToStream(localPath, tmpHtml, 1024);
fileSize = tmpHtml.size(); fileSize = tmpHtml.size();
tmpHtml.close(); tmpHtml.close();
if (!success && SdMan.exists(tmpHtmlPath.c_str())) SdMan.remove(tmpHtmlPath.c_str()); if (!success && SdMan.exists(tmpHtmlPath.c_str())) SdMan.remove(tmpHtmlPath.c_str());
} }
if (!success) { if (!success) {
Serial.printf("[%lu] [SCT] Failed to stream item contents\n", millis()); Serial.printf("[%lu] [SCT] Failed to stream item contents\n", millis());
return false; return false;
} }
} }

View File

@ -273,7 +273,6 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
// PASS 2: Normal parsing // PASS 2: Normal parsing
// ============================================================================ // ============================================================================
// Middle of skip // Middle of skip
if (self->skipUntilDepth < self->depth) { if (self->skipUntilDepth < self->depth) {
self->depth += 1; self->depth += 1;
@ -293,9 +292,12 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
if (self->partWordBufferIndex > 0) { if (self->partWordBufferIndex > 0) {
// Copy of the existing flush logic // Copy of the existing flush logic
EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR; EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR;
if (self->boldUntilDepth < self->depth && self->italicUntilDepth < self->depth) fontStyle = EpdFontFamily::BOLD_ITALIC; if (self->boldUntilDepth < self->depth && self->italicUntilDepth < self->depth)
else if (self->boldUntilDepth < self->depth) fontStyle = EpdFontFamily::BOLD; fontStyle = EpdFontFamily::BOLD_ITALIC;
else if (self->italicUntilDepth < self->depth) fontStyle = EpdFontFamily::ITALIC; else if (self->boldUntilDepth < self->depth)
fontStyle = EpdFontFamily::BOLD;
else if (self->italicUntilDepth < self->depth)
fontStyle = EpdFontFamily::ITALIC;
self->partWordBuffer[self->partWordBufferIndex] = '\0'; self->partWordBuffer[self->partWordBufferIndex] = '\0';
self->currentTextBlock->addWord(std::move(replaceHtmlEntities(self->partWordBuffer)), fontStyle); self->currentTextBlock->addWord(std::move(replaceHtmlEntities(self->partWordBuffer)), fontStyle);
@ -611,7 +613,6 @@ void XMLCALL ChapterHtmlSlimParser::characterData(void* userData, const XML_Char
void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* name) { void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* name) {
auto* self = static_cast<ChapterHtmlSlimParser*>(userData); auto* self = static_cast<ChapterHtmlSlimParser*>(userData);
// Closing paragraph note in Pass 1 // Closing paragraph note in Pass 1
if (strcmp(name, "p") == 0 && self->insideParagraphNote && self->depth - 1 == self->paragraphNoteDepth) { if (strcmp(name, "p") == 0 && self->insideParagraphNote && self->depth - 1 == self->paragraphNoteDepth) {
if (self->isPass1CollectingAsides && self->currentParagraphNoteTextLen > 0 && self->paragraphNoteCount < 32 && if (self->isPass1CollectingAsides && self->currentParagraphNoteTextLen > 0 && self->paragraphNoteCount < 32 &&
@ -691,7 +692,6 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n
// [MODIFIED] 2. Handle 'a' tags (Anchors/Footnotes) // [MODIFIED] 2. Handle 'a' tags (Anchors/Footnotes)
// We check "a" generally now, to handle both Noterefs AND resetting regular links // We check "a" generally now, to handle both Noterefs AND resetting regular links
if (strcmp(name, "a") == 0) { if (strcmp(name, "a") == 0) {
// Track if this was a noteref so we can return early later // Track if this was a noteref so we can return early later
bool wasNoteref = self->insideNoteref; bool wasNoteref = self->insideNoteref;
@ -758,7 +758,6 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n
} }
} }
if (self->partWordBufferIndex > 0) { if (self->partWordBufferIndex > 0) {
const bool shouldBreakText = const bool shouldBreakText =
matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS) || matches(name, HEADER_TAGS, NUM_HEADER_TAGS) || matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS) || matches(name, HEADER_TAGS, NUM_HEADER_TAGS) ||
@ -989,7 +988,7 @@ void ChapterHtmlSlimParser::addLineToPage(std::shared_ptr<TextBlock> line) {
currentPageNextY = 0; currentPageNextY = 0;
} }
if (currentPage && currentPage->elements.size() < 24) { // Assuming generic capacity check or vector size if (currentPage && currentPage->elements.size() < 24) { // Assuming generic capacity check or vector size
currentPage->elements.push_back(std::make_shared<PageLine>(line, 0, currentPageNextY)); currentPage->elements.push_back(std::make_shared<PageLine>(line, 0, currentPageNextY));
currentPageNextY += lineHeight; currentPageNextY += lineHeight;
} else if (currentPage) { } else if (currentPage) {

View File

@ -8,10 +8,8 @@
#include "CrossPointSettings.h" #include "CrossPointSettings.h"
#include "CrossPointState.h" #include "CrossPointState.h"
#include "EpubReaderChapterSelectionActivity.h" #include "EpubReaderChapterSelectionActivity.h"
#include "EpubReaderFootnotesActivity.h" #include "EpubReaderFootnotesActivity.h"
#include "EpubReaderMenuActivity.h" #include "EpubReaderMenuActivity.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "RecentBooksStore.h" #include "RecentBooksStore.h"
#include "ScreenComponents.h" #include "ScreenComponents.h"
@ -140,9 +138,9 @@ void EpubReaderActivity::loop() {
[this, currentPage, totalPages](EpubReaderMenuActivity::MenuOption option) { [this, currentPage, totalPages](EpubReaderMenuActivity::MenuOption option) {
// onSelectOption - handle menu choice // onSelectOption - handle menu choice
if (option == EpubReaderMenuActivity::CHAPTERS) { if (option == EpubReaderMenuActivity::CHAPTERS) {
// Show chapter selection // Show chapter selection
exitActivity(); exitActivity();
enterNewActivity(new EpubReaderChapterSelectionActivity( enterNewActivity(new EpubReaderChapterSelectionActivity(
this->renderer, this->mappedInput, epub, epub->getPath(), currentSpineIndex, currentPage, totalPages, this->renderer, this->mappedInput, epub, epub->getPath(), currentSpineIndex, currentPage, totalPages,
[this] { [this] {
exitActivity(); exitActivity();
@ -205,7 +203,6 @@ void EpubReaderActivity::loop() {
onGoBack(); onGoBack();
return; return;
} }
} }
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) || const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
@ -414,17 +411,18 @@ void EpubReaderActivity::renderScreen() {
return renderScreen(); return renderScreen();
} }
Serial.printf("[%lu] [ERS] Page loaded: %d elements, %d footnotes\n", millis(), p->elements.size(), p->footnotes.size()); Serial.printf("[%lu] [ERS] Page loaded: %d elements, %d footnotes\n", millis(), p->elements.size(),
p->footnotes.size());
// Copy footnotes from page to currentPageFootnotes // Copy footnotes from page to currentPageFootnotes
currentPageFootnotes.clear(); currentPageFootnotes.clear();
int maxFootnotes = (p->footnotes.size() < 8) ? p->footnotes.size() : 8; int maxFootnotes = (p->footnotes.size() < 8) ? p->footnotes.size() : 8;
for (int i = 0; i < maxFootnotes; i++) { for (int i = 0; i < maxFootnotes; i++) {
const FootnoteEntry& footnote = p->footnotes[i]; const FootnoteEntry& footnote = p->footnotes[i];
if (footnote.href[0] != '\0') { if (footnote.href[0] != '\0') {
currentPageFootnotes.addFootnote(footnote.number, footnote.href); currentPageFootnotes.addFootnote(footnote.number, footnote.href);
} }
} }
Serial.printf("[%lu] [ERS] Loaded %d footnotes for current page\n", millis(), p->footnotes.size()); Serial.printf("[%lu] [ERS] Loaded %d footnotes for current page\n", millis(), p->footnotes.size());
@ -499,7 +497,6 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
const auto screenHeight = renderer.getScreenHeight(); const auto screenHeight = renderer.getScreenHeight();
const auto textY = screenHeight - orientedMarginBottom - 4; const auto textY = screenHeight - orientedMarginBottom - 4;
if (showProgress) { if (showProgress) {
// Calculate progress in book // Calculate progress in book
// TODO: use progress values for UI // TODO: use progress values for UI

View File

@ -5,8 +5,8 @@
#include <freertos/semphr.h> #include <freertos/semphr.h>
#include <freertos/task.h> #include <freertos/task.h>
#include "activities/ActivityWithSubactivity.h"
#include "EpubReaderFootnotesActivity.h" #include "EpubReaderFootnotesActivity.h"
#include "activities/ActivityWithSubactivity.h"
class EpubReaderActivity final : public ActivityWithSubactivity { class EpubReaderActivity final : public ActivityWithSubactivity {
std::shared_ptr<Epub> epub; std::shared_ptr<Epub> epub;

View File

@ -14,8 +14,6 @@ constexpr int SKIP_PAGE_MS = 700;
bool EpubReaderChapterSelectionActivity::hasSyncOption() const { return KOREADER_STORE.hasCredentials(); } bool EpubReaderChapterSelectionActivity::hasSyncOption() const { return KOREADER_STORE.hasCredentials(); }
int EpubReaderChapterSelectionActivity::getPageItems() const { int EpubReaderChapterSelectionActivity::getPageItems() const {
// Layout constants used in renderScreen // Layout constants used in renderScreen
constexpr int startY = 60; constexpr int startY = 60;
@ -92,7 +90,7 @@ void EpubReaderChapterSelectionActivity::onEnter() {
// If sync is enabled, we prepend/append it to the selector range. // If sync is enabled, we prepend/append it to the selector range.
if (hasSyncOption()) { if (hasSyncOption()) {
selectorIndex += 1; // Offset for top sync option selectorIndex += 1; // Offset for top sync option
} }
// Trigger first update // Trigger first update
@ -157,15 +155,15 @@ void EpubReaderChapterSelectionActivity::loop() {
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
// Check if sync option is selected // Check if sync option is selected
if (hasSyncOption()) { if (hasSyncOption()) {
if (selectorIndex == 0 || selectorIndex == totalItems - 1) { if (selectorIndex == 0 || selectorIndex == totalItems - 1) {
launchSyncActivity(); launchSyncActivity();
return; return;
} }
} }
// It's a chapter. Calculate index in filtered list. // It's a chapter. Calculate index in filtered list.
int filteredIndex = selectorIndex; int filteredIndex = selectorIndex;
if (hasSyncOption()) filteredIndex -= 1; // Remove top sync offset if (hasSyncOption()) filteredIndex -= 1; // Remove top sync offset
if (filteredIndex >= 0 && filteredIndex < filteredSpineIndices.size()) { if (filteredIndex >= 0 && filteredIndex < filteredSpineIndices.size()) {
onSelectSpineIndex(filteredSpineIndices[filteredIndex]); onSelectSpineIndex(filteredSpineIndices[filteredIndex]);
@ -225,33 +223,33 @@ void EpubReaderChapterSelectionActivity::renderScreen() {
for (int i = pageStartIndex; i < totalItems && i < pageStartIndex + pageItems; i++) { for (int i = pageStartIndex; i < totalItems && i < pageStartIndex + pageItems; i++) {
const int displayY = 60 + (i % pageItems) * 30; const int displayY = 60 + (i % pageItems) * 30;
const bool isSelected = (i == selectorIndex); // Use i for comparison const bool isSelected = (i == selectorIndex); // Use i for comparison
// Check for sync item // Check for sync item
bool isSync = false; bool isSync = false;
if (hasSyncOption()) { if (hasSyncOption()) {
if (i == 0 || i == totalItems - 1) isSync = true; if (i == 0 || i == totalItems - 1) isSync = true;
} }
if (isSync) { if (isSync) {
renderer.drawText(UI_10_FONT_ID, 20, displayY, ">> Sync Progress", !isSelected); renderer.drawText(UI_10_FONT_ID, 20, displayY, ">> Sync Progress", !isSelected);
} else { } else {
// It's a filtered chapter // It's a filtered chapter
int filteredIndex = i; int filteredIndex = i;
if (hasSyncOption()) filteredIndex -= 1; if (hasSyncOption()) filteredIndex -= 1;
const int actualSpineIndex = filteredSpineIndices[filteredIndex]; const int actualSpineIndex = filteredSpineIndices[filteredIndex];
const int tocIndex = epub->getTocIndexForSpineIndex(actualSpineIndex); const int tocIndex = epub->getTocIndexForSpineIndex(actualSpineIndex);
if (tocIndex == -1) { if (tocIndex == -1) {
renderer.drawText(UI_10_FONT_ID, 20, displayY, "Unnamed", !isSelected); renderer.drawText(UI_10_FONT_ID, 20, displayY, "Unnamed", !isSelected);
} else { } else {
auto item = epub->getTocItem(tocIndex); auto item = epub->getTocItem(tocIndex);
const int indentSize = 20 + (item.level - 1) * 15; const int indentSize = 20 + (item.level - 1) * 15;
const std::string chapterName = const std::string chapterName =
renderer.truncatedText(UI_10_FONT_ID, item.title.c_str(), pageWidth - 40 - indentSize); renderer.truncatedText(UI_10_FONT_ID, item.title.c_str(), pageWidth - 40 - indentSize);
renderer.drawText(UI_10_FONT_ID, indentSize, displayY, chapterName.c_str(), !isSelected); renderer.drawText(UI_10_FONT_ID, indentSize, displayY, chapterName.c_str(), !isSelected);
} }
} }
} }
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down"); const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");

View File

@ -27,7 +27,6 @@ class EpubReaderChapterSelectionActivity final : public ActivityWithSubactivity
// This adapts automatically when switching between portrait and landscape. // This adapts automatically when switching between portrait and landscape.
int getPageItems() const; int getPageItems() const;
// Check if sync option is available (credentials configured) // Check if sync option is available (credentials configured)
bool hasSyncOption() const; bool hasSyncOption() const;

View File

@ -1,10 +1,10 @@
#include "EpubReaderFootnotesActivity.h" #include "EpubReaderFootnotesActivity.h"
#include <GfxRenderer.h>
#include <EpdFontFamily.h> #include <EpdFontFamily.h>
#include <GfxRenderer.h>
#include "fontIds.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
void EpubReaderFootnotesActivity::onEnter() { void EpubReaderFootnotesActivity::onEnter() {
selectedIndex = 0; selectedIndex = 0;

View File

@ -1,10 +1,10 @@
#include "EpubReaderMenuActivity.h" #include "EpubReaderMenuActivity.h"
#include <GfxRenderer.h>
#include <EpdFontFamily.h> #include <EpdFontFamily.h>
#include <GfxRenderer.h>
#include "fontIds.h"
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "fontIds.h"
constexpr int MENU_ITEMS_COUNT = 2; constexpr int MENU_ITEMS_COUNT = 2;
@ -39,10 +39,10 @@ void EpubReaderMenuActivity::onExit() {
} }
void EpubReaderMenuActivity::loop() { void EpubReaderMenuActivity::loop() {
const bool prevReleased = const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::Up) ||
mappedInput.wasReleased(MappedInputManager::Button::Up) || mappedInput.wasReleased(MappedInputManager::Button::Left); mappedInput.wasReleased(MappedInputManager::Button::Left);
const bool nextReleased = const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::Down) ||
mappedInput.wasReleased(MappedInputManager::Button::Down) || mappedInput.wasReleased(MappedInputManager::Button::Right); mappedInput.wasReleased(MappedInputManager::Button::Right);
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
onSelectOption(static_cast<MenuOption>(selectorIndex)); onSelectOption(static_cast<MenuOption>(selectorIndex));