more performance optimizations + cleanup
This commit is contained in:
15 files changed
+396
-469
No files matched your search
@@ -369,6 +369,71 @@ private slots:
|
||||
|
||||
KnuthPlassItem::setImageResolver(nullptr);
|
||||
}
|
||||
|
||||
void contentChunkFontSizeScaling()
|
||||
{
|
||||
const QString html = QStringLiteral("<p>Testing dynamic font scaling directly on structured ContentChunk without re-parsing XML.</p>");
|
||||
auto chunks = HtmlBlockParser::parseChunks(html, QStringLiteral("section.xhtml"));
|
||||
QCOMPARE(chunks.size(), 1);
|
||||
const auto &chunk = chunks.first();
|
||||
|
||||
QVERIFY(chunk.wordCount > 5);
|
||||
QVERIFY(chunk.charCount > 20);
|
||||
|
||||
LayoutParams p16;
|
||||
p16.contentWidth = 400;
|
||||
p16.fontSize = 16;
|
||||
p16.lineSpacing = 1.0;
|
||||
auto prep16 = ChunkLayoutEngine::prepareChunk(chunk, 16);
|
||||
auto l16 = ChunkLayoutEngine::layoutPreparedChunk(prep16, p16);
|
||||
|
||||
LayoutParams p24;
|
||||
p24.contentWidth = 400;
|
||||
p24.fontSize = 24;
|
||||
p24.lineSpacing = 1.0;
|
||||
auto prep24 = ChunkLayoutEngine::prepareChunk(chunk, 24);
|
||||
auto l24 = ChunkLayoutEngine::layoutPreparedChunk(prep24, p24);
|
||||
|
||||
QVERIFY(l24.totalHeight > l16.totalHeight);
|
||||
QVERIFY(!l24.lines.isEmpty());
|
||||
QVERIFY(l24.lines[0].runs[0].font.pixelSize() > l16.lines[0].runs[0].font.pixelSize());
|
||||
}
|
||||
|
||||
void contentChunkPartitionAndUnnestedContainers()
|
||||
{
|
||||
const QString html = QStringLiteral(
|
||||
"<blockquote>"
|
||||
"<p>First paragraph inside a blockquote designed to be split across chunk boundaries cleanly.</p>"
|
||||
"<p>Second paragraph inside the same blockquote continuing the quote.</p>"
|
||||
"</blockquote>"
|
||||
);
|
||||
auto chunks = HtmlBlockParser::parseChunks(html, QStringLiteral("section1.xhtml"), 60);
|
||||
QVERIFY(chunks.size() >= 2);
|
||||
|
||||
QCOMPARE(chunks[0].sectionHref, QStringLiteral("section1.xhtml"));
|
||||
QCOMPARE(chunks[0].unnestedContainers, 0);
|
||||
QVERIFY(chunks[0].wordCount > 0);
|
||||
QVERIFY(chunks[0].charCount > 0);
|
||||
|
||||
QCOMPARE(chunks[1].sectionHref, QStringLiteral("section1.xhtml"));
|
||||
QCOMPARE(chunks[1].unnestedContainers, 1); // Carries the open blockquote container
|
||||
QVERIFY(chunks[1].wordCount > 0);
|
||||
QVERIFY(chunks[1].charCount > 0);
|
||||
|
||||
// Layout both chunks and verify decorations
|
||||
LayoutParams params;
|
||||
params.contentWidth = 400;
|
||||
params.fontSize = 16;
|
||||
params.lineSpacing = 1.0;
|
||||
|
||||
auto l1 = ChunkLayoutEngine::layoutPreparedChunk(ChunkLayoutEngine::prepareChunk(chunks[0], 16), params);
|
||||
auto l2 = ChunkLayoutEngine::layoutPreparedChunk(ChunkLayoutEngine::prepareChunk(chunks[1], 16), params);
|
||||
|
||||
QVERIFY(!l1.decorations.isEmpty());
|
||||
QVERIFY(l1.decorations[0].borderLeft > 0);
|
||||
QVERIFY(!l2.decorations.isEmpty());
|
||||
QVERIFY(l2.decorations[0].borderLeft > 0);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ChunkLayoutEngineTest)
|
||||
|
||||
Reference in new issue
Block a user