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 bbbb10a077
.
Change-Id: I394643e11862543177ba57958a26cd8ce06dc09c
This commit is contained in:
parent
d23508eebb
commit
01cd24df1e
2 changed files with 49 additions and 1 deletions
|
@ -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"))
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue