diff --git a/lib/Epub/Epub/Section.cpp b/lib/Epub/Epub/Section.cpp index e33c9c05..b241f671 100644 --- a/lib/Epub/Epub/Section.cpp +++ b/lib/Epub/Epub/Section.cpp @@ -245,11 +245,11 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c viewportHeight, hyphenationEnabled); std::vector lut = {}; - ChapterHtmlSlimParser visitor( + std::unique_ptr visitor(new ChapterHtmlSlimParser( fileToParse, renderer, fontId, lineCompression, extraParagraphSpacing, paragraphAlignment, viewportWidth, viewportHeight, hyphenationEnabled, [this, &lut](std::unique_ptr page) { lut.emplace_back(this->onPageComplete(std::move(page))); }, - progressFn); + progressFn)); Hyphenator::setPreferredLanguage(epub->getLanguage()); @@ -257,7 +257,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c std::set rewrittenInlineIds; int noterefCount = 0; - visitor.setNoterefCallback([this, ¬erefCount, &rewrittenInlineIds](Noteref& noteref) { + visitor->setNoterefCallback([this, ¬erefCount, &rewrittenInlineIds](Noteref& noteref) { // Extract the ID from the href for tracking std::string href(noteref.href); @@ -277,7 +277,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c noterefCount++; }); - success = visitor.parseAndBuildPages(); + success = visitor->parseAndBuildPages(); if (!isVirtual) { SdMan.remove(tmpHtmlPath.c_str()); @@ -293,9 +293,9 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c // --- Footnote Generation Logic (Merged from HEAD) --- // Inline footnotes - for (int i = 0; i < visitor.inlineFootnoteCount; i++) { - const char* inlineId = visitor.inlineFootnotes[i].id; - const char* inlineText = visitor.inlineFootnotes[i].text; + for (int i = 0; i < visitor->inlineFootnoteCount; i++) { + const char* inlineId = visitor->inlineFootnotes[i].id; + const char* inlineText = visitor->inlineFootnotes[i].text; if (rewrittenInlineIds.find(std::string(inlineId)) == rewrittenInlineIds.end()) continue; if (!inlineText || strlen(inlineText) == 0) continue; @@ -326,9 +326,9 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c } // Paragraph notes - for (int i = 0; i < visitor.paragraphNoteCount; i++) { - const char* pnoteId = visitor.paragraphNotes[i].id; - const char* pnoteText = visitor.paragraphNotes[i].text; + for (int i = 0; i < visitor->paragraphNoteCount; i++) { + const char* pnoteId = visitor->paragraphNotes[i].id; + const char* pnoteText = visitor->paragraphNotes[i].text; if (!pnoteText || strlen(pnoteText) == 0) continue; if (rewrittenInlineIds.find(std::string(pnoteId)) == rewrittenInlineIds.end()) continue; diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h index f6ea0b24..50a6ff0f 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h @@ -90,12 +90,12 @@ class ChapterHtmlSlimParser { bool insideParagraphNote = false; int paragraphNoteDepth = 0; char currentParagraphNoteId[16] = {0}; - static constexpr int MAX_PNOTE_BUFFER = 512; + static constexpr int MAX_PNOTE_BUFFER = 256; char currentParagraphNoteText[MAX_PNOTE_BUFFER] = {0}; int currentParagraphNoteTextLen = 0; // Temporary buffer for accumulation, will be copied to dynamic allocation - static constexpr int MAX_ASIDE_BUFFER = 2048; + static constexpr int MAX_ASIDE_BUFFER = 1024; char currentAsideText[MAX_ASIDE_BUFFER] = {0}; int currentAsideTextLen = 0; @@ -116,7 +116,7 @@ class ChapterHtmlSlimParser { InlineFootnote inlineFootnotes[16]; int inlineFootnoteCount = 0; // paragraph notes - ParagraphNote paragraphNotes[32]; + ParagraphNote paragraphNotes[16]; int paragraphNoteCount = 0; explicit ChapterHtmlSlimParser(const std::string& filepath, GfxRenderer& renderer, const int fontId,