diff options
-rw-r--r-- | sw/qa/extras/ww8export/data/tdf126708_containsemf.odt | bin | 0 -> 13315 bytes | |||
-rw-r--r-- | sw/qa/extras/ww8export/ww8export3.cxx | 18 | ||||
-rw-r--r-- | vcl/source/filter/graphicfilter2.cxx | 48 |
3 files changed, 62 insertions, 4 deletions
diff --git a/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt b/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt Binary files differnew file mode 100644 index 000000000000..31b0fab8d02d --- /dev/null +++ b/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx index dfb20c81fc67..a38424cc3ce1 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/text/XFormField.hpp> #include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/text/XTextTablesSupplier.hpp> @@ -276,6 +277,23 @@ DECLARE_WW8EXPORT_TEST(testImageCommentAtChar, "image-comment-at-char.doc") getProperty<OUString>(getRun(xPara, 5), "TextPortionType")); } +DECLARE_WW8EXPORT_TEST(testTdf126708emf, "tdf126708_containsemf.odt") +{ + auto xShape = getShape(1); + // First check the size of the EMF graphic contained in the shape. + auto xGraphic = getProperty< uno::Reference<graphic::XGraphic> >( + xShape, "Graphic"); + auto xSize = getProperty<awt::Size>(xGraphic, "Size100thMM"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8501), xSize.Height); + CPPUNIT_ASSERT_EQUAL(sal_Int32(18939), xSize.Width); + + // Now check that the shape itself has a decent size. + // This size varies slightly when round tripping through doc format. + xSize = getProperty<awt::Size>(xShape, "Size"); + CPPUNIT_ASSERT(abs(xSize.Height - 7629) <= 6); + CPPUNIT_ASSERT(abs(xSize.Width - 17000) <= 6); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx index 27dd780b57c8..8839807aa962 100644 --- a/vcl/source/filter/graphicfilter2.cxx +++ b/vcl/source/filter/graphicfilter2.cxx @@ -1044,12 +1044,52 @@ bool GraphicDescriptor::ImpDetectWMF( SvStream&, bool ) return bRet; } -bool GraphicDescriptor::ImpDetectEMF( SvStream&, bool ) +bool GraphicDescriptor::ImpDetectEMF( SvStream& rStm, bool bExtendedInfo ) { - bool bRet = aPathExt.startsWith( "emf" ); - if (bRet) - nFormat = GraphicFileFormat::EMF; + sal_uInt32 nRecordType = 0; + bool bRet = false; + + sal_Int32 nStmPos = rStm.Tell(); + rStm.SetEndian( SvStreamEndian::LITTLE ); + rStm.ReadUInt32( nRecordType ); + + if ( nRecordType == 0x00000001 ) + { + sal_uInt32 nHeaderSize = 0; + sal_Int32 nBoundLeft = 0, nBoundTop = 0, nBoundRight = 0, nBoundBottom = 0; + sal_Int32 nFrameLeft = 0, nFrameTop = 0, nFrameRight = 0, nFrameBottom = 0; + sal_uInt32 nSignature = 0; + + rStm.ReadUInt32( nHeaderSize ); + rStm.ReadInt32( nBoundLeft ); + rStm.ReadInt32( nBoundTop ); + rStm.ReadInt32( nBoundRight ); + rStm.ReadInt32( nBoundBottom ); + rStm.ReadInt32( nFrameLeft ); + rStm.ReadInt32( nFrameTop ); + rStm.ReadInt32( nFrameRight ); + rStm.ReadInt32( nFrameBottom ); + rStm.ReadUInt32( nSignature ); + + if ( nSignature == 0x464d4520 ) + { + nFormat = GraphicFileFormat::EMF; + bRet = true; + if ( bExtendedInfo ) + { + // size in pixels + aPixSize.setWidth( nBoundRight - nBoundLeft + 1 ); + aPixSize.setHeight( nBoundBottom - nBoundTop + 1 ); + + // size in 0.01mm units + aLogSize.setWidth( nFrameRight - nFrameLeft + 1 ); + aLogSize.setHeight( nFrameBottom - nFrameTop + 1 ); + } + } + } + + rStm.Seek( nStmPos ); return bRet; } |