sw/qa/extras/layout/data/tdf152031-stair.odt |binary sw/qa/extras/layout/data/tdf152085-section-tblr.odt |binary sw/qa/extras/layout/layout2.cxx | 36 ++++++++++++++ sw/source/core/layout/calcmove.cxx | 49 +++++++++----------- 4 files changed, 59 insertions(+), 26 deletions(-)
New commits: commit ae6e57d99cfdeac69cc42cd82904c24edc866310 Author: Mark Hung <mark...@gmail.com> AuthorDate: Sat Nov 26 11:37:31 2022 +0800 Commit: Mark Hung <mark...@gmail.com> CommitDate: Thu Dec 15 04:50:11 2022 +0000 tdf#152031,tdf#152085 minimize impact to table layout. Revert two commits[1][2] that are related to fixing tdf#135991 ( but keep the unit tests) and rework the solution. Cases related to IsNeighborFrame() imply either IsCellFrame() ( a table cell ), or IsColumnFrame() ( a column inside a section ). Original patch[2] affected both of tables and sections. Try to limit the affected case to the section so it does not affect table layout for tdf#152031. [1] 1bf82b26aea3a403920a64cdfcb4671c947c7a01 Author: Mark Hung <mark...@gmail.com> Date: Fri Sep 9 16:09:47 2022 +0800 tdf#150642 fix table layout with vertical writing. [2] 1e21902106cbe57658bed03ed24d4d0863685cfd Author: Mark Hung <mark...@gmail.com> Date: Sun Aug 14 15:23:14 2022 +0800 tdf#135991 fix unexpected hidden RTL sections. Change-Id: If50e2b50b47352dad8eafebd6cce0af0530abefa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143317 Tested-by: Jenkins Reviewed-by: Mark Hung <mark...@gmail.com> diff --git a/sw/qa/extras/layout/data/tdf152031-stair.odt b/sw/qa/extras/layout/data/tdf152031-stair.odt new file mode 100644 index 000000000000..5171920e3496 Binary files /dev/null and b/sw/qa/extras/layout/data/tdf152031-stair.odt differ diff --git a/sw/qa/extras/layout/data/tdf152085-section-tblr.odt b/sw/qa/extras/layout/data/tdf152085-section-tblr.odt new file mode 100644 index 000000000000..3b454edc9b41 Binary files /dev/null and b/sw/qa/extras/layout/data/tdf152085-section-tblr.odt differ diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx index 259a6ea66292..b8ba46bebc20 100644 --- a/sw/qa/extras/layout/layout2.cxx +++ b/sw/qa/extras/layout/layout2.cxx @@ -10,6 +10,7 @@ #include <swmodeltestbase.hxx> #include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/text/XTextTable.hpp> #include <com/sun/star/linguistic2/XHyphenator.hpp> #include <comphelper/scopeguard.hxx> @@ -2485,6 +2486,41 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf150642) assertXPath(pDump, "//bounds[@right<0]", 0); } +CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf152085) +{ + createSwDoc("tdf152085-section-tblr.odt"); + auto pDump = parseLayoutDump(); + sal_Int32 nSectionHeight + = getXPath(pDump, "//section/infos/bounds", "bottom").toInt32(); // was 8391 + sal_Int32 nColumnHeight + = getXPath(pDump, "(//column/infos/bounds)[2]", "bottom").toInt32(); // was 16216 + CPPUNIT_ASSERT_MESSAGE("The column in a TBRL page should be shorter than the section.", + nColumnHeight <= nSectionHeight); +} + +CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf152031) +{ + createSwDoc("tdf152031-stair.odt"); + + // reproduce the bug by shrinking the table width. + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + // Shrink table width from 5" to 4" + sal_Int32 nWidth = getProperty<sal_Int32>(xTable, "Width") * 4 / 5; + + uno::Reference<beans::XPropertySet> xSet(xTable, uno::UNO_QUERY); + xSet->setPropertyValue("Width", uno::Any(nWidth)); + + auto pDump = parseLayoutDump(); + // There was a stair effect after change the table size. + sal_Int32 nLeft_Row1 = getXPath(pDump, "(//row/infos/bounds)[1]", "left").toInt32(); + sal_Int32 nLeft_Row2 = getXPath(pDump, "(//row/infos/bounds)[2]", "left").toInt32(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("left values of SwRowFrames should be consistent.", nLeft_Row1, + nLeft_Row2); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/calcmove.cxx b/sw/source/core/layout/calcmove.cxx index acb384f2b759..184373585928 100644 --- a/sw/source/core/layout/calcmove.cxx +++ b/sw/source/core/layout/calcmove.cxx @@ -949,7 +949,7 @@ void SwLayoutFrame::MakeAll(vcl::RenderContext* /*pRenderContext*/) const SwLayNotify aNotify( this ); bool bVert = IsVertical(); - SwRectFn fnRect = bVert ? ( IsVertLR() ? (IsVertLRBT() ? fnRectVertL2RB2T : fnRectVertL2R) : fnRectVert ) : fnRectHori; + SwRectFn fnRect = ( IsNeighbourFrame() == bVert )? fnRectHori : ( IsVertLR() ? (IsVertLRBT() ? fnRectVertL2RB2T : fnRectVertL2R) : fnRectVert ); std::optional<SwBorderAttrAccess> oAccess; const SwBorderAttrs*pAttrs = nullptr; @@ -975,36 +975,33 @@ void SwLayoutFrame::MakeAll(vcl::RenderContext* /*pRenderContext*/) { // Set FixSize; VarSize is set by Format() after calculating the PrtArea setFramePrintAreaValid(false); - SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this); - if (IsNeighbourFrame() && !bVert) + SwTwips nPrtWidth = (GetUpper()->getFramePrintArea().*fnRect->fnGetWidth)(); + if( bVert && ( IsBodyFrame() || IsFootnoteContFrame() ) ) + { + SwFrame* pNxt = GetPrev(); + while( pNxt && !pNxt->IsHeaderFrame() ) + pNxt = pNxt->GetPrev(); + if( pNxt ) + nPrtWidth -= pNxt->getFrameArea().Height(); + pNxt = GetNext(); + while( pNxt && !pNxt->IsFooterFrame() ) + pNxt = pNxt->GetNext(); + if( pNxt ) + nPrtWidth -= pNxt->getFrameArea().Height(); + } + + const tools::Long nDiff = nPrtWidth - (getFrameArea().*fnRect->fnGetWidth)(); + SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*this); + // SwRectFn switched between horizontal and vertical when bVert == IsNeighbourFrame(). + // We pick fnSubLeft or fnAddRight that is correspondant to SwRectFn->fnAddBottom + if( ( IsCellFrame() && IsRightToLeft() ) || ( IsColumnFrame() && bVert && !IsVertLR() ) ) { - SwTwips nPrtHeight = (GetUpper()->getFramePrintArea().*fnRect->fnGetHeight)(); - const tools::Long nDiff = nPrtHeight - (getFrameArea().*fnRect->fnGetHeight)(); - (aFrm.*fnRect->fnAddBottom)( nDiff ); + (aFrm.*fnRect->fnSubLeft)( nDiff ); } else { - SwTwips nPrtWidth = (GetUpper()->getFramePrintArea().*fnRect->fnGetWidth)(); - if( bVert && ( IsBodyFrame() || IsFootnoteContFrame() ) ) - { - SwFrame* pNxt = GetPrev(); - while( pNxt && !pNxt->IsHeaderFrame() ) - pNxt = pNxt->GetPrev(); - if( pNxt ) - nPrtWidth -= pNxt->getFrameArea().Height(); - pNxt = GetNext(); - while( pNxt && !pNxt->IsFooterFrame() ) - pNxt = pNxt->GetNext(); - if( pNxt ) - nPrtWidth -= pNxt->getFrameArea().Height(); - } - - const tools::Long nDiff = nPrtWidth - (getFrameArea().*fnRect->fnGetWidth)(); - if(IsRightToLeft() ) - (aFrm.*fnRect->fnSubLeft)( nDiff ); - else - (aFrm.*fnRect->fnAddRight)( nDiff ); + (aFrm.*fnRect->fnAddRight)( nDiff ); } } else