old render cleanup part 1
This commit is contained in:
38 files changed
+166
-1366
No files matched your search
@@ -17,13 +17,12 @@
|
||||
|
||||
// Load one zip member through the generic byte-source pipeline (EPUBs are zips).
|
||||
static QImage loadFromEpub(const QString &epubPath, const QString &entry,
|
||||
int displayWidth, const QSize &requestedSize)
|
||||
const QSize &requestedSize)
|
||||
{
|
||||
ZipByteSource source;
|
||||
if (!source.open(epubPath))
|
||||
return {};
|
||||
return EntryImageProvider::loadImageFromSource(source, entry, displayWidth,
|
||||
requestedSize);
|
||||
return EntryImageProvider::loadImageFromSource(source, entry, requestedSize);
|
||||
}
|
||||
|
||||
static EntryImageProvider makeEpubProvider()
|
||||
@@ -96,7 +95,7 @@ private slots:
|
||||
QVERIFY(!epubPath.isEmpty());
|
||||
|
||||
const QImage img = loadFromEpub(
|
||||
epubPath, QStringLiteral("OEBPS/Images/test.png"), 0, QSize());
|
||||
epubPath, QStringLiteral("OEBPS/Images/test.png"), QSize());
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
@@ -112,7 +111,7 @@ private slots:
|
||||
QVERIFY(!epubPath.isEmpty());
|
||||
|
||||
const QImage img = loadFromEpub(
|
||||
epubPath, QStringLiteral("OEBPS/Images/nonexistent.png"), 0, QSize());
|
||||
epubPath, QStringLiteral("OEBPS/Images/nonexistent.png"), QSize());
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
@@ -122,7 +121,7 @@ private slots:
|
||||
void requestImageReturnsNullWhenNoPath()
|
||||
{
|
||||
const QImage img = loadFromEpub(
|
||||
QString{}, QStringLiteral("OEBPS/Images/test.png"), 0, QSize());
|
||||
QString{}, QStringLiteral("OEBPS/Images/test.png"), QSize());
|
||||
QVERIFY(img.isNull());
|
||||
}
|
||||
|
||||
@@ -133,51 +132,20 @@ private slots:
|
||||
|
||||
// After clear the path is empty, so loadImageFromEpub with empty path returns null
|
||||
const QImage img = loadFromEpub(
|
||||
QString{}, QStringLiteral("OEBPS/Images/test.png"), 0, QSize());
|
||||
QString{}, QStringLiteral("OEBPS/Images/test.png"), QSize());
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
QVERIFY(img.isNull());
|
||||
}
|
||||
|
||||
void largeImageScaledToDisplayWidth()
|
||||
{
|
||||
const QString epubPath = buildEpubWithPng("img.png", 600, 400);
|
||||
QVERIFY(!epubPath.isEmpty());
|
||||
|
||||
const QImage img = loadFromEpub(
|
||||
epubPath, QStringLiteral("img.png"), 300, QSize());
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
QVERIFY(!img.isNull());
|
||||
QCOMPARE(img.width(), 300);
|
||||
QCOMPARE(img.height(), 200);
|
||||
QCOMPARE(img.size(), QSize(300, 200));
|
||||
}
|
||||
|
||||
void smallImageNotEnlarged()
|
||||
{
|
||||
const QString epubPath = buildEpubWithPng("img.png", 100, 100);
|
||||
QVERIFY(!epubPath.isEmpty());
|
||||
|
||||
const QImage img = loadFromEpub(
|
||||
epubPath, QStringLiteral("img.png"), 300, QSize());
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
QVERIFY(!img.isNull());
|
||||
QCOMPARE(img.width(), 100);
|
||||
QCOMPARE(img.height(), 100);
|
||||
}
|
||||
|
||||
void requestedSizeHonored()
|
||||
{
|
||||
const QString epubPath = buildEpubWithPng("img.png", 400, 300);
|
||||
QVERIFY(!epubPath.isEmpty());
|
||||
|
||||
const QImage img = loadFromEpub(
|
||||
epubPath, QStringLiteral("img.png"), 600, QSize(200, -1));
|
||||
epubPath, QStringLiteral("img.png"), QSize(200, -1));
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
@@ -196,7 +164,7 @@ private slots:
|
||||
|
||||
AsyncImageResponse response([epubPath] {
|
||||
return loadFromEpub(
|
||||
epubPath, QStringLiteral("img.png"), 0, QSize());
|
||||
epubPath, QStringLiteral("img.png"), QSize());
|
||||
});
|
||||
QSignalSpy spy(&response, &QQuickImageResponse::finished);
|
||||
response.run();
|
||||
@@ -214,7 +182,7 @@ private slots:
|
||||
|
||||
AsyncImageResponse response([epubPath] {
|
||||
return loadFromEpub(
|
||||
epubPath, QStringLiteral("img.png"), 0, QSize());
|
||||
epubPath, QStringLiteral("img.png"), QSize());
|
||||
});
|
||||
QSignalSpy spy(&response, &QQuickImageResponse::finished);
|
||||
response.cancel();
|
||||
@@ -232,7 +200,7 @@ private slots:
|
||||
|
||||
AsyncImageResponse response([epubPath] {
|
||||
return loadFromEpub(
|
||||
epubPath, QStringLiteral("img.png"), 0, QSize());
|
||||
epubPath, QStringLiteral("img.png"), QSize());
|
||||
});
|
||||
response.cancel();
|
||||
response.run();
|
||||
@@ -298,24 +266,6 @@ private slots:
|
||||
delete resp;
|
||||
}
|
||||
|
||||
void loadMethodHandlesEmbeddedUrlFormat()
|
||||
{
|
||||
const QString epubPath = buildEpubWithPng("img.png", 4, 4, qRgb(255, 0, 0));
|
||||
QVERIFY(!epubPath.isEmpty());
|
||||
|
||||
EntryImageProvider provider = makeEpubProvider();
|
||||
// m_epubPath is intentionally NOT set — embedded URL must supply it via query
|
||||
const QString encodedPath = QString::fromUtf8(QUrl::toPercentEncoding(epubPath));
|
||||
const QUrl url(QStringLiteral("image://epub/img.png?src=") + encodedPath);
|
||||
|
||||
const QImage img = provider.load(url, 0);
|
||||
|
||||
QFile::remove(epubPath);
|
||||
|
||||
QVERIFY(!img.isNull());
|
||||
QCOMPARE(img.pixel(0, 0), qRgb(255, 0, 0));
|
||||
}
|
||||
|
||||
void requestImageResponseFallsBackToProviderPath()
|
||||
{
|
||||
// Without a leading slash in id, the provider should use m_epubPath.
|
||||
@@ -387,7 +337,7 @@ private slots:
|
||||
QCOMPARE(source.listEntries(), QStringList{QStringLiteral("cover.png")});
|
||||
|
||||
const QImage img = EntryImageProvider::loadImageFromSource(
|
||||
source, QStringLiteral("cover.png"), 0, QSize());
|
||||
source, QStringLiteral("cover.png"), QSize());
|
||||
QVERIFY(!source.contentHash().isEmpty());
|
||||
|
||||
QFile::remove(path);
|
||||
|
||||
Reference in new issue
Block a user