summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2020-04-22 11:43:22 +0300
committerMiklos Vajna <vmiklos@collabora.com>2020-05-07 14:06:16 +0200
commit99c4fefdbb6129a58421b9c7f4a005f868a0e701 (patch)
tree0e2df54c625c89a5115a98cb6eeeb027838f2f47 /sw/source
parentac0112ecefd64094b150390fc36f9f56d19a4d87 (diff)
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/+/92701 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/filter/ww8/wrtww8.cxx64
1 files changed, 62 insertions, 2 deletions
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 6982cd7a8fcc..91d049a42e11 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -2043,8 +2043,9 @@ void WW8AttributeOutput::TableInfoRow( ww8::WW8TableNodeInfoInner::Pointer_t pTa
m_rWW8Export.pO->push_back( sal_uInt8(0x1) );
}
- // Most of these are per-row definitions, not per-table,
- // so likely some the per-table functions are unnecessarily re-defined...
+ // Most of these are per-row definitions, not per-table.
+ // WW8 has no explicit table start/end markup,
+ // simply rows with the same table properties that are grouped together as a table.
TableBidi( pTableTextNodeInfoInner );
TableOrientation( pTableTextNodeInfoInner );
TableSpacing( pTableTextNodeInfoInner );
@@ -2566,6 +2567,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 )
@@ -2576,9 +2592,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;
}