summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8/WW8TableInfo.cxx
diff options
context:
space:
mode:
authorAdam Co <rattles2013@gmail.com>2013-10-17 11:48:31 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-05 16:22:49 +0100
commit57c54792781cc9befe3a65a97b37fa85f89da0ae (patch)
tree729e09641bb3ddccb620dd5443d5cfc707d6d897 /sw/source/filter/ww8/WW8TableInfo.cxx
parentf689578dc4f3a77f6a3e72bbf32adf88a2c55526 (diff)
fdo#69644 - fix docx export of wrong number and width of columns
When the DOCX exporter exported a table, it filled the table column definitions with the column sizes of the FIRST row only. This was ok for tables that have the same columns on all rows, but for more complex tables with different cell widths - the filter exported the wrong number of columns and the wrong width. A followup fix would fix the rounding problems there still are with the column widths that are exported in the table definition. Conflicts: sw/qa/extras/ooxmlexport/ooxmlexport.cxx Change-Id: Ie95dfe60b1c1811776433e457ca04e728623e01e Reviewed-on: https://gerrit.libreoffice.org/6290
Diffstat (limited to 'sw/source/filter/ww8/WW8TableInfo.cxx')
-rw-r--r--sw/source/filter/ww8/WW8TableInfo.cxx96
1 files changed, 94 insertions, 2 deletions
diff --git a/sw/source/filter/ww8/WW8TableInfo.cxx b/sw/source/filter/ww8/WW8TableInfo.cxx
index 9a0b188a95e3..aa39f3d6b33c 100644
--- a/sw/source/filter/ww8/WW8TableInfo.cxx
+++ b/sw/source/filter/ww8/WW8TableInfo.cxx
@@ -190,10 +190,43 @@ TableBoxVectorPtr WW8TableNodeInfoInner::getTableBoxesOfRow()
return pResult;
}
-GridColsPtr WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase & rBase)
+GridColsPtr WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase & rBase, bool calculateColumnsFromAllRows)
{
GridColsPtr pResult(new GridCols);
- WidthsPtr pWidths(getWidthsOfRow());
+ WidthsPtr pWidths;
+
+ // Check which columns should be checked - only the current row,
+ // or all the rows together
+ if (calculateColumnsFromAllRows)
+ {
+ // Calculate the width of all the columns based on ALL the rows.
+ // The difference is that this kind of draws vertical lines,
+ // so that if the rows look like this:
+ //
+ // ------------------------
+ // | | |
+ // ------------------------
+ // | | |
+ // ------------------------
+ // | | |
+ // ------------------------
+ //
+ // then the actual column widths will be broken down like this:
+ //
+ // ------------------------
+ // | | | | |
+ // ------------------------
+ //
+ // See the example at
+ // http://officeopenxml.com/WPtableGrid.php
+ // Under "Word 2007 Example"
+ pWidths = getColumnWidthsBasedOnAllRows();
+ }
+ else
+ {
+ // Calculate the width of all the columns based on the current row
+ pWidths = getWidthsOfRow();
+ }
const SwFrmFmt *pFmt = getTable()->GetFrmFmt();
OSL_ENSURE(pFmt,"Impossible");
@@ -226,6 +259,65 @@ GridColsPtr WW8TableNodeInfoInner::getGridColsOfRow(AttributeOutputBase & rBase)
return pResult;
}
+WidthsPtr WW8TableNodeInfoInner::getColumnWidthsBasedOnAllRows()
+{
+ WidthsPtr pWidths;
+
+ WW8TableCellGrid::Pointer_t pCellGrid =
+ mpParent->getParent()->getCellGridForTable(getTable(), false);
+
+ if (pCellGrid.get() == NULL)
+ {
+ const SwTable * pTable = getTable();
+ const SwTableLines& rTableLines = pTable->GetTabLines();
+ sal_uInt16 nNumOfLines = rTableLines.size();
+
+ // Go over all the rows - and for each row - calculate where
+ // there is a separator between columns
+ WidthsPtr pSeparators(new Widths);
+ for ( sal_uInt32 nLineIndex = 0; nLineIndex < nNumOfLines; nLineIndex++)
+ {
+ const SwTableLine *pCurrentLine = rTableLines[nLineIndex];
+ const SwTableBoxes & rTabBoxes = pCurrentLine->GetTabBoxes();
+ sal_uInt32 nBoxes = rTabBoxes.size();
+ if ( nBoxes > MAXTABLECELLS )
+ nBoxes = MAXTABLECELLS;
+
+ sal_uInt32 nSeparatorPosition = 0;
+ for (sal_uInt32 nBoxIndex = 0; nBoxIndex < nBoxes; nBoxIndex++)
+ {
+ const SwFrmFmt* pBoxFmt = rTabBoxes[ nBoxIndex ]->GetFrmFmt();
+ const SwFmtFrmSize& rLSz = pBoxFmt->GetFrmSize();
+ nSeparatorPosition += rLSz.GetWidth();
+ pSeparators->push_back(nSeparatorPosition);
+ }
+ }
+
+ // Sort the separator positions and remove any duplicates
+ std::sort(pSeparators->begin(), pSeparators->end());
+ std::vector<sal_uInt32>::iterator it = std::unique(pSeparators->begin(), pSeparators->end());
+ pSeparators->erase(it, pSeparators->end());
+
+ // Calculate the widths based on the position of the unique & sorted
+ // column separators
+ pWidths = WidthsPtr(new Widths);
+ sal_uInt32 nPreviousWidth = 0;
+ Widths::const_iterator aItEnd2 = pSeparators->end();
+ for (Widths::const_iterator aIt2 = pSeparators->begin(); aIt2 != aItEnd2; ++aIt2)
+ {
+ sal_uInt32 nCurrentWidth = *aIt2;
+ pWidths->push_back(nCurrentWidth - nPreviousWidth);
+ nPreviousWidth = nCurrentWidth;
+ }
+ }
+ else
+ {
+ pWidths = pCellGrid->getWidthsOfRow(this);
+ }
+
+ return pWidths;
+}
+
WidthsPtr WW8TableNodeInfoInner::getWidthsOfRow()
{
WidthsPtr pWidths;