LibreOffice Module sw (master)  1
wrtswtbl.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
21 
22 #include <tools/color.hxx>
23 #include <o3tl/sorted_vector.hxx>
24 
25 #include <swdllapi.h>
26 
27 #include <memory>
28 #include <vector>
29 #include <climits>
30 
31 class SwTableBox;
32 class SwTableLine;
33 class SwTableLines;
34 class SwHTMLTableLayout;
35 class SvxBrushItem;
36 
37 namespace editeng { class SvxBorderLine; }
38 
39 // Code from the HTML filter for writing of tables
40 
41 #define COLFUZZY 20
42 #define ROWFUZZY 20
43 #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
44 #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
45 
47 {
48  const SwTableBox *pBox; // SwTableBox of the cell
49  const SvxBrushItem *pBackground; // inherited background of a row
50 
51  long const nHeight; // fix/minimum height of a row
52 
53  sal_uInt32 nWidthOpt; // width from option;
54 
55  sal_uInt16 const nRow; // start row
56  sal_uInt16 const nCol; // start column
57 
58  sal_uInt16 const nRowSpan; // spanned rows
59  sal_uInt16 const nColSpan; // spanned columns
60 
62 
63 public:
64 
65  SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan,
66  sal_uInt16 nCSpan, long nHght, const SvxBrushItem *pBGround)
67  : pBox( pB ), pBackground( pBGround ), nHeight( nHght ), nWidthOpt( 0 ),
68  nRow( nR ), nCol( nC ), nRowSpan( nRSpan ), nColSpan( nCSpan ),
69  bPrcWidthOpt( false )
70  {}
71 
72  const SwTableBox *GetBox() const { return pBox; }
73 
74  sal_uInt16 GetRow() const { return nRow; }
75  sal_uInt16 GetCol() const { return nCol; }
76 
77  sal_uInt16 GetRowSpan() const { return nRowSpan; }
78  sal_uInt16 GetColSpan() const { return nColSpan; }
79 
80  long GetHeight() const { return nHeight; }
81  sal_Int16 GetVertOri() const;
82 
83  const SvxBrushItem *GetBackground() const { return pBackground; }
84 
85  void SetWidthOpt( sal_uInt16 nWidth, bool bPrc )
86  {
87  nWidthOpt = nWidth; bPrcWidthOpt = bPrc;
88  }
89 
90  sal_uInt32 GetWidthOpt() const { return nWidthOpt; }
91  bool HasPrcWidthOpt() const { return bPrcWidthOpt; }
92 };
93 
94 typedef std::vector<std::unique_ptr<SwWriteTableCell>> SwWriteTableCells;
95 
96 class SwWriteTableRow final
97 {
99  const SvxBrushItem *pBackground; // background
100 
101  long const nPos; // end position (twips) of the row
102  bool const mbUseLayoutHeights;
103 
104  SwWriteTableRow & operator= (const SwWriteTableRow &) = delete;
105 
106  // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
107  SwWriteTableRow( const SwWriteTableRow & );
108 
109 public:
110 
111  sal_uInt16 nTopBorder; // thickness of upper/lower border
112  sal_uInt16 nBottomBorder;
113 
114  bool bTopBorder : 1; // which borders are there?
115  bool bBottomBorder : 1;
116 
117  SwWriteTableRow( long nPos, bool bUseLayoutHeights );
118 
119  SwWriteTableCell *AddCell( const SwTableBox *pBox,
120  sal_uInt16 nRow, sal_uInt16 nCol,
121  sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
122  long nHeight,
123  const SvxBrushItem *pBackground );
124 
125  void SetBackground( const SvxBrushItem *pBGround )
126  {
127  pBackground = pBGround;
128  }
129  const SvxBrushItem *GetBackground() const { return pBackground; }
130 
131  bool HasTopBorder() const { return bTopBorder; }
132  bool HasBottomBorder() const { return bBottomBorder; }
133 
134  const SwWriteTableCells& GetCells() const { return m_Cells; }
135 
136  inline bool operator==( const SwWriteTableRow& rRow ) const;
137  inline bool operator<( const SwWriteTableRow& rRow2 ) const;
138 };
139 
140 inline bool SwWriteTableRow::operator==( const SwWriteTableRow& rRow ) const
141 {
142  // allow for some fuzzyness
143  return (nPos >= rRow.nPos ? nPos - rRow.nPos : rRow.nPos - nPos ) <=
145 }
146 
147 inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
148 {
149  // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
150  // not let x==y and x<y at the same time ;-)
151  return nPos < rRow.nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
152 }
153 
154 using SwWriteTableRows
156 
158 {
159  sal_uInt32 const nPos; // end position of the column
160 
161  sal_uInt32 nWidthOpt;
162 
163  bool bRelWidthOpt : 1;
164 
165 public:
166  bool bLeftBorder : 1; // which borders are there?
167  bool bRightBorder : 1;
168 
169  SwWriteTableCol( sal_uInt32 nPosition );
170 
171  sal_uInt32 GetPos() const { return nPos; }
172 
173  bool HasLeftBorder() const { return bLeftBorder; }
174 
175  bool HasRightBorder() const { return bRightBorder; }
176 
177  inline bool operator==( const SwWriteTableCol& rCol ) const;
178  inline bool operator<( const SwWriteTableCol& rCol ) const;
179 
180  void SetWidthOpt( sal_uInt32 nWidth, bool bRel )
181  {
182  nWidthOpt = nWidth; bRelWidthOpt = bRel;
183  }
184  sal_uInt32 GetWidthOpt() const { return nWidthOpt; }
185  bool HasRelWidthOpt() const { return bRelWidthOpt; }
186 };
187 
188 inline bool SwWriteTableCol::operator==( const SwWriteTableCol& rCol ) const
189 {
190  // allow for some fuzzyness
191  return (nPos >= rCol.nPos ? nPos - rCol.nPos
192  : rCol.nPos - nPos ) <= COLFUZZY;
193 }
194 
195 inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
196 {
197  // Since we only know the degrees of truth of 0 and 1 here, we also prefer to
198  // not let x==y and x<y at the same time ;-)
199  return nPos + COLFUZZY < rCol.nPos;
200 }
201 
203  bool operator()(std::unique_ptr<SwWriteTableCol> const & lhs, std::unique_ptr<SwWriteTableCol> const & rhs) {
204  return lhs->GetPos() < rhs->GetPos();
205  }
206 };
207 
208 class SwWriteTableCols : public o3tl::sorted_vector<std::unique_ptr<SwWriteTableCol>, SwWriteTableColLess> {
209 };
210 
211 class SwTable;
212 
214 {
215 private:
217 protected:
218  SwWriteTableCols m_aCols; // all columns
220 
221  Color m_nBorderColor; // border color
222 
223  sal_uInt16 m_nCellSpacing; // thickness of the inner border
224  sal_uInt16 m_nCellPadding; // distance of border to content
225 
226  sal_uInt16 m_nBorder; // thickness of the outer border
227  sal_uInt16 m_nInnerBorder; // thickness of the inner border
228  sal_uInt32 const m_nBaseWidth; // reference value for SwFormatFrameSize width
229 
230  sal_uInt16 m_nHeadEndRow; // last row of the table heading
231 
232  sal_uInt16 const m_nLeftSub;
233  sal_uInt16 const m_nRightSub;
234 
235  sal_uInt32 m_nTabWidth; // absolute/relative width of the table
236 
237  bool const m_bRelWidths : 1; // generate relative widths?
238  bool m_bUseLayoutHeights : 1; // use layout to determine the height?
239 #ifdef DBG_UTIL
240  bool m_bGetLineHeightCalled : 1;
241 #endif
242 
243  bool const m_bColTags : 1;
244  bool const m_bLayoutExport : 1;
245  bool const m_bCollectBorderWidth : 1;
246 
247  virtual bool ShouldExpandSub( const SwTableBox *pBox,
248  bool bExpandedBefore, sal_uInt16 nDepth ) const;
249 
250  void CollectTableRowsCols( long nStartRPos, sal_uInt32 nStartCPos,
251  long nParentLineHeight,
252  sal_uInt32 nParentLineWidth,
253  const SwTableLines& rLines,
254  sal_uInt16 nDepth );
255 
256  void FillTableRowsCols( long nStartRPos, sal_uInt16 nStartRow,
257  sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
258  long nParentLineHeight,
259  sal_uInt32 nParentLineWidth,
260  const SwTableLines& rLines,
261  const SvxBrushItem* pLineBrush,
262  sal_uInt16 nDepth,
263  sal_uInt16 nNumOfHeaderRows );
264 
265  void MergeBorders( const editeng::SvxBorderLine* pBorderLine, bool bTable );
266 
267  sal_uInt16 MergeBoxBorders(const SwTableBox *pBox, size_t nRow, size_t nCol,
268  sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
269  sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder );
270 
271  sal_uInt32 GetBaseWidth() const { return m_nBaseWidth; }
272 
273  bool HasRelWidths() const { return m_bRelWidths; }
274 
275 public:
276  static sal_uInt32 GetBoxWidth( const SwTableBox *pBox );
277 
278  sal_uInt32 GetRawWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
279  sal_uInt16 GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
280  sal_uInt16 GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
281  sal_uInt16 GetPrcWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
282 
283  long GetAbsHeight(long nRawWidth, size_t nRow, sal_uInt16 nRowSpan) const;
284 
285  double GetAbsWidthRatio() const { return m_nTabWidth == m_nBaseWidth ? 1.0 : double(m_nTabWidth) / m_nBaseWidth; }
286 protected:
287  long GetLineHeight( const SwTableLine *pLine );
288  static long GetLineHeight( const SwTableBox *pBox );
289  static const SvxBrushItem *GetLineBrush( const SwTableBox *pBox,
290  SwWriteTableRow *pRow );
291 
292  sal_uInt16 GetLeftSpace( sal_uInt16 nCol ) const;
293  sal_uInt16 GetRightSpace(size_t nCol, sal_uInt16 nColSpan) const;
294 
295 public:
296  SwWriteTable(const SwTable* pTable, const SwTableLines& rLines, long nWidth, sal_uInt32 nBWidth,
297  bool bRel, sal_uInt16 nMaxDepth = USHRT_MAX,
298  sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0);
299  SwWriteTable(const SwTable* pTable, const SwHTMLTableLayout *pLayoutInfo);
300  virtual ~SwWriteTable();
301 
302  const SwWriteTableRows& GetRows() const { return m_aRows; }
303 
304  const SwTable* GetTable() const { return m_pTable; }
305 };
306 
307 #endif
308 
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasRelWidthOpt() const
Definition: wrtswtbl.hxx:185
long const nPos
Definition: wrtswtbl.hxx:101
const SvxBrushItem * pBackground
Definition: wrtswtbl.hxx:49
bool HasRightBorder() const
Definition: wrtswtbl.hxx:175
long GetHeight() const
Definition: wrtswtbl.hxx:80
sal_uInt16 GetRowSpan() const
Definition: wrtswtbl.hxx:77
SwWriteTableCell * AddCell(const SwTableBox *pBox, sal_uInt16 nRow, sal_uInt16 nCol, sal_uInt16 nRowSpan, sal_uInt16 nColSpan, long nHeight, const SvxBrushItem *pBackground)
Definition: wrtswtbl.cxx:65
sal_uInt32 const nPos
Definition: wrtswtbl.hxx:159
bool HasPrcWidthOpt() const
Definition: wrtswtbl.hxx:91
sal_uInt32 m_nTabWidth
Definition: wrtswtbl.hxx:235
sal_uInt16 m_nInnerBorder
Definition: wrtswtbl.hxx:227
const SwTable * GetTable() const
Definition: wrtswtbl.hxx:304
sal_uInt16 const m_nLeftSub
Definition: wrtswtbl.hxx:232
sal_uInt16 const nColSpan
Definition: wrtswtbl.hxx:59
long const nHeight
Definition: wrtswtbl.hxx:51
SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan, sal_uInt16 nCSpan, long nHght, const SvxBrushItem *pBGround)
Definition: wrtswtbl.hxx:65
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
sal_uInt32 GetWidthOpt() const
Definition: wrtswtbl.hxx:184
const SvxBrushItem * pBackground
Definition: wrtswtbl.hxx:99
const SwTableBox * GetBox() const
Definition: wrtswtbl.hxx:72
sal_uInt16 const m_nRightSub
Definition: wrtswtbl.hxx:233
sal_uInt32 GetBaseWidth() const
Definition: wrtswtbl.hxx:271
sal_uInt16 const nCol
Definition: wrtswtbl.hxx:56
bool HasTopBorder() const
Definition: wrtswtbl.hxx:131
const SvxBrushItem * GetBackground() const
Definition: wrtswtbl.hxx:129
const SwWriteTableCells & GetCells() const
Definition: wrtswtbl.hxx:134
sal_uInt16 const nRow
Definition: wrtswtbl.hxx:55
sal_uInt32 GetWidthOpt() const
Definition: wrtswtbl.hxx:90
sal_uInt32 const m_nBaseWidth
Definition: wrtswtbl.hxx:228
void SetWidthOpt(sal_uInt32 nWidth, bool bRel)
Definition: wrtswtbl.hxx:180
bool HasLeftBorder() const
Definition: wrtswtbl.hxx:173
sal_uInt16 m_nCellSpacing
Definition: wrtswtbl.hxx:223
#define COLFUZZY
Definition: wrtswtbl.hxx:41
SwWriteTableCells m_Cells
all cells of the rows
Definition: wrtswtbl.hxx:98
const SwTable * m_pTable
Definition: wrtswtbl.hxx:216
bool const mbUseLayoutHeights
Definition: wrtswtbl.hxx:102
bool operator==(const SwWriteTableCol &rCol) const
Definition: wrtswtbl.hxx:188
bool operator<(const SwWriteTableRow &rRow2) const
Definition: wrtswtbl.hxx:147
sal_uInt16 m_nCellPadding
Definition: wrtswtbl.hxx:224
SwWriteTableRow & operator=(const SwWriteTableRow &)=delete
bool HasRelWidths() const
Definition: wrtswtbl.hxx:273
sal_uInt32 nWidthOpt
Definition: wrtswtbl.hxx:161
bool operator()(std::unique_ptr< SwWriteTableCol > const &lhs, std::unique_ptr< SwWriteTableCol > const &rhs)
Definition: wrtswtbl.hxx:203
const SvxBrushItem * GetBackground() const
Definition: wrtswtbl.hxx:83
sal_uInt16 GetCol() const
Definition: wrtswtbl.hxx:75
bool operator<(const SwWriteTableCol &rCol) const
Definition: wrtswtbl.hxx:195
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
bool operator==(const SwWriteTableRow &rRow) const
Definition: wrtswtbl.hxx:140
sal_uInt16 GetRow() const
Definition: wrtswtbl.hxx:74
void SetBackground(const SvxBrushItem *pBGround)
Definition: wrtswtbl.hxx:125
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
std::vector< std::unique_ptr< SwWriteTableCell > > SwWriteTableCells
Definition: wrtswtbl.hxx:94
#define ROWFUZZY
Definition: wrtswtbl.hxx:42
SwWriteTableCols m_aCols
Definition: wrtswtbl.hxx:218
const SwTableBox * pBox
Definition: wrtswtbl.hxx:48
SwWriteTableRow(const SwWriteTableRow &)
sal_uInt32 nWidthOpt
Definition: wrtswtbl.hxx:53
SwWriteTableRows m_aRows
Definition: wrtswtbl.hxx:219
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
Color m_nBorderColor
Definition: wrtswtbl.hxx:221
SwWriteTableCol(sal_uInt32 nPosition)
Definition: wrtswtbl.cxx:79
sal_uInt16 GetColSpan() const
Definition: wrtswtbl.hxx:78
bool HasBottomBorder() const
Definition: wrtswtbl.hxx:132
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
const SwWriteTableRows & GetRows() const
Definition: wrtswtbl.hxx:302
void SetWidthOpt(sal_uInt16 nWidth, bool bPrc)
Definition: wrtswtbl.hxx:85
sal_uInt16 nTopBorder
Definition: wrtswtbl.hxx:111
sal_uInt16 nBottomBorder
Definition: wrtswtbl.hxx:112
sal_uInt16 const nRowSpan
Definition: wrtswtbl.hxx:58
sal_uInt16 m_nBorder
Definition: wrtswtbl.hxx:226
sal_uInt16 m_nHeadEndRow
Definition: wrtswtbl.hxx:230
sal_uInt32 GetPos() const
Definition: wrtswtbl.hxx:171
double GetAbsWidthRatio() const
Definition: wrtswtbl.hxx:285