Kaydet (Commit) 9101ccfa authored tarafından Miklos Vajna's avatar Miklos Vajna

SwAnchoredObjectPosition::_GetHoriAlignmentValues: fix position of textboxes

The problem was that the right edge of the textbox was outside the parent
draw shape, which is unexpected for rectangle shapes.

Change-Id: I5154a61b07d3d8d894491e76923b3b017aa3ce8e
üst aba64281
......@@ -77,6 +77,8 @@ public:
* returned.
*/
static std::set<const SwFrmFmt*> findTextBoxes(const SwNode& rNode);
/// Is pObject a textbox of a drawinglayer shape?
static bool isTextBox(const SdrObject* pObject);
/// Build a textbox -> shape format map.
static std::map<SwFrmFmt*, SwFrmFmt*> findShapes(const SwDoc* pDoc);
/// Count number of shapes in the document, excluding TextBoxes.
......
......@@ -606,6 +606,19 @@ DECLARE_OOXMLEXPORT_TEST(testNumOverrideStart, "num-override-start.docx")
CPPUNIT_ASSERT_EQUAL(sal_Int16(3), comphelper::SequenceAsHashMap(xRules->getByIndex(1))["StartWith"].get<sal_Int16>());
}
DECLARE_OOXMLEXPORT_TEST(testTextboxRightEdge, "textbox-right-edge.docx")
{
// I'm fairly sure this is not specific to DOCX, but the doc model created
// by the ODF import doesn't trigger this bug, so let's test this here
// instead of uiwriter.
int nShapeLeft = parseDump("//SwAnchoredDrawObject/bounds", "left").toInt32();
int nShapeWidth = parseDump("//SwAnchoredDrawObject/bounds", "width").toInt32();
int nTextboxLeft = parseDump("//fly/infos/bounds", "left").toInt32();
int nTextboxWidth = parseDump("//fly/infos/bounds", "width").toInt32();
// This is a rectangle, make sure the right edge of the textbox is still
// inside the draw shape.
CPPUNIT_ASSERT(nShapeLeft + nShapeWidth >= nTextboxLeft + nTextboxWidth);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -181,6 +181,15 @@ bool lcl_isTextBox(SdrObject* pSdrObject, std::set<const SwFrmFmt*>& rTextBoxes)
return pObject && rTextBoxes.find(pObject->GetFmt()) != rTextBoxes.end();
}
bool SwTextBoxHelper::isTextBox(const SdrObject* pObject)
{
const SwVirtFlyDrawObj* pVirtFlyDrawObj = PTR_CAST(SwVirtFlyDrawObj, pObject);
if (!pVirtFlyDrawObj)
return false;
std::set<const SwFrmFmt*> aTextBoxes = findTextBoxes(pVirtFlyDrawObj->GetFmt()->GetDoc());
return aTextBoxes.find(pVirtFlyDrawObj->GetFmt()) != aTextBoxes.end();
}
sal_Int32 SwTextBoxHelper::getCount(SdrPage* pPage, std::set<const SwFrmFmt*>& rTextBoxes)
{
sal_Int32 nRet = 0;
......
......@@ -34,6 +34,7 @@
#include <editeng/ulspitem.hxx>
#include <ndtxt.hxx>
#include <IDocumentSettingAccess.hxx>
#include <textboxhelper.hxx>
using namespace ::com::sun::star;
using namespace objectpositioning;
......@@ -662,8 +663,13 @@ void SwAnchoredObjectPosition::_GetHoriAlignmentValues( const SwFrm& _rHoriOrie
default:
{
nWidth = (_rHoriOrientFrm.Frm().*fnRect->fnGetWidth)();
// When positioning TextBoxes, always ignore flys anchored at the
// text frame, as we do want to have the textbox overlap with its
// draw shape.
bool bIgnoreFlysAnchoredAtFrame = !_bObjWrapThrough || SwTextBoxHelper::isTextBox(&GetObject());
nOffset = _rHoriOrientFrm.IsTxtFrm() ?
static_cast<const SwTxtFrm&>(_rHoriOrientFrm).GetBaseOfstForFly( !_bObjWrapThrough ) :
static_cast<const SwTxtFrm&>(_rHoriOrientFrm).GetBaseOfstForFly( bIgnoreFlysAnchoredAtFrame ) :
0;
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment