Compare commits

...

9 Commits

Author SHA1 Message Date
Jérôme Launay
94a87470b7
Merge 2614d1da28 into 063a1df851 2025-12-17 23:31:54 +00:00
Jérôme Launay
2614d1da28 clang-format-fix 2025-12-18 00:31:40 +01:00
Jérôme Launay
a29ff93f9c Revert "Fix: Footnotes - validate data integrity before render"
This reverts commit ad7e9bd267.
2025-12-18 00:28:21 +01:00
Jérôme Launay
c591c2e033 fix number of notes per page 2025-12-18 00:14:22 +01:00
Jérôme Launay
d34122177c deserialize inline notes 2025-12-18 00:07:48 +01:00
Jérôme Launay
ad7e9bd267 Fix: Footnotes - validate data integrity before render 2025-12-17 23:53:34 +01:00
Jérôme Launay
91a0677503 Fix: Footnotes crashes after Screen→Activity refactor 2025-12-17 23:46:01 +01:00
Jérôme Launay
b2985f87d3 fix stack task size after bad merge 2025-12-17 23:23:35 +01:00
Jérôme Launay
b042e3c790 fix merge master 2025-12-17 21:18:54 +01:00
8 changed files with 34 additions and 13 deletions

View File

@ -414,6 +414,7 @@ int Epub::findVirtualSpineIndex(const std::string& filename) const {
}
return -1;
}
size_t Epub::getBookSize() const { return getCumulativeSpineItemSize(getSpineItemsCount() - 1); }
// Calculate progress in book
@ -423,4 +424,4 @@ uint8_t Epub::calculateProgress(const int currentSpineIndex, const float current
size_t bookSize = getBookSize();
size_t sectionProgSize = currentSpineRead * curChapterSize;
return round(static_cast<float>(prevChapterSize + sectionProgSize) / bookSize * 100.0);
}
}

View File

@ -70,5 +70,5 @@ class Epub {
int findVirtualSpineIndex(const std::string& filename) const;
size_t getBookSize() const;
uint8_t calculateProgress(const int currentSpineIndex, const float currentSpineRead) const;
uint8_t calculateProgress(const int currentSpineIndex, const float currentSpineRead);
};

View File

@ -44,6 +44,8 @@ void Page::serialize(std::ostream& os) const {
for (int i = 0; i < footnoteCount; i++) {
os.write(footnotes[i].number, 3);
os.write(footnotes[i].href, 64);
uint8_t isInlineFlag = footnotes[i].isInline ? 1 : 0;
os.write(reinterpret_cast<const char*>(&isInlineFlag), 1);
}
}
@ -80,6 +82,9 @@ std::unique_ptr<Page> Page::deserialize(std::istream& is) {
for (int i = 0; i < page->footnoteCount; i++) {
is.read(page->footnotes[i].number, 3);
is.read(page->footnotes[i].href, 64);
uint8_t isInlineFlag = 0;
is.read(reinterpret_cast<char*>(&isInlineFlag), 1);
page->footnotes[i].isInline = (isInlineFlag != 0);
}
return page;

View File

@ -48,7 +48,7 @@ class Page {
elementCapacity = 24;
elements = new std::shared_ptr<PageElement>[elementCapacity];
footnoteCapacity = 8;
footnoteCapacity = 16;
footnotes = new FootnoteEntry[footnoteCapacity];
for (int i = 0; i < footnoteCapacity; i++) {
footnotes[i].number[0] = '\0';

View File

@ -60,7 +60,7 @@ void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::BLOCK_STYLE style
}
void ChapterHtmlSlimParser::addFootnoteToCurrentPage(const char* number, const char* href) {
if (currentPageFootnoteCount >= 32) return;
if (currentPageFootnoteCount >= 16) return;
Serial.printf("[%lu] [ADDFT] Adding footnote: num=%s, href=%s\n", millis(), number, href);

View File

@ -77,7 +77,7 @@ class ChapterHtmlSlimParser {
std::function<void(Noteref&)> noterefCallback = nullptr;
// Footnote tracking for current page
FootnoteEntry currentPageFootnotes[32];
FootnoteEntry currentPageFootnotes[16];
int currentPageFootnoteCount = 0;
// Inline footnotes (aside) tracking

View File

@ -52,7 +52,7 @@ void EpubReaderActivity::onEnter() {
updateRequired = true;
xTaskCreate(&EpubReaderActivity::taskTrampoline, "EpubReaderActivityTask",
8192, // Stack size
24576, // Stack size
this, // Parameters
1, // Priority
&displayTaskHandle // Task handle
@ -321,11 +321,15 @@ void EpubReaderActivity::renderScreen() {
return renderScreen();
}
Serial.printf("[%lu] [ERS] Page loaded: %d elements, %d footnotes\n", millis(), p->elementCount, p->footnoteCount);
// Copy footnotes from page to currentPageFootnotes
currentPageFootnotes.clear();
for (int i = 0; i < p->footnoteCount && i < 16; i++) {
int maxFootnotes = (p->footnoteCount < 8) ? p->footnoteCount : 8;
for (int i = 0; i < maxFootnotes; i++) {
FootnoteEntry* footnote = p->getFootnote(i);
if (footnote) {
if (footnote && footnote->href[0] != '\0') {
currentPageFootnotes.addFootnote(footnote->number, footnote->href);
}
}

View File

@ -8,14 +8,19 @@
class FootnotesData {
private:
FootnoteEntry entries[32];
FootnoteEntry entries[16];
int count;
public:
FootnotesData() : count(0) {}
FootnotesData() : count(0) {
for (int i = 0; i < 16; i++) {
entries[i].number[0] = '\0';
entries[i].href[0] = '\0';
}
}
void addFootnote(const char* number, const char* href) {
if (count < 32) {
if (count < 16 && number && href) {
strncpy(entries[count].number, number, 2);
entries[count].number[2] = '\0';
strncpy(entries[count].href, href, 63);
@ -24,7 +29,13 @@ class FootnotesData {
}
}
void clear() { count = 0; }
void clear() {
count = 0;
for (int i = 0; i < 16; i++) {
entries[i].number[0] = '\0';
entries[i].href[0] = '\0';
}
}
int getCount() const { return count; }
@ -58,4 +69,4 @@ class EpubReaderFootnotesActivity final : public Activity {
private:
void render();
};
};