[Libreoffice-commits] core.git: sw/qa writerfilter/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 16 17:01:41 UTC 2020


 sw/qa/extras/ooxmlexport/data/tdf134609_gridAfter.docx   |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx               |   19 +++++++++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |   25 +++++----------
 writerfilter/source/dmapper/TableManager.cxx             |    8 ++++
 writerfilter/source/dmapper/TableManager.hxx             |    1 
 5 files changed, 37 insertions(+), 16 deletions(-)

New commits:
commit fafc6c0fc3c6d62f982b0deb9bc1d874c51dd6fe
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Fri Jul 10 17:27:51 2020 +0300
Commit:     Justin Luth <justin_luth at sil.org>
CommitDate: Thu Jul 16 19:01:02 2020 +0200

    tdf#134709 writerfilter: consider gridBefore for table borders
    
    When the table itself defines borders, those borders should
    apply to the first cell in each row - even if some grids
    are skipped with gridBefore. (i.e. it won't be a straight line
    on the left side).
    
    Most of the changes here are just simplifications,
    since the original code import was overly complex.
    
    This commit depends on some refactoring done for bug 129452
    in LO 7.1.
    
    A followup commit is needed do the same thing for gridAfter,
    but currently gridAfter is not yet populated,
    so some foundational work needs to be done first.
    
    Change-Id: Ic7dd17fa80422520f3ccf1b121a2abb288b88ccb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98534
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf134609_gridAfter.docx b/sw/qa/extras/ooxmlexport/data/tdf134609_gridAfter.docx
new file mode 100644
index 000000000000..64f8e081864c
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf134609_gridAfter.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 26c36ff9eecf..c987501901f5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -127,6 +127,25 @@ DECLARE_OOXMLEXPORT_TEST(testTdf131561_necessaryBorder, "tdf131561_necessaryBord
     CPPUNIT_ASSERT_MESSAGE("Border between A3 and B3", (aBorderR.LineWidth + aBorderL.LineWidth) > 0);
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf134609_gridAfter, "tdf134609_gridAfter.docx")
+{
+    uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
+    uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
+
+    // Table borders (width 159) apply to edge cells, even in uneven cases caused by gridBefore/gridAfter,
+    table::BorderLine2 aBorder = getProperty<table::BorderLine2>(xTable->getCellByName("A1"), "RightBorder");
+    //CPPUNIT_ASSERT_MESSAGE("Right border before gridAfter cells", aBorder.LineWidth > 0);
+    aBorder = getProperty<table::BorderLine2>(xTable->getCellByName("E2"), "LeftBorder");
+    CPPUNIT_ASSERT_MESSAGE("Left edge border after gridBefore cells", aBorder.LineWidth > 100);
+    aBorder = getProperty<table::BorderLine2>(xTable->getCellByName("E2"), "TopBorder");
+    // but only for left/right borders, not top and bottom.
+    // So somewhat inconsistently, gridBefore/After affects outside edges of columns, but not of rows.
+    // insideH borders are width 53. (no insideV borders defined to emphasize missing edge borders)
+    CPPUNIT_ASSERT_MESSAGE("Top border on 'inside' cell", aBorder.LineWidth > 0);
+    CPPUNIT_ASSERT_MESSAGE("Top border is not an edge border", aBorder.LineWidth < 100);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf134063, "tdf134063.docx")
 {
     CPPUNIT_ASSERT_EQUAL(2, getPages());
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index b56323bd3190..ac8c0f52eb71 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -103,8 +103,9 @@ static void lcl_mergeBorder( PropertyIds nId, const PropertyMapPtr& pOrig, const
 }
 
 static void lcl_computeCellBorders( const PropertyMapPtr& pTableBorders, const PropertyMapPtr& pCellProps,
-        sal_Int32 nCell, sal_Int32 nRow, bool bIsEndCol, bool bIsEndRow, bool bMergedVertically )
+        sal_uInt32 nCell, sal_uInt32 nFirstCell, sal_Int32 nRow, bool bIsEndCol, bool bIsEndRow, bool bMergedVertically )
 {
+    const bool bIsStartCol = nCell == nFirstCell;
     std::optional<PropertyMap::Property> pVerticalVal = pCellProps->getProperty(META_PROP_VERTICAL_BORDER);
     std::optional<PropertyMap::Property> pHorizontalVal = pCellProps->getProperty(META_PROP_HORIZONTAL_BORDER);
 
@@ -135,28 +136,19 @@ static void lcl_computeCellBorders( const PropertyMapPtr& pTableBorders, const P
         pCellProps->Erase( pHorizontalVal->first );
     }
 
-    if ( nCell == 0 )
-    {
+    if ( bIsStartCol )
         lcl_mergeBorder( PROP_LEFT_BORDER, pTableBorders, pCellProps );
-        // <w:insideV> counts if there are multiple cells in this row.
-        if (pVerticalVal && !bIsEndCol)
-            pCellProps->Insert( PROP_RIGHT_BORDER, aVertProp, false );
-    }
 
     if ( bIsEndCol )
-    {
         lcl_mergeBorder( PROP_RIGHT_BORDER, pTableBorders, pCellProps );
-        if ( pVerticalVal )
-            pCellProps->Insert( PROP_LEFT_BORDER, aVertProp, false );
-    }
 
-    if ( nCell > 0 && !bIsEndCol )
+    // <w:insideV> counts if there are multiple cells in this row.
+    if ( pVerticalVal )
     {
-        if ( pVerticalVal )
-        {
+        if ( !bIsEndCol && nCell >= nFirstCell )
             pCellProps->Insert( PROP_RIGHT_BORDER, aVertProp, false );
+        if ( !bIsStartCol )
             pCellProps->Insert( PROP_LEFT_BORDER, aVertProp, false );
-        }
     }
 
     if ( nRow == 0 )
@@ -937,7 +929,8 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl
                     }
                 }
 
-                lcl_computeCellBorders( rInfo.pTableBorders, *aCellIterator, nCell, nRow, bIsEndCol, bIsEndRow, bMergedVertically );
+                const sal_uInt32 nFirstCell = m_rDMapper_Impl.getTableManager().getGridBefore(nRow);
+                lcl_computeCellBorders( rInfo.pTableBorders, *aCellIterator, nCell, nFirstCell, nRow, bIsEndCol, bIsEndRow, bMergedVertically );
 
                 //now set the default left+right border distance TODO: there's an sprm containing the default distance!
                 aCellIterator->get()->Insert( PROP_LEFT_BORDER_DISTANCE,
diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx
index 2649ee1120e2..9f29b2b437bf 100644
--- a/writerfilter/source/dmapper/TableManager.cxx
+++ b/writerfilter/source/dmapper/TableManager.cxx
@@ -49,6 +49,14 @@ void TableManager::openCell(const css::uno::Reference<css::text::XTextRange>& rH
 
 bool TableManager::isIgnore() const { return isRowEnd(); }
 
+sal_uInt32 TableManager::getGridBefore(sal_uInt32 nRow)
+{
+    assert(isInTable());
+    if (nRow >= mTableDataStack.top()->getRowCount())
+        return 0;
+    return mTableDataStack.top()->getRow(nRow)->getGridBefore();
+}
+
 sal_uInt32 TableManager::getCurrentGridBefore()
 {
     return mTableDataStack.top()->getCurrentRow()->getGridBefore();
diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx
index 1cc7caaf958e..375cee7e30aa 100644
--- a/writerfilter/source/dmapper/TableManager.hxx
+++ b/writerfilter/source/dmapper/TableManager.hxx
@@ -500,6 +500,7 @@ public:
      */
     bool isIgnore() const;
 
+    sal_uInt32 getGridBefore(sal_uInt32 nRow);
     sal_uInt32 getCurrentGridBefore();
     void setCurrentGridBefore( sal_uInt32 nSkipGrids );
     std::vector<sal_uInt32> getCurrentGridSpans();


More information about the Libreoffice-commits mailing list