1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
22 #include <tools/color.hxx>
23 #include <tools/long.hxx>
24 #include <o3tl/sorted_vector.hxx>
35 class SwHTMLTableLayout
;
38 namespace editeng
{ class SvxBorderLine
; }
40 // Code from the HTML filter for writing of tables
44 #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
45 #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
47 class SW_DLLPUBLIC SwWriteTableCell
49 const SwTableBox
*m_pBox
; // SwTableBox of the cell
50 const SvxBrushItem
*m_pBackground
; // inherited background of a row
52 tools::Long m_nHeight
; // fix/minimum height of a row
54 sal_uInt32 m_nWidthOpt
; // width from option;
56 sal_uInt16 m_nRow
; // start row
57 sal_uInt16 m_nCol
; // start column
59 sal_uInt16 m_nRowSpan
; // spanned rows
60 sal_uInt16 m_nColSpan
; // spanned columns
62 bool m_bPercentWidthOpt
;
66 SwWriteTableCell(const SwTableBox
*pB
, sal_uInt16 nR
, sal_uInt16 nC
, sal_uInt16 nRSpan
,
67 sal_uInt16 nCSpan
, tools::Long nHght
, const SvxBrushItem
*pBGround
)
68 : m_pBox( pB
), m_pBackground( pBGround
), m_nHeight( nHght
), m_nWidthOpt( 0 ),
69 m_nRow( nR
), m_nCol( nC
), m_nRowSpan( nRSpan
), m_nColSpan( nCSpan
),
70 m_bPercentWidthOpt( false )
73 const SwTableBox
*GetBox() const { return m_pBox
; }
75 sal_uInt16
GetRow() const { return m_nRow
; }
76 sal_uInt16
GetCol() const { return m_nCol
; }
78 sal_uInt16
GetRowSpan() const { return m_nRowSpan
; }
79 sal_uInt16
GetColSpan() const { return m_nColSpan
; }
81 tools::Long
GetHeight() const { return m_nHeight
; }
82 sal_Int16
GetVertOri() const;
84 const SvxBrushItem
*GetBackground() const { return m_pBackground
; }
86 void SetWidthOpt( sal_uInt16 nWidth
, bool bPercent
)
88 m_nWidthOpt
= nWidth
; m_bPercentWidthOpt
= bPercent
;
91 sal_uInt32
GetWidthOpt() const { return m_nWidthOpt
; }
92 bool HasPercentWidthOpt() const { return m_bPercentWidthOpt
; }
95 typedef std::vector
<std::unique_ptr
<SwWriteTableCell
>> SwWriteTableCells
;
97 class SwWriteTableRow final
99 SwWriteTableCells m_Cells
; ///< all cells of the rows
100 const SvxBrushItem
*m_pBackground
; // background
102 tools::Long m_nPos
; // end position (twips) of the row
103 bool mbUseLayoutHeights
;
105 SwWriteTableRow
& operator= (const SwWriteTableRow
&) = delete;
107 // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
108 SwWriteTableRow( const SwWriteTableRow
& );
112 sal_uInt16 m_nTopBorder
; // thickness of upper/lower border
113 sal_uInt16 m_nBottomBorder
;
115 bool m_bTopBorder
: 1; // which borders are there?
116 bool m_bBottomBorder
: 1;
118 SwWriteTableRow( tools::Long nPos
, bool bUseLayoutHeights
);
120 SwWriteTableCell
*AddCell( const SwTableBox
*pBox
,
121 sal_uInt16 nRow
, sal_uInt16 nCol
,
122 sal_uInt16 nRowSpan
, sal_uInt16 nColSpan
,
124 const SvxBrushItem
*pBackground
);
126 void SetBackground( const SvxBrushItem
*pBGround
)
128 m_pBackground
= pBGround
;
130 const SvxBrushItem
*GetBackground() const { return m_pBackground
; }
132 bool HasTopBorder() const { return m_bTopBorder
; }
133 bool HasBottomBorder() const { return m_bBottomBorder
; }
135 const SwWriteTableCells
& GetCells() const { return m_Cells
; }
137 inline bool operator==( const SwWriteTableRow
& rRow
) const;
138 inline bool operator<( const SwWriteTableRow
& rRow2
) const;
141 inline bool SwWriteTableRow::operator==( const SwWriteTableRow
& rRow
) const
143 // allow for some fuzzyness
144 return (m_nPos
>= rRow
.m_nPos
? m_nPos
- rRow
.m_nPos
: rRow
.m_nPos
- m_nPos
) <=
145 (mbUseLayoutHeights
? 0 : ROWFUZZY
);
148 inline bool SwWriteTableRow::operator<( const SwWriteTableRow
& rRow
) const
150 // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
151 // not let x==y and x<y at the same time ;-)
152 return m_nPos
< rRow
.m_nPos
- (mbUseLayoutHeights
? 0 : ROWFUZZY
);
155 using SwWriteTableRows
156 = o3tl::sorted_vector
< std::unique_ptr
<SwWriteTableRow
>, o3tl::less_uniqueptr_to
<SwWriteTableRow
> >;
158 class SwWriteTableCol
160 sal_uInt32 m_nPos
; // end position of the column
162 sal_uInt32 m_nWidthOpt
;
164 bool m_bRelWidthOpt
: 1;
167 bool m_bLeftBorder
: 1; // which borders are there?
168 bool m_bRightBorder
: 1;
170 SwWriteTableCol( sal_uInt32 nPosition
);
172 sal_uInt32
GetPos() const { return m_nPos
; }
174 bool HasLeftBorder() const { return m_bLeftBorder
; }
176 bool HasRightBorder() const { return m_bRightBorder
; }
178 inline bool operator==( const SwWriteTableCol
& rCol
) const;
179 inline bool operator<( const SwWriteTableCol
& rCol
) const;
181 void SetWidthOpt( sal_uInt32 nWidth
, bool bRel
)
183 m_nWidthOpt
= nWidth
; m_bRelWidthOpt
= bRel
;
185 sal_uInt32
GetWidthOpt() const { return m_nWidthOpt
; }
186 bool HasRelWidthOpt() const { return m_bRelWidthOpt
; }
189 inline bool SwWriteTableCol::operator==( const SwWriteTableCol
& rCol
) const
191 // allow for some fuzzyness
192 return (m_nPos
>= rCol
.m_nPos
? m_nPos
- rCol
.m_nPos
193 : rCol
.m_nPos
- m_nPos
) <= COLFUZZY
;
196 inline bool SwWriteTableCol::operator<( const SwWriteTableCol
& rCol
) const
198 // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
199 // not let x==y and x<y at the same time ;-)
200 return m_nPos
+ COLFUZZY
< rCol
.m_nPos
;
203 struct SwWriteTableColLess
{
204 bool operator()(std::unique_ptr
<SwWriteTableCol
> const & lhs
, std::unique_ptr
<SwWriteTableCol
> const & rhs
) {
205 return lhs
->GetPos() < rhs
->GetPos();
209 class SwWriteTableCols
: public o3tl::sorted_vector
<std::unique_ptr
<SwWriteTableCol
>, SwWriteTableColLess
> {
214 class SW_DLLPUBLIC SwWriteTable
217 const SwTable
* m_pTable
;
219 SwWriteTableCols m_aCols
; // all columns
220 SwWriteTableRows m_aRows
; // all rows
222 Color m_nBorderColor
; // border color
224 sal_uInt16 m_nCellSpacing
; // thickness of the inner border
225 sal_uInt16 m_nCellPadding
; // distance of border to content
227 sal_uInt16 m_nBorder
; // thickness of the outer border
228 sal_uInt16 m_nInnerBorder
; // thickness of the inner border
229 sal_uInt32 m_nBaseWidth
; // reference value for SwFormatFrameSize width
231 sal_uInt16 m_nHeadEndRow
; // last row of the table heading
233 sal_uInt16 m_nLeftSub
;
234 sal_uInt16 m_nRightSub
;
236 sal_uInt32 m_nTabWidth
; // absolute/relative width of the table
238 bool m_bRelWidths
: 1; // generate relative widths?
239 bool m_bUseLayoutHeights
: 1; // use layout to determine the height?
241 bool m_bGetLineHeightCalled
: 1;
245 bool m_bLayoutExport
: 1;
246 bool m_bCollectBorderWidth
: 1;
248 virtual bool ShouldExpandSub( const SwTableBox
*pBox
,
249 bool bExpandedBefore
, sal_uInt16 nDepth
) const;
251 void CollectTableRowsCols( tools::Long nStartRPos
, sal_uInt32 nStartCPos
,
252 tools::Long nParentLineHeight
,
253 sal_uInt32 nParentLineWidth
,
254 const SwTableLines
& rLines
,
257 void FillTableRowsCols( tools::Long nStartRPos
, sal_uInt16 nStartRow
,
258 sal_uInt32 nStartCPos
, sal_uInt16 nStartCol
,
259 tools::Long nParentLineHeight
,
260 sal_uInt32 nParentLineWidth
,
261 const SwTableLines
& rLines
,
262 const SvxBrushItem
* pLineBrush
,
264 sal_uInt16 nNumOfHeaderRows
);
266 void MergeBorders( const editeng::SvxBorderLine
* pBorderLine
, bool bTable
);
268 sal_uInt16
MergeBoxBorders(const SwTableBox
*pBox
, size_t nRow
, size_t nCol
,
269 sal_uInt16 nRowSpan
, sal_uInt16 nColSpan
,
270 sal_uInt16
&rTopBorder
, sal_uInt16
&rBottomBorder
);
272 sal_uInt32
GetBaseWidth() const { return m_nBaseWidth
; }
274 bool HasRelWidths() const { return m_bRelWidths
; }
277 static sal_uInt32
GetBoxWidth( const SwTableBox
*pBox
);
279 sal_uInt32
GetRawWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
280 sal_uInt16
GetAbsWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
281 sal_uInt16
GetRelWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
282 sal_uInt16
GetPercentWidth( sal_uInt16 nCol
, sal_uInt16 nColSpan
) const;
284 tools::Long
GetAbsHeight(tools::Long nRawWidth
, size_t nRow
, sal_uInt16 nRowSpan
) const;
286 double GetAbsWidthRatio() const { return m_nTabWidth
== m_nBaseWidth
? 1.0 : double(m_nTabWidth
) / m_nBaseWidth
; }
288 tools::Long
GetLineHeight( const SwTableLine
*pLine
);
289 static tools::Long
GetLineHeight( const SwTableBox
*pBox
);
290 static const SvxBrushItem
*GetLineBrush( const SwTableBox
*pBox
,
291 SwWriteTableRow
*pRow
);
293 sal_uInt16
GetLeftSpace( sal_uInt16 nCol
) const;
294 sal_uInt16
GetRightSpace(size_t nCol
, sal_uInt16 nColSpan
) const;
297 SwWriteTable(const SwTable
* pTable
, const SwTableLines
& rLines
, tools::Long nWidth
, sal_uInt32 nBWidth
,
298 bool bRel
, sal_uInt16 nMaxDepth
= USHRT_MAX
,
299 sal_uInt16 nLeftSub
=0, sal_uInt16 nRightSub
=0, sal_uInt32 nNumOfRowsToRepeat
=0);
300 SwWriteTable(const SwTable
* pTable
, const SwHTMLTableLayout
*pLayoutInfo
);
301 virtual ~SwWriteTable();
303 const SwWriteTableRows
& GetRows() const { return m_aRows
; }
305 const SwTable
* GetTable() const { return m_pTable
; }
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */