From 861db66e61d2b876b439667eb114d0deb8901b07 Mon Sep 17 00:00:00 2001 From: pc0124 Date: Sat, 17 Jan 2026 16:06:13 +0800 Subject: [PATCH] x x --- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 11 +++++++---- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index acddd81d..8fdbc3a7 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -51,7 +51,7 @@ void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style) { makePages(); } - currentTextBlock.reset(new ParsedText(style, extraParagraphSpacing)); + currentTextBlock.reset(new ParsedText(style, extraParagraphSpacing, indentParagraph)); } void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* name, const XML_Char** atts) { @@ -387,8 +387,11 @@ void ChapterHtmlSlimParser::makePages() { currentTextBlock->layoutAndExtractLines( renderer, fontId, viewportWidth, [this](const std::shared_ptr& textBlock) { addLineToPage(textBlock); }); - // Extra paragraph spacing if enabled - if (extraParagraphSpacing) { - currentPageNextY += lineHeight / 2; + // Apply paragraph spacing: 0->0%, 1->30%, 2->50%, 3->80%, 4->100%, 5->120%, 6->140% + if (extraParagraphSpacing > 0) { + const float spacingMultipliers[] = {0.0f, 0.3f, 0.5f, 0.8f, 1.0f, 1.2f, 1.4f}; + const float spacingMultiplier = spacingMultipliers[extraParagraphSpacing]; + const int spacingAmount = static_cast(lineHeight * spacingMultiplier); + currentPageNextY += spacingAmount; } } diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h index c559e157..accee555 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h @@ -32,7 +32,8 @@ class ChapterHtmlSlimParser { int16_t currentPageNextY = 0; int fontId; float lineCompression; - bool extraParagraphSpacing; + uint8_t extraParagraphSpacing; + uint8_t indentParagraph; uint8_t paragraphAlignment; uint16_t viewportWidth; uint16_t viewportHeight; @@ -46,9 +47,9 @@ class ChapterHtmlSlimParser { public: explicit ChapterHtmlSlimParser(const std::string& filepath, GfxRenderer& renderer, const int fontId, - const float lineCompression, const bool extraParagraphSpacing, - const uint8_t paragraphAlignment, const uint16_t viewportWidth, - const uint16_t viewportHeight, + const float lineCompression, const uint8_t extraParagraphSpacing, + const uint8_t indentParagraph, const uint8_t paragraphAlignment, + const uint16_t viewportWidth, const uint16_t viewportHeight, const std::function)>& completePageFn, const std::function& progressFn = nullptr) : filepath(filepath), @@ -56,6 +57,7 @@ class ChapterHtmlSlimParser { fontId(fontId), lineCompression(lineCompression), extraParagraphSpacing(extraParagraphSpacing), + indentParagraph(indentParagraph), paragraphAlignment(paragraphAlignment), viewportWidth(viewportWidth), viewportHeight(viewportHeight),