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 3506fb2ea8)
remotes/origin/release/21.12
Fabio Bas 4 years ago committed by Albert Astals Cid
parent 3e919b4287
commit da5fdc151b
  1. 10
      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<const KZipFileEntry *>(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);

Loading…
Cancel
Save