fix: line break - flush word before <br/> tag (#525)

Manual implementation of upstream PR #525
Added flushPartWordBuffer() function and call it before <br/> handling
to fix issue where preceding word was incorrectly wrapped to new line
This commit is contained in:
cottongin 2026-01-27 07:36:06 -05:00
parent 991b6b5a01
commit 8920c62957
No known key found for this signature in database
GPG Key ID: 0ECC91FE4655C262
2 changed files with 24 additions and 0 deletions

View File

@ -80,6 +80,26 @@ void ChapterHtmlSlimParser::updateEffectiveInlineStyle() {
}
}
// Flush the contents of partWordBuffer to currentTextBlock
void ChapterHtmlSlimParser::flushPartWordBuffer() {
if (partWordBufferIndex == 0) return;
// Determine font style using effective styles
EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR;
if (effectiveBold && effectiveItalic) {
fontStyle = EpdFontFamily::BOLD_ITALIC;
} else if (effectiveBold) {
fontStyle = EpdFontFamily::BOLD;
} else if (effectiveItalic) {
fontStyle = EpdFontFamily::ITALIC;
}
// Flush the buffer
partWordBuffer[partWordBufferIndex] = '\0';
currentTextBlock->addWord(partWordBuffer, fontStyle, effectiveUnderline);
partWordBufferIndex = 0;
}
// start a new text block if needed
void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style, const BlockStyle& blockStyle) {
if (currentTextBlock) {
@ -341,6 +361,9 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
self->updateEffectiveInlineStyle();
} else if (matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS)) {
if (strcmp(name, "br") == 0) {
// Flush word preceding <br/> to currentTextBlock before calling startNewTextBlock
// This fixes issue where <br/> incorrectly wrapped the preceding word to a new line
self->flushPartWordBuffer();
self->startNewTextBlock(self->currentTextBlock->getStyle());
} else {
// Determine alignment from CSS or default

View File

@ -67,6 +67,7 @@ class ChapterHtmlSlimParser {
void updateEffectiveInlineStyle();
void startNewTextBlock(TextBlock::Style style);
void startNewTextBlock(TextBlock::Style style, const BlockStyle& blockStyle);
void flushPartWordBuffer();
void makePages();
// XML callbacks
static void XMLCALL startElement(void* userData, const XML_Char* name, const XML_Char** atts);