x
This commit is contained in:
pc0124 2026-01-17 16:06:13 +08:00 committed by GitHub
parent c3dee887b5
commit 861db66e61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View File

@ -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>& 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<int>(lineHeight * spacingMultiplier);
currentPageNextY += spacingAmount;
}
}

View File

@ -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<void(std::unique_ptr<Page>)>& completePageFn,
const std::function<void(int)>& progressFn = nullptr)
: filepath(filepath),
@ -56,6 +57,7 @@ class ChapterHtmlSlimParser {
fontId(fontId),
lineCompression(lineCompression),
extraParagraphSpacing(extraParagraphSpacing),
indentParagraph(indentParagraph),
paragraphAlignment(paragraphAlignment),
viewportWidth(viewportWidth),
viewportHeight(viewportHeight),