diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2017-05-15 13:41:14 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-05-18 14:15:27 +0200 |
commit | 5477f7274e4df1210298c0f503a54eabc0f06bfc (patch) | |
tree | a6dff61ec7f6d51dbebb3512bdb3e57f19dc148a | |
parent | 63843a97262ccfa38d838a9cbbc3faadba8290a6 (diff) |
tdf#100072 zero height of shape's path was causing geometry errors
DOCX custom geometry shape's path width and height are now used
independently for scaling calculations.
Change-Id: I368dd4dc065b8f122c4eb2911261e45047f03c70
Reviewed-on: https://gerrit.libreoffice.org/37639
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | svx/source/customshapes/EnhancedCustomShape2d.cxx | 17 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 9 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf100072.docx (renamed from sw/qa/extras/ooxmlexport/data/tdf100072.docx) | bin | 7034 -> 7034 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 45 |
4 files changed, 60 insertions, 11 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx index c3c2d4c33099..c4de12bbcfc3 100644 --- a/svx/source/customshapes/EnhancedCustomShape2d.cxx +++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx @@ -651,10 +651,23 @@ void EnhancedCustomShape2d::SetPathSize( sal_Int32 nIndex ) "svx", "ooxml shape, path width: " << nCoordWidth << " height: " << nCoordHeight); + + // Try to set up scale separately, if given only width or height + // This is possible case in OOXML when only width or height is non-zero if ( nCoordWidth == 0 ) - fXScale = 1.0; + { + if ( nWidth ) + fXScale = (double)aLogicRect.GetWidth() / (double)nWidth; + else + fXScale = 1.0; + } if ( nCoordHeight == 0 ) - fYScale = 1.0; + { + if ( nHeight ) + fYScale = (double)aLogicRect.GetHeight() / (double)nHeight; + else + fYScale = 1.0; + } } if ( (sal_uInt32)nXRef != 0x80000000 && aLogicRect.GetHeight() ) { diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index ce8a77a02c8c..2aff1fb23ed1 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -490,15 +490,6 @@ DECLARE_OOXMLEXPORT_TEST(testTdf107033, "tdf107033.docx") CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(25), getProperty<sal_Int32>(xPageStyle, "FootnoteLineRelativeWidth")); } -DECLARE_OOXMLEXPORT_TEST(testTdf100072, "tdf100072.docx") -{ - // Ensure that shape has non-zero height - CPPUNIT_ASSERT(getShape(1)->getSize().Height > 0); - - // Ensure that shape left corner is within page (positive) - CPPUNIT_ASSERT(getShape(1)->getPosition().X > 0); -} - DECLARE_OOXMLEXPORT_TEST(testTdf107889, "tdf107889.docx") { uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); diff --git a/sw/qa/extras/ooxmlexport/data/tdf100072.docx b/sw/qa/extras/ooxmlimport/data/tdf100072.docx Binary files differindex 02b885b9aafa..02b885b9aafa 100644 --- a/sw/qa/extras/ooxmlexport/data/tdf100072.docx +++ b/sw/qa/extras/ooxmlimport/data/tdf100072.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 87ccce61d9b5..90e36f1ef593 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -24,6 +24,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp> #include <com/sun/star/drawing/PointSequenceSequence.hpp> +#include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/style/BreakType.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> @@ -59,6 +60,7 @@ #include <comphelper/propertysequence.hxx> #include <com/sun/star/drawing/HomogenMatrix3.hpp> #include <com/sun/star/awt/CharSet.hpp> +#include <test/mtfxmldump.hxx> class Test : public SwModelTestBase { @@ -1306,6 +1308,49 @@ DECLARE_OOXMLIMPORT_TEST(testTdf101627, "tdf101627.docx") CPPUNIT_ASSERT_EQUAL(sal_Int32(466), getProperty<sal_Int32>(xFrame, "Height")); } +DECLARE_OOXMLIMPORT_TEST(testTdf100072, "tdf100072.docx") +{ + uno::Reference<drawing::XShape> xShape = getShape(1); + + // Ensure that shape has non-zero height + CPPUNIT_ASSERT(xShape->getSize().Height > 0); + + // Ensure that shape left corner is within page (positive) + CPPUNIT_ASSERT(xShape->getPosition().X > 0); + + // Save the first shape to a metafile. + uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter = drawing::GraphicExportFilter::create(comphelper::getProcessComponentContext()); + uno::Reference<lang::XComponent> xSourceDoc(xShape, uno::UNO_QUERY); + xGraphicExporter->setSourceDocument(xSourceDoc); + + SvMemoryStream aStream; + uno::Reference<io::XOutputStream> xOutputStream(new utl::OStreamWrapper(aStream)); + uno::Sequence<beans::PropertyValue> aDescriptor = + { + beans::PropertyValue("OutputStream", sal_Int32(0), uno::makeAny(xOutputStream), beans::PropertyState_DIRECT_VALUE), + beans::PropertyValue("FilterName", sal_Int32(0), uno::makeAny(OUString("SVM")), beans::PropertyState_DIRECT_VALUE) + }; + xGraphicExporter->filter(aDescriptor); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + + // Read it back and dump it as an XML file. + Graphic aGraphic; + ReadGraphic(aStream, aGraphic); + const GDIMetaFile& rMetaFile = aGraphic.GetGDIMetaFile(); + MetafileXmlDump dumper; + xmlDocPtr pXmlDoc = dumper.dumpAndParse(rMetaFile); + + // Get first polyline rightside x coordinate + sal_Int32 nFirstEnd = getXPath(pXmlDoc, "/metafile/polyline[1]/point[2]", "x").toInt32(); + + // Get last stroke x coordinate + sal_Int32 nSecondEnd = getXPath(pXmlDoc, "/metafile/polyline[last()]/point[2]", "x").toInt32(); + + // Assert that the difference is less than half point. + CPPUNIT_ASSERT_MESSAGE("Shape line width does not match", abs(nFirstEnd - nSecondEnd) < 10); +} + + // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT CPPUNIT_PLUGIN_IMPLEMENT(); |