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.
This commit is contained in:
Fabio Bas 2022-01-26 11:08:53 +00:00 committed by Albert Astals Cid
parent 3e2e5cc95e
commit 3506fb2ea8

View File

@ -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);