diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-12-07 12:23:21 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-12-07 12:40:14 +0100 |
commit | 01cd24df1ec7eaa53e9e2156d4d6890a7cc5996a (patch) | |
tree | bf8598b414b61472455e00273b92289306a8f175 | |
parent | d23508eebba52d7e40c84b3cea17868192519654 (diff) |
fdo#55289: fix crash in SwXShape::setPropertyValue:
In the libreoffice-3-6 branch the docx import crashes here when setting
the anchor position of a shape, because the previous setting of the
AnchorType was not done properly: the position of the anchor in the
SwFmt did not match the actual position of the text attribute, so we get
these assertions: "Missing FlyInCnt-Hint." and crash.
This cannot be reproduced with the docx import on master, because on
master a different intermediate AnchorType is set, and transitioning
from that happens not to cause the crash. But it can be reproduced with
a unit test.
The regression was introduced in libreoffice-3-6 with
backport commit bbbb10a0774b9da546557632cd09c4f6958f8939.
Change-Id: I394643e11862543177ba57958a26cd8ce06dc09c
-rw-r--r-- | sw/qa/core/macros-test.cxx | 43 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 7 |
2 files changed, 49 insertions, 1 deletions
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx index 7d7197776554..bdd7deea1ab4 100644 --- a/sw/qa/core/macros-test.cxx +++ b/sw/qa/core/macros-test.cxx @@ -37,8 +37,15 @@ #include <com/sun/star/frame/XDesktop.hpp> #include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/document/MacroExecMode.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> #include <sfx2/app.hxx> #include <sfx2/docfilt.hxx> @@ -48,6 +55,7 @@ #include <basic/sbxdef.hxx> +#include <doc.hxx> #include "docsh.hxx" SV_DECL_REF(SwDocShell) @@ -73,6 +81,7 @@ public: //void testStarBasic(); void testVba(); + void testFdo55289(); CPPUNIT_TEST_SUITE(SwMacrosTest); #if !defined(MACOSX) && !defined(WNT) //enable this test if you want to play with star basic macros in unit tests @@ -80,6 +89,7 @@ public: //CPPUNIT_TEST(testStarBasic); CPPUNIT_TEST(testVba); #endif + CPPUNIT_TEST(testFdo55289); CPPUNIT_TEST_SUITE_END(); @@ -162,6 +172,39 @@ void SwMacrosTest::testVba() } } +void SwMacrosTest::testFdo55289() +{ + SwDoc *const pDoc = new SwDoc; + SwDocShellRef pDocShell = new SwDocShell(pDoc, SFX_CREATE_MODE_EMBEDDED); + // this needs to run with no layout to tickle the bugs in the special + // cases in SwXShape re-anchoring + assert(!pDoc->GetCurrentLayout()); + + uno::Reference<frame::XModel> const xModel(pDocShell->GetModel()); + uno::Reference<drawing::XDrawPageSupplier> const xDPS(xModel, UNO_QUERY); + uno::Reference<drawing::XShapes> const xShapes(xDPS->getDrawPage(), + UNO_QUERY); + uno::Reference<beans::XPropertySet> const xShape( + uno::Reference<lang::XMultiServiceFactory>(xModel, UNO_QUERY)-> + createInstance("com.sun.star.drawing.GraphicObjectShape"), + UNO_QUERY); + xShape->setPropertyValue("AnchorType", + makeAny(text::TextContentAnchorType_AT_PAGE)); + xShapes->add(uno::Reference<drawing::XShape>(xShape, UNO_QUERY)); + xShape->setPropertyValue("AnchorType", + makeAny(text::TextContentAnchorType_AT_CHARACTER)); + xShape->setPropertyValue("AnchorType", + makeAny(text::TextContentAnchorType_AS_CHARACTER)); + xShape->setPropertyValue("AnchorType", + makeAny(text::TextContentAnchorType_AT_CHARACTER)); + xShape->setPropertyValue("AnchorType", + makeAny(text::TextContentAnchorType_AS_CHARACTER)); + uno::Reference<text::XTextRange> const xEnd = + uno::Reference<text::XTextDocument>(xModel, UNO_QUERY)->getText()->getEnd(); + uno::Reference<text::XTextContent> const xShapeContent(xShape, UNO_QUERY); + xShapeContent->attach(xEnd); +} + SwMacrosTest::SwMacrosTest() : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data")) { diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 8193b082eeee..62b6bc54e980 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -1355,7 +1355,12 @@ void SwXShape::setPropertyValue(const rtl::OUString& rPropertyName, const uno::A SwFmtFlyCnt aFmt( pFlyFmt ); pNd->InsertItem(aFmt, aPam.GetPoint()->nContent.GetIndex(), 0 ); - //aPam.GetPoint()->nContent--; + aPam.GetPoint()->nContent--; // InsertItem moved it + SwFmtAnchor aNewAnchor( + dynamic_cast<const SwFmtAnchor&>( + aSet.Get(RES_ANCHOR))); + aNewAnchor.SetAnchor( aPam.GetPoint() ); + aSet.Put( aNewAnchor ); } if( bSetAttr ) pFmt->SetFmtAttr(aSet); |