diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 79e6e6c7..da8ac382 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -40,18 +40,18 @@ bool matches(const char* tag_name, const char* possible_tags[], const int possib return false; } -EpdFontFamily::Style getFontStyle(const int boldUntilDepth, const int italicUntilDepth, const int depth) { - if (boldUntilDepth < depth && italicUntilDepth < depth) { - return EpdFontFamily::BOLD_ITALIC; - } else if (boldUntilDepth < depth) { - return EpdFontFamily::BOLD; +void ChapterHtmlSlimParser::flushPartWordBuffer() { + EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR; + if (boldUntilDepth < depth) { + if (italicUntilDepth < depth) { + fontStyle = EpdFontFamily::BOLD_ITALIC; + } else { + fontStyle = EpdFontFamily::BOLD; + } } else if (italicUntilDepth < depth) { - return EpdFontFamily::ITALIC; + fontStyle = EpdFontFamily::ITALIC; } - return EpdFontFamily::REGULAR; -} -void ChapterHtmlSlimParser::flushPartWordBuffer(const EpdFontFamily::Style fontStyle) { partWordBuffer[partWordBufferIndex] = '\0'; currentTextBlock->addWord(partWordBuffer, fontStyle); partWordBufferIndex = 0; @@ -143,8 +143,7 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* } else if (matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS)) { if (strcmp(name, "br") == 0) { // flush word preceding
to currentTextBlock before calling startNewTextBlock - EpdFontFamily::Style fontStyle = getFontStyle(self->boldUntilDepth, self->italicUntilDepth, self->depth); - self->flushPartWordBuffer(fontStyle); + self->flushPartWordBuffer(); self->startNewTextBlock(self->currentTextBlock->getStyle()); } else { self->startNewTextBlock((TextBlock::Style)self->paragraphAlignment); @@ -169,13 +168,11 @@ void XMLCALL ChapterHtmlSlimParser::characterData(void* userData, const XML_Char return; } - EpdFontFamily::Style fontStyle = getFontStyle(self->boldUntilDepth, self->italicUntilDepth, self->depth); - for (int i = 0; i < len; i++) { if (isWhitespace(s[i])) { // Currently looking at whitespace, if there's anything in the partWordBuffer, flush it if (self->partWordBufferIndex > 0) { - self->flushPartWordBuffer(fontStyle); + self->flushPartWordBuffer(); } // Skip the whitespace char continue; @@ -197,7 +194,7 @@ void XMLCALL ChapterHtmlSlimParser::characterData(void* userData, const XML_Char // If we're about to run out of space, then cut the word off and start a new one if (self->partWordBufferIndex >= MAX_WORD_SIZE) { - self->flushPartWordBuffer(fontStyle); + self->flushPartWordBuffer(); } self->partWordBuffer[self->partWordBufferIndex++] = s[i]; @@ -228,9 +225,7 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n matches(name, BOLD_TAGS, NUM_BOLD_TAGS) || matches(name, ITALIC_TAGS, NUM_ITALIC_TAGS) || self->depth == 1; if (shouldBreakText) { - EpdFontFamily::Style fontStyle = getFontStyle(self->boldUntilDepth, self->italicUntilDepth, self->depth); - - self->flushPartWordBuffer(fontStyle); + self->flushPartWordBuffer(); } } diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h index d0dc235f..2d8ebe5c 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h @@ -39,7 +39,7 @@ class ChapterHtmlSlimParser { bool hyphenationEnabled; void startNewTextBlock(TextBlock::Style style); - void flushPartWordBuffer(EpdFontFamily::Style fontStyle); + void flushPartWordBuffer(); void makePages(); // XML callbacks static void XMLCALL startElement(void* userData, const XML_Char* name, const XML_Char** atts);