mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
clang-format-fix
This commit is contained in:
parent
4f227ec277
commit
e97bcb717e
@ -690,8 +690,8 @@ int Epub::addVirtualSpineItem(const std::string& path) {
|
||||
}
|
||||
|
||||
bool Epub::isVirtualSpineItem(int spineIndex) const {
|
||||
int currentSpineSize = bookMetadataCache ? bookMetadataCache->getSpineCount() : 0;
|
||||
return spineIndex >= currentSpineSize;
|
||||
int currentSpineSize = bookMetadataCache ? bookMetadataCache->getSpineCount() : 0;
|
||||
return spineIndex >= currentSpineSize;
|
||||
}
|
||||
|
||||
int Epub::findVirtualSpineIndex(const std::string& filename) const {
|
||||
|
||||
@ -53,7 +53,6 @@ bool Page::serialize(FsFile& file) const {
|
||||
file.write(&isInlineFlag, 1);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <SdFat.h>
|
||||
#include <vector>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "FootnoteEntry.h"
|
||||
#include "blocks/TextBlock.h"
|
||||
@ -44,7 +44,7 @@ class Page {
|
||||
entry.number[2] = '\0';
|
||||
strncpy(entry.href, href, 63);
|
||||
entry.href[63] = '\0';
|
||||
entry.isInline = false; // Default
|
||||
entry.isInline = false; // Default
|
||||
footnotes.push_back(entry);
|
||||
}
|
||||
|
||||
|
||||
@ -163,8 +163,6 @@ bool Section::loadSectionFile(const int fontId, const float lineCompression, con
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Section::clearCache() const {
|
||||
if (!SdMan.exists(filePath.c_str())) {
|
||||
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;
|
||||
|
||||
if (isVirtual) {
|
||||
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/...
|
||||
// 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?
|
||||
// Assuming absolute path is fine.
|
||||
fileToParse = localPath;
|
||||
success = true;
|
||||
fileSize = 0; // Don't check size for progress bar on virtual items
|
||||
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/...
|
||||
// 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?
|
||||
// Assuming absolute path is fine.
|
||||
fileToParse = localPath;
|
||||
success = true;
|
||||
fileSize = 0; // Don't check size for progress bar on virtual items
|
||||
} else {
|
||||
// Normal file - stream from zip
|
||||
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;
|
||||
if (!SdMan.openFileForWrite("SCT", tmpHtmlPath, tmpHtml)) continue;
|
||||
success = epub->readItemContentsToStream(localPath, tmpHtml, 1024);
|
||||
fileSize = tmpHtml.size();
|
||||
tmpHtml.close();
|
||||
FsFile tmpHtml;
|
||||
if (!SdMan.openFileForWrite("SCT", tmpHtmlPath, tmpHtml)) continue;
|
||||
success = epub->readItemContentsToStream(localPath, tmpHtml, 1024);
|
||||
fileSize = tmpHtml.size();
|
||||
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) {
|
||||
Serial.printf("[%lu] [SCT] Failed to stream item contents\n", millis());
|
||||
return false;
|
||||
Serial.printf("[%lu] [SCT] Failed to stream item contents\n", millis());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -273,7 +273,6 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
|
||||
// PASS 2: Normal parsing
|
||||
// ============================================================================
|
||||
|
||||
|
||||
// Middle of skip
|
||||
if (self->skipUntilDepth < self->depth) {
|
||||
self->depth += 1;
|
||||
@ -293,9 +292,12 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
|
||||
if (self->partWordBufferIndex > 0) {
|
||||
// Copy of the existing flush logic
|
||||
EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR;
|
||||
if (self->boldUntilDepth < self->depth && self->italicUntilDepth < self->depth) fontStyle = EpdFontFamily::BOLD_ITALIC;
|
||||
else if (self->boldUntilDepth < self->depth) fontStyle = EpdFontFamily::BOLD;
|
||||
else if (self->italicUntilDepth < self->depth) fontStyle = EpdFontFamily::ITALIC;
|
||||
if (self->boldUntilDepth < self->depth && self->italicUntilDepth < self->depth)
|
||||
fontStyle = EpdFontFamily::BOLD_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->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) {
|
||||
auto* self = static_cast<ChapterHtmlSlimParser*>(userData);
|
||||
|
||||
|
||||
// Closing paragraph note in Pass 1
|
||||
if (strcmp(name, "p") == 0 && self->insideParagraphNote && self->depth - 1 == self->paragraphNoteDepth) {
|
||||
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)
|
||||
// We check "a" generally now, to handle both Noterefs AND resetting regular links
|
||||
if (strcmp(name, "a") == 0) {
|
||||
|
||||
// Track if this was a noteref so we can return early later
|
||||
bool wasNoteref = self->insideNoteref;
|
||||
|
||||
@ -758,7 +758,6 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (self->partWordBufferIndex > 0) {
|
||||
const bool shouldBreakText =
|
||||
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;
|
||||
}
|
||||
|
||||
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));
|
||||
currentPageNextY += lineHeight;
|
||||
} else if (currentPage) {
|
||||
|
||||
@ -8,10 +8,8 @@
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
|
||||
#include "EpubReaderFootnotesActivity.h"
|
||||
#include "EpubReaderMenuActivity.h"
|
||||
|
||||
#include "MappedInputManager.h"
|
||||
#include "RecentBooksStore.h"
|
||||
#include "ScreenComponents.h"
|
||||
@ -140,9 +138,9 @@ void EpubReaderActivity::loop() {
|
||||
[this, currentPage, totalPages](EpubReaderMenuActivity::MenuOption option) {
|
||||
// onSelectOption - handle menu choice
|
||||
if (option == EpubReaderMenuActivity::CHAPTERS) {
|
||||
// Show chapter selection
|
||||
exitActivity();
|
||||
enterNewActivity(new EpubReaderChapterSelectionActivity(
|
||||
// Show chapter selection
|
||||
exitActivity();
|
||||
enterNewActivity(new EpubReaderChapterSelectionActivity(
|
||||
this->renderer, this->mappedInput, epub, epub->getPath(), currentSpineIndex, currentPage, totalPages,
|
||||
[this] {
|
||||
exitActivity();
|
||||
@ -205,7 +203,6 @@ void EpubReaderActivity::loop() {
|
||||
onGoBack();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::PageBack) ||
|
||||
@ -414,17 +411,18 @@ void EpubReaderActivity::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
|
||||
currentPageFootnotes.clear();
|
||||
int maxFootnotes = (p->footnotes.size() < 8) ? p->footnotes.size() : 8;
|
||||
|
||||
for (int i = 0; i < maxFootnotes; i++) {
|
||||
const FootnoteEntry& footnote = p->footnotes[i];
|
||||
if (footnote.href[0] != '\0') {
|
||||
currentPageFootnotes.addFootnote(footnote.number, footnote.href);
|
||||
}
|
||||
const FootnoteEntry& footnote = p->footnotes[i];
|
||||
if (footnote.href[0] != '\0') {
|
||||
currentPageFootnotes.addFootnote(footnote.number, footnote.href);
|
||||
}
|
||||
}
|
||||
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 textY = screenHeight - orientedMarginBottom - 4;
|
||||
|
||||
|
||||
if (showProgress) {
|
||||
// Calculate progress in book
|
||||
// TODO: use progress values for UI
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
#include <freertos/semphr.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "activities/ActivityWithSubactivity.h"
|
||||
#include "EpubReaderFootnotesActivity.h"
|
||||
#include "activities/ActivityWithSubactivity.h"
|
||||
|
||||
class EpubReaderActivity final : public ActivityWithSubactivity {
|
||||
std::shared_ptr<Epub> epub;
|
||||
|
||||
@ -14,8 +14,6 @@ constexpr int SKIP_PAGE_MS = 700;
|
||||
|
||||
bool EpubReaderChapterSelectionActivity::hasSyncOption() const { return KOREADER_STORE.hasCredentials(); }
|
||||
|
||||
|
||||
|
||||
int EpubReaderChapterSelectionActivity::getPageItems() const {
|
||||
// Layout constants used in renderScreen
|
||||
constexpr int startY = 60;
|
||||
@ -92,7 +90,7 @@ void EpubReaderChapterSelectionActivity::onEnter() {
|
||||
// If sync is enabled, we prepend/append it to the selector range.
|
||||
|
||||
if (hasSyncOption()) {
|
||||
selectorIndex += 1; // Offset for top sync option
|
||||
selectorIndex += 1; // Offset for top sync option
|
||||
}
|
||||
|
||||
// Trigger first update
|
||||
@ -157,15 +155,15 @@ void EpubReaderChapterSelectionActivity::loop() {
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
// Check if sync option is selected
|
||||
if (hasSyncOption()) {
|
||||
if (selectorIndex == 0 || selectorIndex == totalItems - 1) {
|
||||
launchSyncActivity();
|
||||
return;
|
||||
}
|
||||
if (selectorIndex == 0 || selectorIndex == totalItems - 1) {
|
||||
launchSyncActivity();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// It's a chapter. Calculate index in filtered list.
|
||||
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()) {
|
||||
onSelectSpineIndex(filteredSpineIndices[filteredIndex]);
|
||||
@ -225,33 +223,33 @@ void EpubReaderChapterSelectionActivity::renderScreen() {
|
||||
|
||||
for (int i = pageStartIndex; i < totalItems && i < pageStartIndex + pageItems; i++) {
|
||||
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
|
||||
bool isSync = false;
|
||||
if (hasSyncOption()) {
|
||||
if (i == 0 || i == totalItems - 1) isSync = true;
|
||||
if (i == 0 || i == totalItems - 1) isSync = true;
|
||||
}
|
||||
|
||||
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 {
|
||||
// It's a filtered chapter
|
||||
int filteredIndex = i;
|
||||
if (hasSyncOption()) filteredIndex -= 1;
|
||||
// It's a filtered chapter
|
||||
int filteredIndex = i;
|
||||
if (hasSyncOption()) filteredIndex -= 1;
|
||||
|
||||
const int actualSpineIndex = filteredSpineIndices[filteredIndex];
|
||||
const int tocIndex = epub->getTocIndexForSpineIndex(actualSpineIndex);
|
||||
const int actualSpineIndex = filteredSpineIndices[filteredIndex];
|
||||
const int tocIndex = epub->getTocIndexForSpineIndex(actualSpineIndex);
|
||||
|
||||
if (tocIndex == -1) {
|
||||
renderer.drawText(UI_10_FONT_ID, 20, displayY, "Unnamed", !isSelected);
|
||||
} else {
|
||||
auto item = epub->getTocItem(tocIndex);
|
||||
const int indentSize = 20 + (item.level - 1) * 15;
|
||||
const std::string chapterName =
|
||||
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);
|
||||
}
|
||||
if (tocIndex == -1) {
|
||||
renderer.drawText(UI_10_FONT_ID, 20, displayY, "Unnamed", !isSelected);
|
||||
} else {
|
||||
auto item = epub->getTocItem(tocIndex);
|
||||
const int indentSize = 20 + (item.level - 1) * 15;
|
||||
const std::string chapterName =
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");
|
||||
|
||||
@ -27,7 +27,6 @@ class EpubReaderChapterSelectionActivity final : public ActivityWithSubactivity
|
||||
// This adapts automatically when switching between portrait and landscape.
|
||||
int getPageItems() const;
|
||||
|
||||
|
||||
// Check if sync option is available (credentials configured)
|
||||
bool hasSyncOption() const;
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#include "EpubReaderFootnotesActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <EpdFontFamily.h>
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "fontIds.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
void EpubReaderFootnotesActivity::onEnter() {
|
||||
selectedIndex = 0;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#include "EpubReaderMenuActivity.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <EpdFontFamily.h>
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "fontIds.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
constexpr int MENU_ITEMS_COUNT = 2;
|
||||
|
||||
@ -39,10 +39,10 @@ void EpubReaderMenuActivity::onExit() {
|
||||
}
|
||||
|
||||
void EpubReaderMenuActivity::loop() {
|
||||
const bool prevReleased =
|
||||
mappedInput.wasReleased(MappedInputManager::Button::Up) || mappedInput.wasReleased(MappedInputManager::Button::Left);
|
||||
const bool nextReleased =
|
||||
mappedInput.wasReleased(MappedInputManager::Button::Down) || mappedInput.wasReleased(MappedInputManager::Button::Right);
|
||||
const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::Up) ||
|
||||
mappedInput.wasReleased(MappedInputManager::Button::Left);
|
||||
const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::Down) ||
|
||||
mappedInput.wasReleased(MappedInputManager::Button::Right);
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
onSelectOption(static_cast<MenuOption>(selectorIndex));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user