From e024cad7c1365da6a198656c3ca0c32b28938e87 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 7 Nov 2017 10:42:27 +0100 Subject: tdf#113686 sw: handle sections when counting height of first content line When moving back a row that has a single text frame, it should not matter if that text frame is in a section frame or not. The problem was that the bugdoc has a split (outer) table, the follow's ShouldBwdMoved() returned false, as SwTabFrame::CalcHeightOfFirstContentLine() returned USHRT_MAX, as it had no idea how to calc the height of a text frame in a section frame. Fix this by looking "through" the section frame, and handling "text frame" and "text frame in section frame" the same way. Change-Id: Ic3605a1e2d28bfaa69bf18f31cfbf1e6e681c04f Reviewed-on: https://gerrit.libreoffice.org/44393 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/extras/uiwriter/data/tdf113686.fodt | 278 ++++++++++++++++++++++++++++++ sw/qa/extras/uiwriter/uiwriter.cxx | 28 +++ sw/source/core/layout/tabfrm.cxx | 11 +- 3 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 sw/qa/extras/uiwriter/data/tdf113686.fodt diff --git a/sw/qa/extras/uiwriter/data/tdf113686.fodt b/sw/qa/extras/uiwriter/data/tdf113686.fodt new file mode 100644 index 000000000000..7f7f8ac74a70 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/tdf113686.fodt @@ -0,0 +1,278 @@ + + + + + 0 + 0 + 49108 + 22809 + true + false + + + view2 + 9377 + 3007 + 0 + 0 + 49107 + 22807 + 0 + 0 + false + 100 + false + + + + + false + true + true + true + true + 0 + true + + false + false + false + false + false + false + false + false + false + false + false + false + false + true + false + true + true + false + false + false + false + + false + false + true + false + false + + false + false + false + false + true + 676140 + false + true + true + false + true + true + false + true + 0 + false + true + high-resolution + false + false + false + true + true + true + writer-data-source-ooxml + true + false + false + false + true + false + false + false + + false + false + 104774 + false + 1 + true + false + false + 0 + false + false + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Table2:A1-P01 + Table2:A1-P02 + Table2:A1-P03 + Table2:A1-P04 + Table2:A1-P05 + Table2:A1-P06 + Table2:A1-P07 + Table2:A1-P08 + Table2:A1-P09 + Table2:A1-P10 + + + Table2:B1 + + + Table2:C1 + + + Table2:D1 + + + + + Table1:A1 + + + + + + Table1:A2 + + + + + + + diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index aa7a422d6c0c..202c91cd9069 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -278,6 +278,7 @@ public: void testTdf112860(); void testTdf113287(); void testTdf113445(); + void testTdf113686(); #endif void testLinesInSectionInTable(); void testParagraphOfTextRange(); @@ -444,6 +445,7 @@ public: CPPUNIT_TEST(testTdf112860); CPPUNIT_TEST(testTdf113287); CPPUNIT_TEST(testTdf113445); + CPPUNIT_TEST(testTdf113686); #endif CPPUNIT_TEST(testLinesInSectionInTable); CPPUNIT_TEST(testParagraphOfTextRange); @@ -5381,6 +5383,32 @@ void SwUiWriterTest::testTdf113445() CPPUNIT_ASSERT_EQUAL(nCell3Top, nCell4Top); } +void SwUiWriterTest::testTdf113686() +{ + SwDoc* pDoc = createDoc("tdf113686.fodt"); + xmlDocPtr pXmlDoc = parseLayoutDump(); + assertXPath(pXmlDoc, "/root/page", 2); + sal_uInt32 nPage1LastNode = getXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell[1]/tab/row/cell[1]/txt[last()]", "txtNodeIndex").toUInt32(); + CPPUNIT_ASSERT_EQUAL(OUString("Table2:A1-P10"), pDoc->GetNodes()[nPage1LastNode]->GetTextNode()->GetText()); + sal_uInt32 nPage2FirstNode = getXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell[1]/section/txt[1]", "txtNodeIndex").toUInt32(); + CPPUNIT_ASSERT_EQUAL(OUString("Table1:A1"), pDoc->GetNodes()[nPage2FirstNode]->GetTextNode()->GetText()); + + // Remove page 2. + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + while (pWrtShell->GetCursor()->Start()->nNode.GetIndex() < nPage1LastNode) + pWrtShell->Down(/*bSelect=*/false); + pWrtShell->EndPara(); + for (int i = 0; i < 3; ++i) + pWrtShell->Up(/*bSelect=*/true); + pWrtShell->DelLeft(); + + // Assert that the second page is removed. + discardDumpedLayout(); + pXmlDoc = parseLayoutDump(); + // This was still 2, content from 2nd page was not moved. + assertXPath(pXmlDoc, "/root/page", 1); +} + void SwUiWriterTest::testTableInSectionInTable() { // The document has a table, containing a section, containing a nested diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx index af4d9ab0ba05..cc3a2f8d0058 100644 --- a/sw/source/core/layout/tabfrm.cxx +++ b/sw/source/core/layout/tabfrm.cxx @@ -5378,9 +5378,16 @@ static SwTwips lcl_CalcHeightOfFirstContentLine( const SwRowFrame& rSourceLine ) { nTmpHeight = static_cast(pTmp)->CalcHeightOfFirstContentLine(); } - else if ( pTmp->IsTextFrame() ) + else if (pTmp->IsTextFrame() || (pTmp->IsSctFrame() && pTmp->GetLower() && pTmp->GetLower()->IsTextFrame())) { - SwTextFrame* pTextFrame = const_cast(static_cast(pTmp)); + // Section frames don't influence the size/position of text + // frames, so 'text frame' and 'text frame in section frame' is + // the same case. + SwTextFrame* pTextFrame = nullptr; + if (pTmp->IsTextFrame()) + pTextFrame = const_cast(static_cast(pTmp)); + else + pTextFrame = const_cast(static_cast(pTmp->GetLower())); pTextFrame->GetFormatted(); nTmpHeight = pTextFrame->FirstLineHeight(); } -- cgit v1.2.3