summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Deller <luke@deller.id.au>2019-08-07 00:22:12 +1000
committerMiklos Vajna <vmiklos@collabora.com>2019-08-07 16:43:21 +0200
commit6369cab9b1e16275c8700692bb717aec3c42d346 (patch)
tree86d3edc226c7bd4d5f92270d2f6e5df0349a725f
parent75903a0298218f89a199a5ac151ee0166f4469d7 (diff)
tdf#126708 Fix EMF image size in CLI .doc export
Implement EMF image size detection, to fix this bug where an EMF image gets zero size when exported to .doc format from the command line. Change-Id: If980c5d65d4880150815fd1df9704d9c1b3b93c9 Reviewed-on: https://gerrit.libreoffice.org/77031 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/qa/extras/ww8export/data/tdf126708_containsemf.odtbin0 -> 13315 bytes
-rw-r--r--sw/qa/extras/ww8export/ww8export3.cxx18
-rw-r--r--vcl/source/filter/graphicfilter2.cxx48
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
new file mode 100644
index 000000000000..31b0fab8d02d
--- /dev/null
+++ b/sw/qa/extras/ww8export/data/tdf126708_containsemf.odt
Binary files differ
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;
}