summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-10-26 21:16:28 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-10-27 11:20:46 +0100
commit4a35c118a3a6b954827953674cc9bad435c394ee (patch)
tree634777e6795c0cbd049bd7bfdd8de3e4b1624b48 /emfio
parent6dfbab409032516e05a63fbc777b9147d1deb4ec (diff)
tdf#137413 EMF import: fix transparency in the PDF fallback case
Commit d75c5b38911557173c54a78f42ff220ab3918573 (tdf#136836 emfio: speed up import of EMF import when the orig PDF is available, 2020-09-17) improved both performance and correctness of the EMF import, in case it had a PDF fallback. It turns out that PDF fallback can be nominally non-transparent, and still the EMF equivalent supports transparency. Fix the problem by enabling transparency in the PDF-in-EMF case. Change-Id: I4d1585a5db6f28bd9c9cb380b5f193f4d5edcc8d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104849 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'emfio')
-rw-r--r--emfio/inc/mtftools.hxx5
-rw-r--r--emfio/qa/cppunit/emf/EmfImportTest.cxx15
-rw-r--r--emfio/source/reader/emfreader.cxx3
-rw-r--r--emfio/source/reader/mtftools.cxx9
4 files changed, 29 insertions, 3 deletions
diff --git a/emfio/inc/mtftools.hxx b/emfio/inc/mtftools.hxx
index 5c0c60973350..70471b66ea21 100644
--- a/emfio/inc/mtftools.hxx
+++ b/emfio/inc/mtftools.hxx
@@ -441,6 +441,7 @@ namespace emfio
BitmapEx aBmpEx;
tools::Rectangle aOutRect;
sal_uInt32 nWinRop;
+ bool m_bForceAlpha = false;
BSaveStruct(const Bitmap& rBmp, const tools::Rectangle& rOutRect, sal_uInt32 nRop)
: aBmpEx(rBmp)
@@ -448,10 +449,12 @@ namespace emfio
, nWinRop(nRop)
{}
- BSaveStruct(const BitmapEx& rBmpEx, const tools::Rectangle& rOutRect, sal_uInt32 nRop)
+ BSaveStruct(const BitmapEx& rBmpEx, const tools::Rectangle& rOutRect, sal_uInt32 nRop,
+ bool bForceAlpha = false)
: aBmpEx(rBmpEx)
, aOutRect(rOutRect)
, nWinRop(nRop)
+ , m_bForceAlpha(bForceAlpha)
{}
};
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 9d3364693530..45894455141e 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -26,6 +26,7 @@
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
#include <drawinglayer/tools/primitive2dxmldump.hxx>
+#include <vcl/bitmapaccess.hxx>
#include <memory>
@@ -243,6 +244,20 @@ void Test::TestPdfInEmf()
// i.e. there was no size hint, the shape with 14cm height had a bitmap-from-PDF fill, the PDF
// height was only 5cm, so it looked blurry.
CPPUNIT_ASSERT_EQUAL(14321.0, pVectorGraphicData->getSizeHint().getY());
+
+#if !defined(WNT) && !defined(MACOSX)
+ // Hmm, manual testing on Windows looks OK.
+ BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
+ AlphaMask aMask = aBitmapEx.GetAlpha();
+ Bitmap::ScopedReadAccess pAccess(aMask);
+ Color aColor(pAccess->GetPixel(0, 0));
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 220
+ // - Actual : 0
+ // i.e. the pixel at the top left corner was entirely opaque, while it should be mostly
+ // transparent.
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>(220), aColor.GetBlue());
+#endif
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/emfio/source/reader/emfreader.cxx b/emfio/source/reader/emfreader.cxx
index b47d0c86496f..1bc6339ff897 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -507,7 +507,8 @@ namespace emfio
// ours.
aGraphic.getVectorGraphicData()->setSizeHint(maSizeHint);
- maBmpSaveList.emplace_back(new BSaveStruct(aGraphic.GetBitmapEx(), aOutputRect, SRCCOPY));
+ maBmpSaveList.emplace_back(
+ new BSaveStruct(aGraphic.GetBitmapEx(), aOutputRect, SRCCOPY, /*bForceAlpha=*/true));
const std::shared_ptr<VectorGraphicData> pVectorGraphicData
= aGraphic.getVectorGraphicData();
if (!pVectorGraphicData)
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index e32b0f2be502..7cd1ff58093d 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -1837,7 +1837,14 @@ namespace emfio
{
if ( nRasterOperation == 0x33 )
aBitmap.Invert();
- ImplDrawBitmap( aPos, aSize, BitmapEx(aBitmap) );
+ if (pSave->m_bForceAlpha)
+ {
+ ImplDrawBitmap(aPos, aSize, pSave->aBmpEx);
+ }
+ else
+ {
+ ImplDrawBitmap(aPos, aSize, BitmapEx(aBitmap));
+ }
}
break;