sw/qa/extras/ww8export/ww8export3.cxx |    5 +-
 sw/source/filter/ww8/wrtww8.cxx       |   59 ++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 3 deletions(-)

New commits:
commit 8db856d8afe26cc11b41b3081310c15e90bb55bb
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Wed Apr 22 11:43:22 2020 +0300
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Fri May 8 11:55:08 2020 +0200

    tdf#98409 doc export: export (non-default) cell margins
    
    Previously, the only cell margins that were being
    exported were the row defaults from the last column.
    
    These cell margins are tricky, because multiple
    cells and multiple sides can be combined together
    into a single definition.
    
    A previous commit for tdf#73056 was needed to import
    these sequences.
    
    Change-Id: I513c432ec11a78c7bb52ac6fb628851192e88023
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93231
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index 55cc1c50ba74..721fc95fa8a6 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -168,9 +168,8 @@ DECLARE_WW8EXPORT_TEST(testTdf73056_cellMargins, 
"tdf73056_cellMargins.doc")
 
     // only the first cell with specific margins was processed, leaving the 
rest at table defaults. Was 0.
     uno::Reference< beans::XPropertySet > xPropSet( xCell, 
uno::UNO_QUERY_THROW );
-    if ( !mbExported )
-        CPPUNIT_ASSERT_EQUAL_MESSAGE( "bottom cell spacing to contents",
-            sal_Int32(101), getProperty<sal_Int32>(xPropSet, 
"BottomBorderDistance" ) );
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "bottom cell spacing to contents",
+        sal_Int32(101), getProperty<sal_Int32>(xPropSet, 
"BottomBorderDistance" ) );
 }
 DECLARE_WW8EXPORT_TEST(testTdf79435_legacyInputFields, 
"tdf79435_legacyInputFields.docx")
 {
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 8ab70eb01ddc..096be4c81e4c 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -2575,6 +2575,21 @@ void WW8AttributeOutput::TableCellBorders(
     const SvxBoxItem * pLastBox = nullptr;
     sal_uInt8 nSeqStart = 0; // start of sequence of cells with same borders
 
+    static const SvxBoxItemLine aBorders[] =
+    {
+        SvxBoxItemLine::TOP, SvxBoxItemLine::LEFT,
+        SvxBoxItemLine::BOTTOM, SvxBoxItemLine::RIGHT
+    };
+
+    sal_uInt16 nDefaultMargin[4] = {31681, 31681, 31681, 31681};  // outside 
of documented valid range
+    // last column in each row defines the row default in 
TableRowDefaultBorders()
+    if ( nBoxes && rTabBoxes.size() == nBoxes )
+    {
+        const SvxBoxItem& rBox = rTabBoxes[ nBoxes-1 
]->GetFrameFormat()->GetBox();
+        for ( int i = 0; i < 4; ++i )
+            nDefaultMargin[i] = rBox.GetDistance( aBorders[i] );
+    }
+
     // Detect sequences of cells which have the same borders, and output
     // a border description for each such cell range.
     for ( unsigned n = 0; n <= nBoxes; ++n )
@@ -2585,9 +2600,53 @@ void WW8AttributeOutput::TableCellBorders(
             pLastBox = pBox;
         else if( !pBox || *pLastBox != *pBox )
         {
+            if ( !pLastBox )
+                break;
+
             // This cell has different borders than the previous cell,
             // so output the borders for the preceding cell range.
             m_rWW8Export.Out_CellRangeBorders(pLastBox, nSeqStart, n);
+
+            // The last column is used as the row default for margins, so we 
can ignore these matching ones
+            if ( n == nBoxes )
+                break;
+
+            // Output cell margins.
+            // One CSSA can define up to all four margins if they are the same 
size value.
+            sal_uInt16 nMargin[4];
+            sal_uInt8 nSideBits[4] = {0, 0, 0, 0}; // 0001:top, 0010:left, 
0100:bottom, 1000:right
+            for ( int i = 0; i < 4; ++i )  // sides: top, left, bottom, right
+            {
+                nMargin[i] = std::min(sal_uInt16(31680), 
pLastBox->GetDistance( aBorders[i] ));
+                if ( nMargin[i] == nDefaultMargin[i] )
+                    continue;
+
+                // join a previous side's definition if it shares the same 
value
+                for ( int p = 0; p < 4; ++p )
+                {
+                    if ( nMargin[i] == nMargin[p] )
+                    {
+                        nSideBits[p] |= 1 << i;
+                        break;
+                    }
+                }
+            }
+
+            // write out the cell margins definitions that were used
+            for ( int i = 0; i < 4; ++i )
+            {
+                if ( nSideBits[i] )
+                {
+                    SwWW8Writer::InsUInt16( *m_rWW8Export.pO, 
NS_sprm::sprmTCellPadding );
+                    m_rWW8Export.pO->push_back( sal_uInt8(6) );            // 
6 bytes
+                    m_rWW8Export.pO->push_back( sal_uInt8(nSeqStart) );    // 
first cell: apply margin
+                    m_rWW8Export.pO->push_back( sal_uInt8(n) );            // 
end cell: do not apply margin
+                    m_rWW8Export.pO->push_back( sal_uInt8(nSideBits[i]) );
+                    m_rWW8Export.pO->push_back( sal_uInt8(3) );            // 
FtsDxa: size in twips
+                    SwWW8Writer::InsUInt16( *m_rWW8Export.pO, nMargin[i] );
+                }
+            }
+
             nSeqStart = n;
             pLastBox = pBox;
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to