sw/inc/tblafmt.hxx                             |    8 +++++
 sw/qa/extras/htmlimport/data/reqif-table.xhtml |   34 ++++++-------------------
 sw/qa/extras/htmlimport/htmlimport.cxx         |   11 ++++++++
 sw/source/core/doc/tblafmt.cxx                 |   27 ++++++++++---------
 sw/source/filter/html/htmltab.cxx              |    5 ++-
 5 files changed, 45 insertions(+), 40 deletions(-)

New commits:
commit b620741fed32e9d9d65068857e8fdbd2a325e63b
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue May 13 16:00:38 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed May 14 21:20:05 2025 +0200

    ReqIF: set all necessary borders in merged cells
    
    Commit 63c91b9cb3f73b66a915875721b0efd65b8aebac (sw HTML import: apply
    default table autoformat on cells in reqif mode, 2018-08-08) made ReqIF
    import apply default table autoformat to tables, because ReqIF has no
    cell format info.
    
    Commit 46fcf87725818666fee34226afdac4a64edd94eb (tdf#115576 sw: fix
    borders for single row/col autotable styles, 2019-11-19) introduced
    special handling for inserting tables with single row and/or column,
    because in that case, the applied formatting was for the first (e.g.,
    top-left) cell, which lacked bottom/right borders.
    
    In case of ReqIF tables with merged cells, which span till the right
    table edge, applying autoformat to such a cell has the same problem:
    the cell position is not rightmost, but it needs a right border as in
    the rightmost cell.
    
    This change extends the code from the fix of tdf#115576, to handle not
    only single-row/single-column cases, but also spanned cells, and fixes
    the ReqIF merged cells case.
    
    Change-Id: I50da381d0a74e75e808036bcf335d0857994bf40
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185259
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 9396237e8e0e2524b852c1abaa25c50e32ce7d44)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185295
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index d0a147af7885..c749e9d2f675 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -207,7 +207,13 @@ public:
 
     void UpdateFromSet( sal_uInt8 nPos, const SfxItemSet& rSet,
                                 SwTableAutoFormatUpdateFlags eFlags, 
SvNumberFormatter const * );
-    void UpdateToSet( const sal_uInt8 nPos, const bool bSingleRowTable, const 
bool bSingleColTable,
+    // bCellSpansToEndV means either "single-row table", or "a cell that spans 
several rows till the
+    // bottom of the table", i.e. "include the bottom border properties in the 
set, in addition to
+    // the properties of its starting position (when eFlags include Box)".
+    // bCellSpansToEndH means either "single-column table", or "a cell that 
spans several columns
+    // till the right of the table", i.e. "include the right border properties 
in the set, in
+    // addition to the properties of its starting position (when eFlags 
include Box)".
+    void UpdateToSet( sal_uInt8 nPos, bool bCellSpansToEndV, bool 
bCellSpansToEndH,
                         SfxItemSet& rSet, SwTableAutoFormatUpdateFlags eFlags,
                         SvNumberFormatter* ) const ;
 
diff --git a/sw/qa/extras/htmlimport/data/reqif-table.xhtml 
b/sw/qa/extras/htmlimport/data/reqif-table.xhtml
index a169a079e27a..25f5e29fbced 100644
--- a/sw/qa/extras/htmlimport/data/reqif-table.xhtml
+++ b/sw/qa/extras/htmlimport/data/reqif-table.xhtml
@@ -45,34 +45,18 @@
 
 <reqif-xhtml:p>Table 3.</reqif-xhtml:p>
 
-<reqif-xhtml:table width="100%" cellpadding="4" cellspacing="0">
+<reqif-xhtml:table width="100%" cellpadding="0" cellspacing="0">
+       <reqif-xhtml:col width="85*"/>
+       <reqif-xhtml:col width="85*"/>
+       <reqif-xhtml:col width="85*"/>
        <reqif-xhtml:tr valign="top">
-               <reqif-xhtml:td><reqif-xhtml:p align="left" 
style="text-decoration: none">
-                       <reqif-xhtml:br/>
-
-                       </reqif-xhtml:p>
-               </reqif-xhtml:td>
-       </reqif-xhtml:tr>
-       <reqif-xhtml:tr valign="top">
-               <reqif-xhtml:td><reqif-xhtml:p align="left" 
style="text-decoration: none">
-                       <reqif-xhtml:br/>
-
-                       </reqif-xhtml:p>
-               </reqif-xhtml:td>
+               
<reqif-xhtml:td><reqif-xhtml:p>1</reqif-xhtml:p></reqif-xhtml:td>
+               
<reqif-xhtml:td><reqif-xhtml:p>2</reqif-xhtml:p></reqif-xhtml:td>
+               
<reqif-xhtml:td><reqif-xhtml:p>3</reqif-xhtml:p></reqif-xhtml:td>
        </reqif-xhtml:tr>
        <reqif-xhtml:tr valign="top">
-               <reqif-xhtml:td><reqif-xhtml:p align="left" 
style="text-decoration: none">
-                       <reqif-xhtml:br/>
-
-                       </reqif-xhtml:p>
-               </reqif-xhtml:td>
-       </reqif-xhtml:tr>
-       <reqif-xhtml:tr valign="top">
-               <reqif-xhtml:td><reqif-xhtml:p align="left" 
style="text-decoration: none">
-                       <reqif-xhtml:br/>
-
-                       </reqif-xhtml:p>
-               </reqif-xhtml:td>
+               
<reqif-xhtml:td><reqif-xhtml:p>a</reqif-xhtml:p></reqif-xhtml:td>
+               <reqif-xhtml:td 
colspan="2"><reqif-xhtml:p>b</reqif-xhtml:p></reqif-xhtml:td>
        </reqif-xhtml:tr>
 </reqif-xhtml:table>
 <reqif-xhtml:p>After.</reqif-xhtml:p>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx 
b/sw/qa/extras/htmlimport/htmlimport.cxx
index c118872158cb..6cf8f22647b9 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -357,6 +357,17 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testReqIfTable)
     aBorder = getProperty<table::BorderLine2>(xCell, u"RightBorder"_ustr);
     // This was 0. Single column tables had no right border.  tdf#115576
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Right Border", static_cast<sal_uInt32>(18), 
aBorder.LineWidth);
+
+    // Test a cell merged horizontally to the table end
+    xTable.set(xTables->getByIndex(2), uno::UNO_QUERY_THROW);
+    xCell.set(xTable->getCellByName(u"B2"_ustr), uno::UNO_QUERY_THROW);
+    aBorder = getProperty<table::BorderLine2>(xCell, u"BottomBorder"_ustr);
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(18), aBorder.LineWidth);
+    aBorder = getProperty<table::BorderLine2>(xCell, u"LeftBorder"_ustr);
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(18), aBorder.LineWidth);
+    aBorder = getProperty<table::BorderLine2>(xCell, u"RightBorder"_ustr);
+    // This was 0, merged cell had no right border.
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(18), aBorder.LineWidth);
 }
 
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testImageSize)
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index b73e195a6bbc..656dc730e710 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -565,7 +565,7 @@ void SwTableAutoFormat::UpdateFromSet( sal_uInt8 nPos,
     // we cannot handle the rest, that's specific to StarCalc
 }
 
-void SwTableAutoFormat::UpdateToSet(const sal_uInt8 nPos, const bool 
bSingleRowTable, const bool bSingleColTable, SfxItemSet& rSet,
+void SwTableAutoFormat::UpdateToSet(const sal_uInt8 nPos, const bool 
bCellSpansToEndV, const bool bCellSpansToEndH, SfxItemSet& rSet,
                                  SwTableAutoFormatUpdateFlags eFlags, 
SvNumberFormatter* pNFormatr) const
 {
     const SwBoxAutoFormat& rChg = GetBoxFormat( nPos );
@@ -626,20 +626,21 @@ void SwTableAutoFormat::UpdateToSet(const sal_uInt8 nPos, 
const bool bSingleRowT
     {
         SvxBoxItem aAutoFormatBox = rChg.GetBox();
 
-        // No format box is adequate to specify the borders of single 
column/row tables, so combine first/last.
-        if ( bSingleRowTable || bSingleColTable )
+        // No format box is adequate to specify the borders of single 
column/row tables (or cells
+        // that span to the respective end), so combine first/last.
+        if (bCellSpansToEndV || bCellSpansToEndH)
         {
-            sal_uInt8 nSingleRowOrColumnId = 15; //LAST_ROW_END_COLUMN
-            if ( !bSingleRowTable )
-                nSingleRowOrColumnId = nPos + 3;  //LAST COLUMN (3, 7, 11, 15)
-            else if ( !bSingleColTable )
-                nSingleRowOrColumnId = nPos + 12; //LAST ROW (12, 13, 14, 15)
-
-            assert( nSingleRowOrColumnId < 16 );
-            const SvxBoxItem aLastAutoFormatBox( 
GetBoxFormat(nSingleRowOrColumnId).GetBox() );
-            if ( bSingleRowTable )
+            sal_uInt8 nLastRowOrColumnId = 15; //LAST_ROW_END_COLUMN
+            if (!bCellSpansToEndV)
+                nLastRowOrColumnId = (nPos / 4 * 4) + 3; //LAST COLUMN (3, 7, 
11, 15)
+            else if (!bCellSpansToEndH)
+                nLastRowOrColumnId = (nPos % 4) + 12; //LAST ROW (12, 13, 14, 
15)
+
+            assert(nLastRowOrColumnId < 16);
+            const SvxBoxItem& 
aLastAutoFormatBox(GetBoxFormat(nLastRowOrColumnId).GetBox());
+            if (bCellSpansToEndV)
                 aAutoFormatBox.SetLine( 
aLastAutoFormatBox.GetLine(SvxBoxItemLine::BOTTOM), SvxBoxItemLine::BOTTOM );
-            if ( bSingleColTable )
+            if (bCellSpansToEndH)
                 aAutoFormatBox.SetLine( 
aLastAutoFormatBox.GetLine(SvxBoxItemLine::RIGHT), SvxBoxItemLine::RIGHT );
         }
 
diff --git a/sw/source/filter/html/htmltab.cxx 
b/sw/source/filter/html/htmltab.cxx
index 96664b710f2a..81f2d170e2f3 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -1492,7 +1492,10 @@ void HTMLTable::FixFrameFormat( SwTableBox *pBox,
                 std::unique_ptr<SvxBoxItem> pOldBoxItem;
                 if (const SvxBoxItem* pBoxItem2 = 
rAttrSet.GetItemIfSet(RES_BOX))
                     pOldBoxItem.reset(pBoxItem2->Clone());
-                pTableFormat->UpdateToSet(nPos, m_nRows==1, m_nCols==1,
+
+                bool bSpansToEndV = m_nRows == 1 || (nRowSpan > 1 && nRow + 
nRowSpan == m_nRows);
+                bool bSpansToEndH = m_nCols == 1 || (nColSpan > 1 && nCol + 
nColSpan == m_nCols);
+                pTableFormat->UpdateToSet(nPos, bSpansToEndV, bSpansToEndH,
                                           const_cast<SfxItemSet&>(rAttrSet),
                                           SwTableAutoFormatUpdateFlags::Box,
                                           
pFrameFormat->GetDoc()->GetNumberFormatter());

Reply via email to