diff options
author | Mark Hung <marklh9@gmail.com> | 2018-05-26 22:34:49 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2018-06-12 16:59:26 +0200 |
commit | 5f42787232a5a2ece35d4c018df8a9b7c856919f (patch) | |
tree | 467a99a956ca537275f3e93e93ea576ab6d032b1 | |
parent | 389ccf384f21be3e06f3939db858a9b06c9dbbae (diff) |
tdf#117884: intersect border with paint area of upper frame.
This patch fix regression caused by e87cc12eaf53 and allow
table borders rendered in the left or right page margin.
Also add another test case (testTableExtrusion2) to assure
inner table can't have wider border than outer table.
Change-Id: I7a86b379dee08fb2f23385183a42d0ebde007370
Reviewed-on: https://gerrit.libreoffice.org/54862
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mark Hung <marklh9@gmail.com>
(cherry picked from commit 1e21902106cbe57658bed03ed24d4d0863685cfd)
Reviewed-on: https://gerrit.libreoffice.org/55663
-rwxr-xr-x | sw/qa/extras/layout/data/table-extrusion1.odt | bin | 0 -> 9234 bytes | |||
-rwxr-xr-x | sw/qa/extras/layout/data/table-extrusion2.odt | bin | 0 -> 9259 bytes | |||
-rwxr-xr-x[-rw-r--r--] | sw/qa/extras/layout/layout.cxx | 43 | ||||
-rw-r--r-- | sw/source/core/layout/paintfrm.cxx | 28 |
4 files changed, 53 insertions, 18 deletions
diff --git a/sw/qa/extras/layout/data/table-extrusion1.odt b/sw/qa/extras/layout/data/table-extrusion1.odt Binary files differnew file mode 100755 index 000000000000..10600fa54c86 --- /dev/null +++ b/sw/qa/extras/layout/data/table-extrusion1.odt diff --git a/sw/qa/extras/layout/data/table-extrusion2.odt b/sw/qa/extras/layout/data/table-extrusion2.odt Binary files differnew file mode 100755 index 000000000000..63fc74f46db8 --- /dev/null +++ b/sw/qa/extras/layout/data/table-extrusion2.odt diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index a7eb24e89208..2356832cc4ba 100644..100755 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -20,6 +20,8 @@ public: void testTdf116925(); void testTdf117028(); void testTdf106390(); + void testTableExtrusion1(); + void testTableExtrusion2(); void testTdf116848(); void testTdf117245(); @@ -28,6 +30,8 @@ public: CPPUNIT_TEST(testTdf116925); CPPUNIT_TEST(testTdf117028); CPPUNIT_TEST(testTdf106390); + CPPUNIT_TEST(testTableExtrusion1); + CPPUNIT_TEST(testTableExtrusion2); CPPUNIT_TEST(testTdf116848); CPPUNIT_TEST(testTdf117245); CPPUNIT_TEST_SUITE_END(); @@ -132,6 +136,45 @@ void SwLayoutWriter::testTdf106390() assertXPath(pXmlDoc, sXPath, 0); } +void SwLayoutWriter::testTableExtrusion1() +{ + SwDoc* pDoc = createDoc("table-extrusion1.odt"); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Dump the rendering of the first page as an XML file. + std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + xmlDocPtr pXmlDoc = dumper.dumpAndParse(*xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + sal_Int32 nRight = getXPath(pXmlDoc, "//sectrectclipregion", "right").toInt32(); + sal_Int32 nLeft = (nRight + getXPath(pXmlDoc, "(//rect)[1]", "right").toInt32()) / 2; + + // Expect table borders in right page margin. + const OString sXPath = "//polyline/point[@x>" + OString::number(nLeft) + " and @x<" + + OString::number(nRight) + "]"; + + assertXPath(pXmlDoc, sXPath, 4); +} + +void SwLayoutWriter::testTableExtrusion2() +{ + SwDoc* pDoc = createDoc("table-extrusion2.odt"); + SwDocShell* pShell = pDoc->GetDocShell(); + + // Dump the rendering of the first page as an XML file. + std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile(); + MetafileXmlDump dumper; + xmlDocPtr pXmlDoc = dumper.dumpAndParse(*xMetaFile); + CPPUNIT_ASSERT(pXmlDoc); + // End point position of the outer table. + sal_Int32 nX = getXPath(pXmlDoc, "(//polyline[1]/point)[2]", "x").toInt32(); + + // Do not allow inner table extrude outer table. + const OString sXPath = "//polyline/point[@x>" + OString::number(nX) + "]"; + + assertXPath(pXmlDoc, sXPath, 0); +} + void SwLayoutWriter::testTdf116848() { SwDoc* pDoc = createDoc("tdf116848.odt"); diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index cd76c222b040..b684c5ac1b2c 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -2308,8 +2308,8 @@ class SwTabFramePainter const SwTabFrame& mrTabFrame; void Insert( SwLineEntry&, bool bHori ); - void Insert( const SwFrame& rFrame, const SvxBoxItem& rBoxItem ); - void HandleFrame( const SwLayoutFrame& rFrame ); + void Insert(const SwFrame& rFrame, const SvxBoxItem& rBoxItem, const SwRect &rPaintArea); + void HandleFrame(const SwLayoutFrame& rFrame, const SwRect& rPaintArea); void FindStylesForLine( const Point&, const Point&, svx::frame::Style*, @@ -2324,10 +2324,11 @@ public: SwTabFramePainter::SwTabFramePainter( const SwTabFrame& rTabFrame ) : mrTabFrame( rTabFrame ) { - HandleFrame( rTabFrame ); + SwRect aPaintArea = rTabFrame.GetUpper()->GetPaintArea(); + HandleFrame(rTabFrame, aPaintArea); } -void SwTabFramePainter::HandleFrame( const SwLayoutFrame& rLayoutFrame ) +void SwTabFramePainter::HandleFrame(const SwLayoutFrame& rLayoutFrame, const SwRect& rPaintArea) { // Add border lines of cell frames. Skip covered cells. Skip cells // in special row span row, which do not have a negative row span: @@ -2341,7 +2342,7 @@ void SwTabFramePainter::HandleFrame( const SwLayoutFrame& rLayoutFrame ) SwBorderAttrAccess aAccess( SwFrame::GetCache(), &rLayoutFrame ); const SwBorderAttrs& rAttrs = *aAccess.Get(); const SvxBoxItem& rBox = rAttrs.GetBox(); - Insert( rLayoutFrame, rBox ); + Insert(rLayoutFrame, rBox, rPaintArea); } } @@ -2351,7 +2352,7 @@ void SwTabFramePainter::HandleFrame( const SwLayoutFrame& rLayoutFrame ) { const SwLayoutFrame* pLowerLayFrame = dynamic_cast<const SwLayoutFrame*>(pLower); if ( pLowerLayFrame && !pLowerLayFrame->IsTabFrame() ) - HandleFrame( *pLowerLayFrame ); + HandleFrame(*pLowerLayFrame, rPaintArea); pLower = pLower->GetNext(); } @@ -2725,21 +2726,12 @@ static bool lcl_IsFirstRowInFollowTableWithoutRepeatedHeadlines( && rBoxItem.GetBottom()); } -void SwTabFramePainter::Insert( const SwFrame& rFrame, const SvxBoxItem& rBoxItem ) +void SwTabFramePainter::Insert(const SwFrame& rFrame, const SvxBoxItem& rBoxItem, const SwRect& rPaintArea) { // build 4 line entries for the 4 borders: SwRect aBorderRect = rFrame.getFrameArea(); - // Frame area of a table might be larger than the containing frame - // so we have to intersect the border rect with upper frames til - // the first frame that is not part of a table. - const SwLayoutFrame *pUpper = rFrame.GetUpper(); - while(pUpper) - { - aBorderRect.Intersection(pUpper->getFrameArea()); - if (!pUpper->IsInTab()) - break; - pUpper = pUpper->GetUpper(); - } + + aBorderRect.Intersection(rPaintArea); bool const bBottomAsTop(lcl_IsFirstRowInFollowTableWithoutRepeatedHeadlines( mrTabFrame, rFrame, rBoxItem)); |