summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-10-02 14:23:20 +0200
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2019-10-11 18:05:46 +0200
commit6733422ffc1d31fdc7519094c4182b148b55966a (patch)
treedfbeaa0c3165413112278e31726f0ccf4f70bfaa
parent7040869501dc2b5752822285c3e0616edd6276ef (diff)
tdf#124601 sw FollowTextFlow: fix hori pos of objects outside the current cell
The problem is that the image in the bugdoc's footer is anchored in one cell, but its position has a value that shifts it to the next column and next row. The next column is the problem for the horizontal position. So build on top of the previous vertical position fix, and make sure that CalcRelPosX() doesn't limit the position inside the current cell for an in-table, follow-text-flow, wrap-though image. Once that's in place, make sure that we don't try to grow the cell due to follow-text-flow, wrap-though objects in CalcPosition(), since in a wrap-through vs follow-text-flow situation, the wrap-though should have priority (should not affect size of cells). Finally, now that cells don't grow in this case, the previously added special-casing of footers in SwFlyFreeFrame::CheckClip() is no longer necessary. Not growing the cells means we don't try to re-position the object. (cherry picked from commit 29d7ece94318d3f03d079dff33ec15ff74f8febf) Change-Id: Ic55e4b5188704fa70314f91fe9a01987b6a56d7b Reviewed-on: https://gerrit.libreoffice.org/80650 Tested-by: Jenkins Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
-rw-r--r--sw/qa/extras/layout/layout.cxx16
-rw-r--r--sw/source/core/layout/flylay.cxx4
-rw-r--r--sw/source/core/objectpositioning/anchoredobjectposition.cxx8
-rw-r--r--sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx14
4 files changed, 37 insertions, 5 deletions
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 2dbd8a10a550..fa3720d2a977 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -3129,16 +3129,32 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf124601b)
// Table has an image, which is anchored in the first row, but its vertical position is large
// enough to be rendered in the second row.
// The shape has layoutInCell=1, so should match what Word does here.
+ // Also the horizontal position should be in the last column, even if the anchor is in the
+ // last-but-one column.
createDoc("tdf124601b.doc");
xmlDocPtr pXmlDoc = parseLayoutDump();
sal_Int32 nFlyTop = getXPath(pXmlDoc, "//fly/infos/bounds", "top").toInt32();
+ sal_Int32 nFlyLeft = getXPath(pXmlDoc, "//fly/infos/bounds", "left").toInt32();
+ sal_Int32 nFlyRight = nFlyLeft + getXPath(pXmlDoc, "//fly/infos/bounds", "width").toInt32();
sal_Int32 nSecondRowTop = getXPath(pXmlDoc, "//tab/row[2]/infos/bounds", "top").toInt32();
+ sal_Int32 nLastCellLeft
+ = getXPath(pXmlDoc, "//tab/row[1]/cell[5]/infos/bounds", "left").toInt32();
+ sal_Int32 nLastCellRight
+ = nLastCellLeft + getXPath(pXmlDoc, "//tab/row[1]/cell[5]/infos/bounds", "width").toInt32();
// Without the accompanying fix in place, this test would have failed with:
// - Expected greater than: 3736
// - Actual : 2852
// i.e. the image was still inside the first row.
CPPUNIT_ASSERT_GREATER(nSecondRowTop, nFlyTop);
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected greater than: 9640
+ // - Actual : 9639
+ // i.e. the right edge of the image was not within the bounds of the last column, the right edge
+ // was in the last-but-one column.
+ CPPUNIT_ASSERT_GREATER(nLastCellLeft, nFlyRight);
+ CPPUNIT_ASSERT_LESS(nLastCellRight, nFlyRight);
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index 3fb75b92b113..49afefe7a828 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -501,11 +501,11 @@ void SwFlyFreeFrame::CheckClip( const SwFormatFrameSize &rSz )
!GetDrawObjs() && !GetAnchorFrame()->IsInTab() )
{
SwFrame* pHeader = FindFooterOrHeader();
- // In a header or footer, correction of the position is no good idea.
+ // In a header, correction of the position is no good idea.
// If the fly moves, some paragraphs have to be formatted, this
// could cause a change of the height of the headerframe,
// now the flyframe can change its position and so on ...
- if ( !pHeader )
+ if ( !pHeader || !pHeader->IsHeaderFrame() )
{
const long nOld = getFrameArea().Top();
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index 09f6b33c5458..f60e097a01bb 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -881,7 +881,13 @@ SwTwips SwAnchoredObjectPosition::CalcRelPosX(
// keep object inside 'page' alignment layout frame
const SwFrame& rEnvironmentLayFrame =
_rEnvOfObj.GetHoriEnvironmentLayoutFrame( _rHoriOrientFrame );
- nRelPosX = AdjustHoriRelPos( rEnvironmentLayFrame, nRelPosX );
+ bool bFollowTextFlow = GetFrameFormat().GetFollowTextFlow().GetValue();
+ bool bWrapThrough = GetFrameFormat().GetSurround().GetSurround() != text::WrapTextMode_THROUGH;
+ // Don't try to keep wrap-though objects inside the cell, even if they are following text flow.
+ if (!rEnvironmentLayFrame.IsInTab() || !bFollowTextFlow || bWrapThrough)
+ {
+ nRelPosX = AdjustHoriRelPos( rEnvironmentLayFrame, nRelPosX );
+ }
// if object is a Writer fly frame and it's anchored to a content and
// it is horizontal positioned left or right, but not relative to character,
diff --git a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
index 25424dfaa3f3..e09e34b0f289 100644
--- a/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/tocntntanchoredobjectposition.cxx
@@ -629,7 +629,12 @@ void SwToContentAnchoredObjectPosition::CalcPosition()
// <lcl_DoesVertPosFits(..)>.
if ( pLayoutFrameToGrow )
{
- pLayoutFrameToGrow->Grow( nRelPosY - nAvail );
+ // No need to grow the anchor cell in case the follow-text-flow object
+ // is wrap-though.
+ if (!GetAnchorFrame().IsInTab() || !DoesObjFollowsTextFlow() || !bWrapThrough)
+ {
+ pLayoutFrameToGrow->Grow( nRelPosY - nAvail );
+ }
}
nRelPosY = 0;
}
@@ -786,7 +791,12 @@ void SwToContentAnchoredObjectPosition::CalcPosition()
}
if ( pLayoutFrameToGrow )
{
- pLayoutFrameToGrow->Grow( -nDist );
+ // No need to grow the anchor cell in case the follow-text-flow object
+ // is wrap-though.
+ if (!GetAnchorFrame().IsInTab() || !DoesObjFollowsTextFlow() || !bWrapThrough)
+ {
+ pLayoutFrameToGrow->Grow( -nDist );
+ }
}
}