fix page counter

This commit is contained in:
Agel committed 2026-10-30 15:47:53 +01:00
1 parent 511472bc73
commit da8abf0332
13 files changed
+310 -122

No files matched your search

@@ -4,19 +4,18 @@
namespace {
void countInlines(const QVector<InlineItem> &inlines, int &pChars, int &pWords)
int countInlines(const QVector<InlineItem> &inlines)
{
pChars = 0;
pWords = 0;
int pChars = 0;
for (const auto &inl : inlines) {
if (inl.kind == InlineItem::Kind::Text) {
pChars += inl.text.size();
pWords += inl.text.split(QLatin1Char(' '), Qt::SkipEmptyParts).size();
} else if (inl.kind == InlineItem::Kind::Image) {
pChars += 1;
pWords += 1;
const bool isSmallIcon = (inl.cssWidth > 0 && inl.cssWidth <= 48 && inl.cssHeight > 0 && inl.cssHeight <= 48);
pChars += isSmallIcon ? 1 : kNormalizedCharsPerPage;
}
}
return pChars;
}
} // namespace
@@ -233,13 +232,10 @@ void DocumentChunkBuilder::finishParagraph()
return;
}
int pChars = 0;
int pWords = 0;
countInlines(inlines, pChars, pWords);
const int pChars = countInlines(inlines);
m_currentChunk.blocks.append(m_currentParagraph);
m_currentChunk.charCount += pChars;
m_currentChunk.wordCount += pWords;
m_hasActiveParagraph = false;
m_currentParagraph = BlockItem();
@@ -277,12 +273,9 @@ void DocumentChunkBuilder::appendBlock(const BlockItem &block)
} else if (block.kind == BlockItem::Kind::Rule) {
appendRule(block.ruleColor);
} else if (block.kind == BlockItem::Kind::Paragraph) {
int pChars = 0;
int pWords = 0;
countInlines(block.inlines, pChars, pWords);
const int pChars = countInlines(block.inlines);
m_currentChunk.blocks.append(block);
m_currentChunk.charCount += pChars;
m_currentChunk.wordCount += pWords;
if (m_currentChunk.charCount >= m_targetChars) {
m_pendingFlush = true;