27#include <osl/diagnose.h>
35using ::editeng::SvxBorderLine;
40 sal_Int16 eCellVertOri = text::VertOrientation::TOP;
47 if( text::VertOrientation::CENTER==eBoxVertOri || text::VertOrientation::BOTTOM==eBoxVertOri)
48 eCellVertOri = eBoxVertOri;
56 : m_pBackground(nullptr),
m_nPos(nPosition), mbUseLayoutHeights(bUseLayoutHeights),
57 m_nTopBorder(USHRT_MAX), m_nBottomBorder(USHRT_MAX), m_bTopBorder(true),
63 sal_uInt16 nRow, sal_uInt16 nCol,
64 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
70 nHeight, pBackgroundBrush );
71 m_Cells.push_back(std::unique_ptr<SwWriteTableCell>(pCell));
77 :
m_nPos(nPosition), m_nWidthOpt(0), m_bRelWidthOpt(false),
78 m_bLeftBorder(true), m_bRightBorder(true)
88 return sal::static_int_cast<sal_uInt32>(aFrameSize.
GetSize().
Width());
102 bool bLayoutAvailable =
false;
114 SAL_WARN_IF( !bLayoutAvailable && bOldGetLineHeightCalled,
"sw",
"Layout invalid?" );
119 for(
auto pBox : rBoxes )
121 if( pBox->GetSttNd() )
130 for(
size_t nLine=0; nLine<rLines.
size(); nLine++ )
154 nHeight = pItem->GetHeight();
182 pLine = pBox ? pBox->
GetUpper() :
nullptr;
193 if( !pBorderLine->GetColor().IsRGBEqual(
COL_GRAY ) )
200 const sal_uInt16 nOutWidth = pBorderLine->GetOutWidth();
212 const sal_uInt16 nDist = pBorderLine->GetInWidth() ? pBorderLine->GetDistance()
219 size_t const nRow,
size_t const nCol,
220 sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
221 sal_uInt16& rTopBorder,
222 sal_uInt16 &rBottomBorder )
224 sal_uInt16 nBorderMask = 0;
279 sal_uInt32 nWidth =
m_aCols[nCol+nColSpan-1]->GetPos();
281 nWidth = nWidth -
m_aCols[nCol-1]->GetPos();
333 OSL_ENSURE( nWidth > 0,
"Column Width <= 0. OK?" );
334 return nWidth > 0 ? o3tl::narrowing<sal_uInt16>(nWidth) : 0;
356 sal_uInt16 nRowSpan )
const
374 if( !pRow || nRowSpan > 1 )
375 pRow =
m_aRows[nRow+nRowSpan-1].get();
380 OSL_ENSURE( nRawHeight > 0,
"Row Height <= 0. OK?" );
381 return std::max<tools::Long>(nRawHeight, 0);
385 sal_uInt16 nDepth)
const
387 return !pBox->
GetSttNd() && nDepth > 0;
395 sal_uInt32 nStartCPos,
397 sal_uInt32 nParentLineWidth,
401 bool bSubExpanded =
false;
404#if OSL_DEBUG_LEVEL > 0
405 sal_uInt32 nEndCPos = 0;
415 if( nLine < nLines-1 || nParentLineHeight==0 )
418 nRPos += nLineHeight;
419 if( nParentLineHeight && nStartRPos + nParentLineHeight <= nRPos )
425 OSL_FAIL(
"Corrupt line height I" );
426 nRPos -= nLineHeight;
427 nLineHeight = nStartRPos + nParentLineHeight - nRPos;
428 nLineHeight /= nLines - nLine;
429 nRPos += nLineHeight;
436#if OSL_DEBUG_LEVEL > 0
439 nRPos = nStartRPos + nParentLineHeight;
440#if OSL_DEBUG_LEVEL > 0
443 [&](std::unique_ptr<SwWriteTableRow>
const &
p)
444 { return *p == aSrchRow; }) !=
m_aRows.
end(),
"Parent-Row not found" );
448 aRowCheckPos == aRowRPos,
449 "Height of the rows does not correspond with the parent" );
455 const SwTableBoxes::size_type nBoxes = rBoxes.size();
457 sal_uInt32 nCPos = nStartCPos;
458 for( SwTableBoxes::size_type nBox=0; nBox<nBoxes; ++nBox )
462 sal_uInt32 nOldCPos = nCPos;
464 if( nBox < nBoxes-1 || (nParentLineWidth==0 && nLine==0) )
473 OSL_ENSURE( nLine==0 && nParentLineWidth==0,
474 "Now the parent width will be flattened!" );
475 nParentLineWidth = nCPos-nStartCPos;
480#if OSL_DEBUG_LEVEL > 0
481 sal_uInt32 nCheckPos = nCPos +
GetBoxWidth( pBox );
484 nEndCPos = nCheckPos;
490 "Cell includes rows of different widths" );
493 nCPos = nStartCPos + nParentLineWidth;
495#if OSL_DEBUG_LEVEL > 0
498 "Parent-Cell not found" );
501 "Width of the cells does not correspond with the parent" );
519 sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
521 sal_uInt32 nParentLineWidth,
525 sal_uInt16 nNumOfHeaderRows )
528 bool bSubExpanded =
false;
532 sal_uInt16 nRow = nStartRow;
540 if( nLine < nLines-1 || nParentLineHeight==0 )
543 nRPos += nLineHeight;
544 if( nParentLineHeight && nStartRPos + nParentLineHeight <= nRPos )
547 OSL_FAIL(
"Corrupt line height II" );
548 nRPos -= nLineHeight;
549 nLineHeight = nStartRPos + nParentLineHeight - nRPos;
550 nLineHeight /= nLines - nLine;
551 nRPos += nLineHeight;
555 nRPos = nStartRPos + nParentLineHeight;
558 sal_uInt16 nOldRow = nRow;
561 [&](std::unique_ptr<SwWriteTableRow>
const &
p)
562 { return *p == aSrchRow; });
568 OSL_ENSURE( nOldRow <= nRow,
"Don't look back!" );
578 if( nLine+1==nNumOfHeaderRows && nParentLineHeight==0 )
588 nHeight = pFrameSizeItem->GetHeight();
590 const SvxBrushItem *pBrushItem, *pLineBrush = pParentBrush;
593 pLineBrush = pTmpBrush;
598 bool bOutAtRow = !nParentLineWidth;
599 if( !bOutAtRow && nStartCPos==0 )
607 pBrushItem =
nullptr;
610 pBrushItem = pLineBrush;
615 pBrushItem =
nullptr;
618 const SwTableBoxes::size_type nBoxes = rBoxes.size();
619 sal_uInt32 nCPos = nStartCPos;
620 sal_uInt16 nCol = nStartCol;
622 for( SwTableBoxes::size_type nBox=0; nBox<nBoxes; ++nBox )
627 sal_uInt32 nOldCPos = nCPos;
628 if( nBox < nBoxes-1 || (nParentLineWidth==0 && nLine==0) )
632 nParentLineWidth = nCPos - nStartCPos;
635 nCPos = nStartCPos + nParentLineWidth;
638 sal_uInt16 nOldCol = nCol;
641 OSL_ENSURE( it !=
m_aCols.
end(),
"missing column" );
650 sal_uInt16 nRowSpan = nRow - nOldRow + 1;
653 const sal_Int32 nAttrRowSpan = pBox->
getRowSpan();
654 if ( 1 < nAttrRowSpan )
655 nRowSpan = o3tl::narrowing<sal_uInt16>(nAttrRowSpan);
656 else if ( nAttrRowSpan < 1 )
659 SAL_WARN_IF(nCol < nOldCol,
"sw.filter",
"unexpected " << nCol <<
" < " << nOldCol);
660 sal_uInt16 nColSpan = nCol >= nOldCol ? nCol - nOldCol + 1 : 1;
661 pRow->
AddCell( pBox, nOldRow, nOldCol,
662 nRowSpan, nColSpan, nHeight,
668 sal_uInt16 nTopBorder = USHRT_MAX, nBottomBorder = USHRT_MAX;
670 nRowSpan, nColSpan, nTopBorder, nBottomBorder);
675 if (!(nBorderMask & 4) && nOldCol <
m_aCols.
size())
678 OSL_ENSURE(pCol,
"No TableCol found, panic!");
683 if (!(nBorderMask & 8))
686 OSL_ENSURE(pCol,
"No TableCol found, panic!");
691 if (!(nBorderMask & 1))
693 else if (!pRow->
m_nTopBorder || nTopBorder < pRow->m_nTopBorder)
696 if (!(nBorderMask & 2))
700 nBottomBorder < pEndRow->m_nBottomBorder
710 nRPos-nOldRPos, nCPos-nOldCPos,
712 pLineBrush, nDepth-1,
725 sal_uInt32 nBWidth,
bool bRel, sal_uInt16 nMaxDepth, sal_uInt16 nLSub, sal_uInt16 nRSub, sal_uInt32 nNumOfRowsToRepeat)
726 : m_pTable(pTable), m_nBorderColor(
ColorTransparency, sal_uInt32(-1)), m_nCellSpacing(0), m_nCellPadding(0), m_nBorder(0),
727 m_nInnerBorder(0), m_nBaseWidth(nBWidth), m_nHeadEndRow(USHRT_MAX),
728 m_nLeftSub(nLSub), m_nRightSub(nRSub), m_nTabWidth(nWidth), m_bRelWidths(bRel),
729 m_bUseLayoutHeights(true),
731 m_bGetLineHeightCalled(false),
733 m_bColTags(true), m_bLayoutExport(false),
734 m_bCollectBorderWidth(true)
740 std::unique_ptr<SwWriteTableCol> pCol(
new SwWriteTableCol( nParentWidth ));
751 FillTableRowsCols( 0, 0, 0, 0, 0, nParentWidth, rLines,
nullptr, nMaxDepth - 1,
static_cast< sal_uInt16
>(nNumOfRowsToRepeat) );
759 : m_pTable(pTable), m_nBorderColor(
ColorTransparency, sal_uInt32(-1)), m_nCellSpacing(0), m_nCellPadding(0), m_nBorder(0),
760 m_nInnerBorder(0), m_nBaseWidth(pLayoutInfo->GetWidthOption()), m_nHeadEndRow(0),
761 m_nLeftSub(0), m_nRightSub(0), m_nTabWidth(pLayoutInfo->GetWidthOption()),
762 m_bRelWidths(pLayoutInfo->HasPercentWidthOption()), m_bUseLayoutHeights(false),
764 m_bGetLineHeightCalled(false),
766 m_bColTags(pLayoutInfo->HasColTags()), m_bLayoutExport(true),
767 m_bCollectBorderWidth(pLayoutInfo->HaveBordersChanged())
776 const sal_uInt16 nCols = pLayoutInfo->
GetColCount();
777 const sal_uInt16 nRows = pLayoutInfo->
GetRowCount();
780 for( sal_uInt16 nCol=0; nCol<nCols; ++nCol )
782 std::unique_ptr<SwWriteTableCol> pCol(
796 for( sal_uInt16 nRow=0; nRow<nRows; ++nRow )
798 std::unique_ptr<SwWriteTableRow> pRow(
800 pRow->m_nTopBorder = 0;
801 pRow->m_nBottomBorder = 0;
806 for( sal_uInt16 nRow=0; nRow<nRows; ++nRow )
810 bool bHeightExported =
false;
811 for( sal_uInt16 nCol=0; nCol<nCols; nCol++ )
814 pLayoutInfo->
GetCell( nRow, nCol );
820 if( ( nRow>0 && pLayoutCnts == pLayoutInfo->
GetCell(nRow-1,nCol)
822 ( nCol>0 && pLayoutCnts == pLayoutInfo->
GetCell(nRow,nCol-1)
828 const sal_uInt16 nRowSpan = pLayoutCell->
GetRowSpan();
829 const sal_uInt16 nColSpan = pLayoutCell->
GetColSpan();
832 "Table in Table can not be exported over layout" );
838 pRow->
AddCell( pBox, nRow, nCol, nRowSpan, nColSpan,
839 nHeight, pBrushItem );
843 sal_uInt16 nTopBorder = USHRT_MAX, nBottomBorder = USHRT_MAX;
844 sal_uInt16 nBorderMask =
846 nTopBorder, nBottomBorder );
849 if( !(nBorderMask & 4) )
852 pCol =
m_aCols[nCol+nColSpan-1].get();
853 if( !(nBorderMask & 8) )
856 if( !(nBorderMask & 1) )
860 if( !(nBorderMask & 2) )
865 bHeightExported =
true;
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
constexpr tools::Long Width() const
const editeng::SvxBorderLine * GetTop() const
const editeng::SvxBorderLine * GetRight() const
const editeng::SvxBorderLine * GetLeft() const
sal_Int16 GetDistance(SvxBoxItemLine nLine, bool bAllowNegative=false) const
const editeng::SvxBorderLine * GetBottom() const
const Size & GetSize() const
const SwFormatVertOrient & GetVertOrient(bool=true) const
sal_uInt16 GetColSpan() const
bool IsPercentWidthOption() const
sal_uInt16 GetWidthOption() const
sal_uInt16 GetRowSpan() const
const std::shared_ptr< SwHTMLTableLayoutCnts > & GetContents() const
SwTableBox * GetTableBox() const
sal_uInt16 GetWidthOption() const
bool IsRelWidthOption() const
SwHTMLTableLayoutColumn * GetColumn(sal_uInt16 nCol) const
SwHTMLTableLayoutCell * GetCell(sal_uInt16 nRow, sal_uInt16 nCol) const
sal_uInt16 GetColCount() const
sal_uInt16 GetBorder() const
sal_uInt16 GetRowCount() const
sal_uInt16 GetCellPadding() const
sal_uInt16 GetCellSpacing() const
SwTableBox is one table cell in the document model.
sal_Int32 getRowSpan() const
SwFrameFormat * GetFrameFormat()
SwTableLines & GetTabLines()
const SwStartNode * GetSttNd() const
SwTableLine is one table row in the document model.
SwFrameFormat * GetFrameFormat()
SwTwips GetTableLineHeight(bool &bLayoutAvailable) const
SwTableBoxes & GetTabBoxes()
std::vector< SwTableLine * >::size_type size_type
SwTable is one table in the document model, containing rows (which contain cells).
sal_Int16 GetVertOri() const
const SwTableBox * m_pBox
void SetWidthOpt(sal_uInt16 nWidth, bool bPercent)
SwWriteTableCol(sal_uInt32 nPosition)
bool HasLeftBorder() const
bool HasRightBorder() const
sal_uInt16 m_nBottomBorder
const SvxBrushItem * GetBackground() const
SwWriteTableCell * AddCell(const SwTableBox *pBox, sal_uInt16 nRow, sal_uInt16 nCol, sal_uInt16 nRowSpan, sal_uInt16 nColSpan, tools::Long nHeight, const SvxBrushItem *pBackground)
bool HasBottomBorder() const
SwWriteTableCells m_Cells
all cells of the rows
SwWriteTableRow(const SwWriteTableRow &)
void SetBackground(const SvxBrushItem *pBGround)
bool HasTopBorder() const
void CollectTableRowsCols(tools::Long nStartRPos, sal_uInt32 nStartCPos, tools::Long nParentLineHeight, sal_uInt32 nParentLineWidth, const SwTableLines &rLines, sal_uInt16 nDepth)
sal_uInt32 GetRawWidth(sal_uInt16 nCol, sal_uInt16 nColSpan) const
bool m_bCollectBorderWidth
static const SvxBrushItem * GetLineBrush(const SwTableBox *pBox, SwWriteTableRow *pRow)
tools::Long GetLineHeight(const SwTableLine *pLine)
sal_uInt16 GetRelWidth(sal_uInt16 nCol, sal_uInt16 nColSpan) const
sal_uInt16 GetRightSpace(size_t nCol, sal_uInt16 nColSpan) const
void FillTableRowsCols(tools::Long nStartRPos, sal_uInt16 nStartRow, sal_uInt32 nStartCPos, sal_uInt16 nStartCol, tools::Long nParentLineHeight, sal_uInt32 nParentLineWidth, const SwTableLines &rLines, const SvxBrushItem *pLineBrush, sal_uInt16 nDepth, sal_uInt16 nNumOfHeaderRows)
sal_uInt32 GetBaseWidth() const
sal_uInt16 m_nCellPadding
sal_uInt16 MergeBoxBorders(const SwTableBox *pBox, size_t nRow, size_t nCol, sal_uInt16 nRowSpan, sal_uInt16 nColSpan, sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder)
sal_uInt16 GetLeftSpace(sal_uInt16 nCol) const
tools::Long GetAbsHeight(tools::Long nRawWidth, size_t nRow, sal_uInt16 nRowSpan) const
SwWriteTable(const SwTable *pTable, const SwTableLines &rLines, tools::Long nWidth, sal_uInt32 nBWidth, bool bRel, sal_uInt16 nMaxDepth=USHRT_MAX, sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0)
sal_uInt16 GetPercentWidth(sal_uInt16 nCol, sal_uInt16 nColSpan) const
sal_uInt16 m_nInnerBorder
static sal_uInt32 GetBoxWidth(const SwTableBox *pBox)
sal_uInt16 GetAbsWidth(sal_uInt16 nCol, sal_uInt16 nColSpan) const
void MergeBorders(const editeng::SvxBorderLine *pBorderLine, bool bTable)
virtual bool ShouldExpandSub(const SwTableBox *pBox, bool bExpandedBefore, sal_uInt16 nDepth) const
sal_uInt16 m_nCellSpacing
bool m_bGetLineHeightCalled
sal_uInt16 GetOutWidth() const
const_iterator begin() const
std::vector< Value >::const_iterator const_iterator
const_iterator find(const Value &x) const
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
constexpr ::Color COL_GRAY(0x80, 0x80, 0x80)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatVertOrient > RES_VERT_ORIENT(108)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SvxBoxItem > RES_BOX(112)
#define SAL_WARN_IF(condition, area, stream)
std::vector< SwTableBox * > SwTableBoxes