tdf#154198 sw: fix lost vertical table cell borders for WordTableCell + RTL
This went wrong in commit 0dbecd2d2ebe18a262cfab96e105637840b5b7fe (sw:
fix too long inner borders intersecting with outer borders for Word
cells, 2022-01-06), the problem is that in its current form this assumes
that the first cell is on the left and the last cell is on the right,
which is not true for RTL, so only tweak the length of the borders in
the LTR case.
(cherry picked from commit 652ab50ce18d0ce7fa1209e6bcf3b10ac5c9a933)
Change-Id: I513af974855496e507134cf156f9ee5a937a46db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157166
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
diff --git a/sw/qa/core/layout/data/rtl-table.docx b/sw/qa/core/layout/data/rtl-table.docx
new file mode 100644
index 0000000..a329229
--- /dev/null
+++ b/sw/qa/core/layout/data/rtl-table.docx
Binary files differ
diff --git a/sw/qa/core/layout/paintfrm.cxx b/sw/qa/core/layout/paintfrm.cxx
index 2416c6b..ad09405 100644
--- a/sw/qa/core/layout/paintfrm.cxx
+++ b/sw/qa/core/layout/paintfrm.cxx
@@ -68,6 +68,47 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitTableBorder)
// missing.
CPPUNIT_ASSERT_EQUAL(4, nHorizontalBorders);
}
CPPUNIT_TEST_FIXTURE(Test, testRTLBorderMerge)
{
// Given a document with an RTL table:
createSwDoc("rtl-table.docx");
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
SwDocShell* pShell = pTextDoc->GetDocShell();
// When rendering that document:
std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
// Then make sure the 5 columns all have left and right vertical borders:
MetafileXmlDump aDumper;
xmlDocUniquePtr pXmlDoc = dumpAndParse(aDumper, *xMetaFile);
xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, "//polyline[@style='solid']/point");
xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
int nVerticalBorders = 0;
// Count the vertical borders:
for (int i = 0; i < xmlXPathNodeSetGetLength(pXmlNodes); i += 2)
{
xmlNodePtr pStart = pXmlNodes->nodeTab[i];
xmlNodePtr pEnd = pXmlNodes->nodeTab[i + 1];
xmlChar* pStartY = xmlGetProp(pStart, BAD_CAST("y"));
xmlChar* pEndY = xmlGetProp(pEnd, BAD_CAST("y"));
sal_Int32 nStartY = o3tl::toInt32(reinterpret_cast<char const*>(pStartY));
sal_Int32 nEndY = o3tl::toInt32(reinterpret_cast<char const*>(pEndY));
if (nStartY == nEndY)
{
// Horizontal border.
continue;
}
++nVerticalBorders;
}
xmlXPathFreeObject(pXmlObj);
// Without the accompanying fix in place, this test would have failed with:
// - Expected: 6
// - Actual : 4
// i.e. the 2nd and 5th vertical border was missing.
CPPUNIT_ASSERT_EQUAL(6, nVerticalBorders);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 8f6347a..bd07aa9 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -3123,11 +3123,13 @@ void SwTabFramePainter::Insert( SwLineEntry& rNew, bool bHori )
const IDocumentSettingAccess& rIDSA = pShell->GetDoc()->getIDocumentSettingAccess();
bWordTableCell = rIDSA.get(DocumentSettingId::TABLE_ROW_KEEP);
}
bool bR2L = mrTabFrame.IsRightToLeft();
while ( aIter != pLineSet->end() && rNew.mnStartPos < rNew.mnEndPos )
{
const SwLineEntry& rOld = *aIter;
if (rOld.mnLimitedEndPos || (bWordTableCell && (rOld.mbOuter != rNew.mbOuter)))
// The bWordTableCell code only works for LTR at the moment, avoid it for RTL.
if (rOld.mnLimitedEndPos || (bWordTableCell && (rOld.mbOuter != rNew.mbOuter) && !bR2L))
{
// Don't merge with this line entry as it ends sooner than mnEndPos.
++aIter;