From 2612509d573b19769da81c9ee1c4918c8416a779 Mon Sep 17 00:00:00 2001 From: Jonas Diemer Date: Mon, 15 Dec 2025 19:33:47 +0100 Subject: [PATCH 1/2] add horizontal indent in first line of paragraph in case Extra Paragraph Spacing is OFF --- lib/Epub/Epub/ParsedText.cpp | 8 +++++++- lib/Epub/Epub/ParsedText.h | 4 +++- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Epub/Epub/ParsedText.cpp b/lib/Epub/Epub/ParsedText.cpp index 73a3988..1e19c39 100644 --- a/lib/Epub/Epub/ParsedText.cpp +++ b/lib/Epub/Epub/ParsedText.cpp @@ -122,7 +122,10 @@ void ParsedText::layoutAndExtractLines(const GfxRenderer& renderer, const int fo } // Calculate spacing - const int spareSpace = pageWidth - lineWordWidthSum; + int spareSpace = pageWidth - lineWordWidthSum; + if (!extraParagraphSpacing && wordWidthIndex ==0) { + spareSpace -= 3*spaceWidth; + } int spacing = spaceWidth; const bool isLastLine = lineBreak == totalWordCount; @@ -132,6 +135,9 @@ void ParsedText::layoutAndExtractLines(const GfxRenderer& renderer, const int fo // Calculate initial x position uint16_t xpos = 0; + if (!extraParagraphSpacing && wordWidthIndex ==0) { + xpos = 3*spaceWidth; + } if (style == TextBlock::RIGHT_ALIGN) { xpos = spareSpace - (lineWordCount - 1) * spaceWidth; } else if (style == TextBlock::CENTER_ALIGN) { diff --git a/lib/Epub/Epub/ParsedText.h b/lib/Epub/Epub/ParsedText.h index 188cb12..cfeb1f4 100644 --- a/lib/Epub/Epub/ParsedText.h +++ b/lib/Epub/Epub/ParsedText.h @@ -16,9 +16,11 @@ class ParsedText { std::list words; std::list wordStyles; TextBlock::BLOCK_STYLE style; + bool extraParagraphSpacing; public: - explicit ParsedText(const TextBlock::BLOCK_STYLE style) : style(style) {} + explicit ParsedText(const TextBlock::BLOCK_STYLE style, const bool extraParagraphSpacing) + : style(style), extraParagraphSpacing(extraParagraphSpacing) {} ~ParsedText() = default; void addWord(std::string word, EpdFontStyle fontStyle); diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 3c1f5ca..9c2e9e9 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -48,7 +48,7 @@ void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::BLOCK_STYLE style makePages(); } - currentTextBlock.reset(new ParsedText(style)); + currentTextBlock.reset(new ParsedText(style, extraParagraphSpacing)); } void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* name, const XML_Char** atts) { From b45d0238f4500cba824e524c18d3bc578faa3db6 Mon Sep 17 00:00:00 2001 From: Jonas Diemer Date: Mon, 15 Dec 2025 19:37:09 +0100 Subject: [PATCH 2/2] Treat tabs as whitespace (so they are properly stripped) --- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 9c2e9e9..ea15e1a 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -25,7 +25,7 @@ constexpr int NUM_IMAGE_TAGS = sizeof(IMAGE_TAGS) / sizeof(IMAGE_TAGS[0]); const char* SKIP_TAGS[] = {"head", "table"}; constexpr int NUM_SKIP_TAGS = sizeof(SKIP_TAGS) / sizeof(SKIP_TAGS[0]); -bool isWhitespace(const char c) { return c == ' ' || c == '\r' || c == '\n'; } +bool isWhitespace(const char c) { return c == ' ' || c == '\r' || c == '\n' || c == '\t'; } // given the start and end of a tag, check to see if it matches a known tag bool matches(const char* tag_name, const char* possible_tags[], const int possible_tag_count) {