summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2012-12-07 12:23:21 +0100
committerAndras Timar <atimar@suse.com>2013-01-13 22:00:39 +0100
commit1ee11a24aa30b498c0c2d741bee2085de55e69b6 (patch)
tree18ee326ecb621a3efc74391c4f93a731dd43dce4
parent5af027dbea69d9159b000c2bac41433d50b250a0 (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 (cherry picked from commit 01cd24df1ec7eaa53e9e2156d4d6890a7cc5996a) Reviewed-on: https://gerrit.libreoffice.org/1264 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/core/macros-test.cxx43
-rw-r--r--sw/source/core/unocore/unodraw.cxx7
2 files changed, 49 insertions, 1 deletions
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx
index 3f9262eb486c..cbabeafd8483 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"
SO2_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 1bf4b20f00b3..b8b566396cfc 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1382,7 +1382,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);