sw/qa/extras/ww8export/ww8export3.cxx | 5 +- sw/source/filter/ww8/wrtww8.cxx | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-)
New commits: commit c3bbfc91b48654120e70ad769c5bb27f9cfa110e Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Wed Apr 22 11:43:22 2020 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Mon May 18 20:58:43 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 - instead of only the first instance. Change-Id: I513c432ec11a78c7bb52ac6fb628851192e88023 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93638 Tested-by: Andras Timar <andras.ti...@collabora.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 acc68352102d..c8bbe96a1b9d 100644 --- a/sw/qa/extras/ww8export/ww8export3.cxx +++ b/sw/qa/extras/ww8export/ww8export3.cxx @@ -171,9 +171,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 e908cab35162..555f01de8f7d 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -2571,6 +2571,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 ) @@ -2581,9 +2596,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