tdf#155887 WMF Fix displaying images with size of EOF other that 3
The size of W_META_EOF (record indicates the end of the WMF metafile)
could be different than 3 (e.g. 6).
The MS Office is allowing different sizes of EOF,
and just properly finalizine parsing WMF file, and display its content.
Original bug report:
https://bz.apache.org/ooo/show_bug.cgi?id=42090
Change-Id: I21b72615c7f45fdca145e6240c6451d7d264d238
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153204
Tested-by: Jenkins
Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl>
diff --git a/emfio/qa/cppunit/wmf/data/EOF.wmf b/emfio/qa/cppunit/wmf/data/EOF.wmf
new file mode 100644
index 0000000..5e6af78
--- /dev/null
+++ b/emfio/qa/cppunit/wmf/data/EOF.wmf
Binary files differ
diff --git a/emfio/qa/cppunit/wmf/wmfimporttest.cxx b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
index a42e7f0..84154f4 100644
--- a/emfio/qa/cppunit/wmf/wmfimporttest.cxx
+++ b/emfio/qa/cppunit/wmf/wmfimporttest.cxx
@@ -45,6 +45,7 @@ public:
{
}
void testEOFWmf();
void testNonPlaceableWmf();
void testTdf88163NonPlaceableWmf();
void testTdf88163PlaceableWmf();
@@ -63,6 +64,7 @@ public:
void testStockObject();
CPPUNIT_TEST_SUITE(WmfTest);
CPPUNIT_TEST(testEOFWmf);
CPPUNIT_TEST(testNonPlaceableWmf);
CPPUNIT_TEST(testTdf88163NonPlaceableWmf);
CPPUNIT_TEST(testTdf88163PlaceableWmf);
@@ -82,6 +84,31 @@ public:
CPPUNIT_TEST_SUITE_END();
};
void WmfTest::testEOFWmf()
{
// tdf#155887 Test META_EOF with size different than 3
// It should be properly displayed as MS Office do
SvFileStream aFileStream(getFullUrl(u"EOF.wmf"), StreamMode::READ);
GDIMetaFile aGDIMetaFile;
ReadWindowMetafile(aFileStream, aGDIMetaFile);
MetafileXmlDump dumper;
xmlDocUniquePtr pDoc = dumpAndParse(dumper, aGDIMetaFile);
CPPUNIT_ASSERT(pDoc);
assertXPath(pDoc, "/metafile/push", 2);
assertXPath(pDoc, "/metafile/push[2]", "flags", "PushClipRegion");
assertXPath(pDoc, "/metafile/push[2]/fillcolor", 2);
assertXPath(pDoc, "/metafile/push[2]/fillcolor[1]", "color", "#000000");
assertXPath(pDoc, "/metafile/push[2]/fillcolor[2]", "color", "#d0d0d0");
assertXPath(pDoc, "/metafile/push[2]/linecolor", 60);
assertXPath(pDoc, "/metafile/push[2]/polyline", 209);
assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point", 5);
assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point[3]", "x", "16906");
assertXPath(pDoc, "/metafile/push[2]/polyline[1]/point[3]", "y", "12673");
assertXPath(pDoc, "/metafile/push[2]/textarray", 307);
}
void WmfTest::testNonPlaceableWmf()
{
SvFileStream aFileStream(getFullUrl(u"visio_import_source.wmf"), StreamMode::READ);
diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx
index fd954e9..b419fb3 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -156,6 +156,7 @@ namespace
#else
switch( nRecType )
{
case W_META_EOF: return "W_META_EOF";
case W_META_SETBKCOLOR: return "META_SETBKCOLOR";
case W_META_SETBKMODE: return "META_SETBKMODE";
case W_META_SETMAPMODE: return "META_SETMAPMODE";
@@ -1523,10 +1524,10 @@ namespace emfio
// changing mnUnitsPerInch as a tool to scale wmf
mnUnitsPerInch *= fRatio;
SAL_INFO("emfio", "Placeable bounds "
" left: " << aPlaceableBound.Left() << " top: " << aPlaceableBound.Top()
<< " right: " << aPlaceableBound.Right() << " bottom: " << aPlaceableBound.Bottom());
}
SAL_INFO("emfio", "Placeable bounds "
" left: " << aPlaceableBound.Left() << " top: " << aPlaceableBound.Top() <<
" right: " << aPlaceableBound.Right() << " bottom: " << aPlaceableBound.Bottom());
}
mpInputStream->Seek( nStrmPos );
@@ -1606,14 +1607,10 @@ namespace emfio
{
mpInputStream->ReadUInt32(mnRecSize).ReadUInt16( nFunction );
if (
!mpInputStream->good() ||
(mnRecSize < 3) ||
(mnRecSize == 3 && nFunction == W_META_EOF)
)
if (!mpInputStream->good() || (mnRecSize < 3) || (nFunction == W_META_EOF))
{
if( mpInputStream->eof() )
mpInputStream->SetError( SVSTREAM_FILEFORMAT_ERROR );
if (mpInputStream->eof())
mpInputStream->SetError(SVSTREAM_FILEFORMAT_ERROR);
break;
}
@@ -1727,10 +1724,11 @@ namespace emfio
bRet = false;
break;
}
else if ( nRSize == 3 && nFunction == W_META_EOF )
else if (nFunction == W_META_EOF)
{
break;
}
switch( nFunction )
{
case W_META_EOF:
@@ -2043,9 +2041,11 @@ namespace emfio
pStm->SetError( SVSTREAM_GENERALERROR );
bRet = false;
}
if (!bRet)
{
SAL_WARN("emfio", "Unable to calculate Placeable Bounds");
return;
}
if (aWinExt)
{
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 1088118..89e2f49 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -5949,14 +5949,14 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf145873)
CPPUNIT_ASSERT_MESSAGE("no object", pObject != nullptr);
// tdf#145873: Without the fix #2 in place, this test would have failed with
// - Expected: 13.23
// - Expected: 13.40
// - Actual : 3.57...
// - Delta : 0.1
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.23, pObject->getBounds().getWidth(), 0.1);
// - Expected: 13.49
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.40, pObject->getBounds().getWidth(), 0.1);
// - Expected: 13.79
// - Actual : 3.74...
// - Delta : 0.1
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.49, pObject->getBounds().getHeight(), 0.1);
CPPUNIT_ASSERT_DOUBLES_EQUAL(13.79, pObject->getBounds().getHeight(), 0.1);
}
CPPUNIT_TEST_FIXTURE(PdfExportTest, testPdfImageHyperlink)