hopefully true virtual list layout
This commit is contained in:
10 files changed
+522
-37
No files matched your search
@@ -311,6 +311,64 @@ private slots:
|
||||
// With useBookColours = true, (testX, testY) is drawn with border or background
|
||||
QVERIFY(imgTrue.pixelColor(testX, testY).alpha() > 0);
|
||||
}
|
||||
|
||||
void clipRectCullingSkipsOffscreenImage()
|
||||
{
|
||||
class TrackingResolver : public IBookImageResolver {
|
||||
public:
|
||||
int resolveCount = 0;
|
||||
QImage resolveImage(const QString &) override {
|
||||
++resolveCount;
|
||||
QImage img(100, 100, QImage::Format_RGB32);
|
||||
img.fill(Qt::blue);
|
||||
return img;
|
||||
}
|
||||
QSizeF imageSize(const QString &) override {
|
||||
return QSizeF(100, 100);
|
||||
}
|
||||
};
|
||||
|
||||
TrackingResolver resolver;
|
||||
KnuthPlassItem::setImageResolver(&resolver);
|
||||
|
||||
const QString html = QStringLiteral(
|
||||
"<p>First paragraph taking vertical space</p>"
|
||||
"<p><img src=\"image://epub/fig1.png\" width=\"100\" height=\"100\"/></p>"
|
||||
);
|
||||
LayoutParams params;
|
||||
params.contentWidth = 400;
|
||||
params.fontSize = 16;
|
||||
params.lineSpacing = 1.0;
|
||||
|
||||
auto layout = ChunkLayoutEngine::layoutChunk(html, params, &resolver);
|
||||
QVERIFY(!layout.images.isEmpty());
|
||||
const qreal imageTop = layout.images[0].targetRect.top();
|
||||
QVERIFY(imageTop > 20.0);
|
||||
|
||||
KnuthPlassItem item;
|
||||
item.setSize(QSizeF(400, layout.totalHeight));
|
||||
item.setLayout(QVariant::fromValue(layout));
|
||||
|
||||
// 1. Paint with clip above the image: image resolver must NOT be called
|
||||
QImage img(400, int(layout.totalHeight), QImage::Format_ARGB32_Premultiplied);
|
||||
img.fill(Qt::transparent);
|
||||
{
|
||||
QPainter p(&img);
|
||||
p.setClipRect(QRectF(0, 0, 400, imageTop - 5.0));
|
||||
item.paint(&p);
|
||||
}
|
||||
QCOMPARE(resolver.resolveCount, 0);
|
||||
|
||||
// 2. Paint with clip covering the image: image resolver must be called
|
||||
{
|
||||
QPainter p(&img);
|
||||
p.setClipRect(QRectF(0, 0, 400, imageTop + 50.0));
|
||||
item.paint(&p);
|
||||
}
|
||||
QVERIFY(resolver.resolveCount >= 1);
|
||||
|
||||
KnuthPlassItem::setImageResolver(nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ChunkLayoutEngineTest)
|
||||
|
||||
Reference in new issue
Block a user