summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2022-04-05 14:07:36 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-04-06 16:41:57 +0200
commitf385661ec1463053c1ca51dc50db075c478de87c (patch)
tree253ba0bcc0b9b4f0d76490055699b89be122990f /emfio
parent4e8d6ccf97e29e5ea14e0d074074606f12040f36 (diff)
tdf#148359 Fix emfio regression: missing emf image
This patch fixes tdf#148359 which prevented the display of EMF images embedded in the rtf files or even loading when loading them directly. Looking into the problem caused by the cleanup commit 3e7dd04dd8ca1baea4b7918eb7a7080c595c4625, it became visible that while enums were converted to enum class, there was a cast that was wrongly ommited: - sal_uInt16 nStockId = static_cast<sal_uInt8>(nIndex); + StockObject nStockId = static_cast<StockObject>(nIndex); Now, it is re-written as: StockObject nStockId = static_cast<StockObject>(nIndex & 0xFF); The symptom was that the StockObject field was mishandled, and thus the shapes were displayed in white, instead of black. "Stock Logical Object" is discussed in the MS document for EMF: * [MS-EMF] v20210625 - pages 44, 45 and 182 A unit test is provided to make sure that the regression does not happen again. The test can be run by: make CPPUNIT_TEST_NAME=testStockObject -sr CppunitTest_emfio_wmf Change-Id: I9a7f1008e92a96d9fb12aeb7bd057af828c1722a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132540 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'emfio')
-rw-r--r--emfio/qa/cppunit/wmf/data/stockobject.emfbin0 -> 12708 bytes
-rw-r--r--emfio/qa/cppunit/wmf/wmfimporttest.cxx25
-rw-r--r--emfio/source/reader/mtftools.cxx2
3 files changed, 26 insertions, 1 deletions
diff --git a/emfio/qa/cppunit/wmf/data/stockobject.emf b/emfio/qa/cppunit/wmf/data/stockobject.emf
new file mode 100644
index 000000000000..8de7c1ae591c
--- /dev/null
+++ b/emfio/qa/cppunit/wmf/data/stockobject.emf
Binary files differ
diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
index b8c2218fdec2..d8a4ed82d0f0 100644
--- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx
+++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
@@ -56,6 +56,7 @@ public:
void testTdf99402();
void testTdf39894();
void testETO_PDY();
+ void testStockObject();
CPPUNIT_TEST_SUITE(WmfTest);
CPPUNIT_TEST(testNonPlaceableWmf);
@@ -69,6 +70,7 @@ public:
CPPUNIT_TEST(testTdf99402);
CPPUNIT_TEST(testTdf39894);
CPPUNIT_TEST(testETO_PDY);
+ CPPUNIT_TEST(testStockObject);
CPPUNIT_TEST_SUITE_END();
};
@@ -389,6 +391,29 @@ void WmfTest::testETO_PDY()
}
}
+void WmfTest::testStockObject()
+{
+ SvFileStream aFileStream(getFullUrl(u"stockobject.emf"), StreamMode::READ);
+ GDIMetaFile aGDIMetaFile;
+ ReadWindowMetafile(aFileStream, aGDIMetaFile);
+
+ MetafileXmlDump dumper;
+ xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
+
+ CPPUNIT_ASSERT(pDoc);
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: 42
+ // - Actual : 37
+ assertXPathChildren(pDoc, "/metafile/push[2]", 42);
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: 1
+ // - Actual : 0
+ // - In <>, XPath '/metafile/push[2]/fillcolor[2]' number of nodes is incorrect
+ assertXPath(pDoc, "/metafile/push[2]/fillcolor[2]", "color", "#000000");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(WmfTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index f829788dbd1b..5cb43ec68510 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -750,7 +750,7 @@ namespace emfio
if ( nIndex & ENHMETA_STOCK_OBJECT )
{
SAL_INFO ( "emfio", "\t\t ENHMETA_STOCK_OBJECT, StockObject Enumeration: 0x" << std::hex << nIndex );
- StockObject nStockId = static_cast<StockObject>(nIndex);
+ StockObject nStockId = static_cast<StockObject>(nIndex & 0xFF);
switch( nStockId )
{
case StockObject::WHITE_BRUSH :