QTextOdfWriter: fix exporting pixmaps to ODT
The QVariant returned by resource() can contain either a QPixmap or a QImage. The code here is now more similar to the one in qtextimagehandler.cpp. Also, the quality is 0 when not set, in which case we want a nice PNG rather than a very very low quality JPG with just a few large blocks of same-color pixels. Pick-to: 5.15 6.2 Change-Id: I49db542e2234c8068f85a636a81a7d8cdb7b5876 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
2d97c08bcd
commit
b67f887a04
@ -458,7 +458,7 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF
|
|||||||
name.prepend(QLatin1String("qrc"));
|
name.prepend(QLatin1String("qrc"));
|
||||||
QUrl url = QUrl(name);
|
QUrl url = QUrl(name);
|
||||||
const QVariant variant = m_document->resource(QTextDocument::ImageResource, url);
|
const QVariant variant = m_document->resource(QTextDocument::ImageResource, url);
|
||||||
if (variant.userType() == QMetaType::QImage) {
|
if (variant.userType() == QMetaType::QPixmap || variant.userType() == QMetaType::QImage) {
|
||||||
image = qvariant_cast<QImage>(variant);
|
image = qvariant_cast<QImage>(variant);
|
||||||
} else if (variant.userType() == QMetaType::QByteArray) {
|
} else if (variant.userType() == QMetaType::QByteArray) {
|
||||||
data = variant.toByteArray();
|
data = variant.toByteArray();
|
||||||
@ -479,7 +479,7 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF
|
|||||||
QBuffer imageBytes;
|
QBuffer imageBytes;
|
||||||
|
|
||||||
int imgQuality = imageFormat.quality();
|
int imgQuality = imageFormat.quality();
|
||||||
if (imgQuality >= 100 || imgQuality < 0 || image.hasAlphaChannel()) {
|
if (imgQuality >= 100 || imgQuality <= 0 || image.hasAlphaChannel()) {
|
||||||
QImageWriter imageWriter(&imageBytes, "png");
|
QImageWriter imageWriter(&imageBytes, "png");
|
||||||
imageWriter.write(image);
|
imageWriter.write(image);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user