From da5fdc151b75346a0f829d5f3027418f4d3a14e8 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Wed, 26 Jan 2022 11:08:53 +0000 Subject: [PATCH] XPS: fix multipiece image loading Turns out some files contain images saved in the xps archive as a directory containing multiple pieces, the first one being the image itself and the second one being empty. Of course this is quite a weird way to save an image, but it seems that it still is valid and other viewers are able to load it correctly. This change fixes the loading of multipiece images. (cherry picked from commit 3506fb2ea8bb052cc6e166e613370a1517248b37) --- generators/xps/generator_xps.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/generators/xps/generator_xps.cpp b/generators/xps/generator_xps.cpp index d1c640d2f..df5d67205 100644 --- a/generators/xps/generator_xps.cpp +++ b/generators/xps/generator_xps.cpp @@ -520,12 +520,6 @@ static const KArchiveEntry *loadEntry(KZip *archive, const QString &fileName, Qt return nullptr; } -static const KZipFileEntry *loadFile(KZip *archive, const QString &fileName, Qt::CaseSensitivity cs) -{ - const KArchiveEntry *entry = loadEntry(archive, fileName, cs); - return entry->isFile() ? static_cast(entry) : nullptr; -} - /** \return The name of a resource from the \p fileName */ @@ -1491,7 +1485,7 @@ QImage XpsPage::loadImageFromFile(const QString &fileName) } QString absoluteFileName = absolutePath(entryPath(m_fileName), fileName); - const KZipFileEntry *imageFile = loadFile(m_file->xpsArchive(), absoluteFileName, Qt::CaseInsensitive); + const KArchiveEntry *imageFile = loadEntry(m_file->xpsArchive(), absoluteFileName, Qt::CaseInsensitive); if (!imageFile) { // image not found return QImage(); @@ -1509,7 +1503,7 @@ QImage XpsPage::loadImageFromFile(const QString &fileName) */ QImage image; - QByteArray data = imageFile->data(); + QByteArray data = readFileOrDirectoryParts(imageFile); QBuffer buffer(&data); buffer.open(QBuffer::ReadOnly);