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 .
20 #ifndef INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
27 #include <unordered_map>
29 #include <sal/types.h>
36 class AttributeOutputBase
;
40 const unsigned int MAXTABLECELLS
= 63;
42 class WW8TableNodeInfo
;
43 typedef std::vector
<const SwTableBox
*> TableBoxVector
;
44 typedef std::shared_ptr
<TableBoxVector
> TableBoxVectorPtr
;
45 typedef std::vector
<sal_uInt32
> GridCols
;
46 typedef std::shared_ptr
<GridCols
> GridColsPtr
;
47 typedef std::vector
<sal_Int32
> RowSpans
;
48 typedef std::shared_ptr
<RowSpans
> RowSpansPtr
;
49 typedef std::vector
<sal_uInt32
> Widths
;
50 typedef std::shared_ptr
<Widths
> WidthsPtr
;
52 class WW8TableNodeInfoInner
54 WW8TableNodeInfo
* mpParent
;
58 sal_uInt32 mnShadowsBefore
;
59 sal_uInt32 mnShadowsAfter
;
61 bool mbFinalEndOfLine
;
65 const SwTableBox
* mpTableBox
;
66 const SwTable
* mpTable
;
70 typedef std::shared_ptr
<WW8TableNodeInfoInner
> Pointer_t
;
72 explicit WW8TableNodeInfoInner(WW8TableNodeInfo
* pParent
);
74 void setDepth(sal_uInt32 nDepth
);
75 void setCell(sal_uInt32 nCell
);
76 void setRow(sal_uInt32 nRow
);
77 void setShadowsBefore(sal_uInt32 nShadowsBefore
);
78 void setShadowsAfter(sal_uInt32 nShadowsAfter
);
79 void setEndOfLine(bool bEndOfLine
);
80 void setFinalEndOfLine(bool bEndOfLine
);
81 void setEndOfCell(bool bEndOfCell
);
82 void setFirstInTable(bool bFirstInTable
);
83 void setVertMerge(bool bVertMerge
);
84 void setTableBox(const SwTableBox
*pTableBox
);
85 void setTable(const SwTable
* pTable
);
86 void setRect(const SwRect
& rRect
);
88 sal_uInt32
getDepth() const { return mnDepth
;}
89 sal_uInt32
getCell() const { return mnCell
;}
90 sal_uInt32
getRow() const { return mnRow
;}
91 sal_uInt32
getShadowsBefore() const { return mnShadowsBefore
;}
92 sal_uInt32
getShadowsAfter() const { return mnShadowsAfter
;}
93 bool isEndOfCell() const { return mbEndOfCell
;}
94 bool isEndOfLine() const { return mbEndOfLine
;}
95 bool isFinalEndOfLine() const { return mbFinalEndOfLine
;}
96 bool isFirstInTable() const { return mbFirstInTable
;}
97 const SwTableBox
* getTableBox() const { return mpTableBox
;}
98 const SwTable
* getTable() const { return mpTable
;}
99 const SwRect
& getRect() const { return maRect
;}
101 const SwNode
* getNode() const;
103 TableBoxVectorPtr
getTableBoxesOfRow() const;
104 WidthsPtr
getWidthsOfRow() const;
105 WidthsPtr
getColumnWidthsBasedOnAllRows() const;
106 GridColsPtr
getGridColsOfRow(AttributeOutputBase
& rBase
, bool calculateColumnsFromAllRows
= false);
107 RowSpansPtr
getRowSpansOfRow() const;
110 std::string
toString() const;
117 WW8TableNodeInfo
* m_pNodeInfo
;
118 tools::ULong m_nFormatFrameWidth
;
121 CellInfo(const SwRect
& aRect
, WW8TableNodeInfo
* pNodeInfo
);
123 CellInfo(const CellInfo
& aRectAndTableInfo
)
124 : m_aRect(aRectAndTableInfo
.m_aRect
),
125 m_pNodeInfo(aRectAndTableInfo
.m_pNodeInfo
),
126 m_nFormatFrameWidth(aRectAndTableInfo
.m_nFormatFrameWidth
)
130 bool operator < (const CellInfo
& aCellInfo
) const;
132 tools::Long
top() const { return m_aRect
.Top(); }
133 tools::Long
bottom() const { return m_aRect
.Bottom(); }
134 tools::Long
left() const { return m_aRect
.Left(); }
135 tools::Long
right() const { return m_aRect
.Right(); }
136 tools::Long
width() const { return m_aRect
.Width(); }
137 tools::Long
height() const { return m_aRect
.Height(); }
138 const SwRect
& getRect() const { return m_aRect
; }
139 WW8TableNodeInfo
* getTableNodeInfo() const
140 { return m_pNodeInfo
; }
141 tools::ULong
getFormatFrameWidth() const
143 return m_nFormatFrameWidth
;
146 void setFormatFrameWidth(tools::ULong nFormatFrameWidth
)
148 m_nFormatFrameWidth
= nFormatFrameWidth
;
152 std::string
toString() const;
156 typedef std::multiset
<CellInfo
> CellInfoMultiSet
;
157 typedef std::map
<sal_uInt32
, WW8TableNodeInfoInner
*,
158 std::greater
<sal_uInt32
> > RowEndInners_t
;
162 class WW8TableNodeInfo final
165 typedef std::map
<sal_uInt32
, WW8TableNodeInfoInner::Pointer_t
,
166 std::greater
<sal_uInt32
> > Inners_t
;
169 WW8TableInfo
* mpParent
;
171 const SwNode
* mpNode
;
173 WW8TableNodeInfo
* mpNext
;
174 const SwNode
* mpNextNode
;
177 typedef std::shared_ptr
<WW8TableNodeInfo
> Pointer_t
;
179 WW8TableNodeInfo(WW8TableInfo
* pParent
, const SwNode
* pTextNode
);
182 void setDepth(sal_uInt32 nDepth
);
183 void setEndOfLine(bool bEndOfLine
);
184 void setEndOfCell(bool bEndOfCell
);
185 void setFirstInTable(bool bFirstInTable
);
186 void setVertMerge(bool bVertMerge
);
187 void setTableBox(const SwTableBox
*pTableBox
);
188 void setTable(const SwTable
* pTable
);
189 void setCell(sal_uInt32 nCell
);
190 void setRow(sal_uInt32 nRow
);
191 void setShadowsBefore(sal_uInt32 nShadowsBefore
);
192 void setShadowsAfter(sal_uInt32 nShadowsAfter
);
193 void setNext(WW8TableNodeInfo
* pNext
);
194 void setNextNode(const SwNode
* pNode
);
195 void setRect(const SwRect
& rRect
);
197 WW8TableInfo
* getParent() const { return mpParent
;}
198 sal_uInt32
getDepth() const;
199 const SwNode
* getNode() const { return mpNode
;}
200 const SwTableBox
* getTableBox() const;
201 WW8TableNodeInfo
* getNext() const { return mpNext
;}
202 const SwNode
* getNextNode() const { return mpNextNode
;}
204 const Inners_t
& getInners() const { return mInners
;}
205 WW8TableNodeInfoInner::Pointer_t
getFirstInner() const;
206 WW8TableNodeInfoInner::Pointer_t
getInnerForDepth(sal_uInt32 nDepth
) const;
208 sal_uInt32
getCell() const;
209 sal_uInt32
getRow() const;
212 std::string
toString() const;
215 bool operator < (const WW8TableNodeInfo
& rInfo
) const;
220 size_t operator()(const SwNode
* pNode
) const
221 { return reinterpret_cast<size_t>(pNode
); }
226 size_t operator()(const SwTable
* pTable
) const
227 { return reinterpret_cast<size_t>(pTable
); }
230 class WW8TableCellGridRow
232 std::shared_ptr
<CellInfoMultiSet
> m_pCellInfos
;
233 TableBoxVectorPtr m_pTableBoxVector
;
235 RowSpansPtr m_pRowSpans
;
238 typedef std::shared_ptr
<WW8TableCellGridRow
> Pointer_t
;
239 WW8TableCellGridRow();
240 ~WW8TableCellGridRow();
242 void insert(const CellInfo
& rCellInfo
);
243 CellInfoMultiSet::const_iterator
begin() const;
244 CellInfoMultiSet::const_iterator
end() const;
246 void setTableBoxVector(TableBoxVectorPtr
const & pTableBoxVector
);
247 void setWidths(WidthsPtr
const & pGridCols
);
248 void setRowSpans(RowSpansPtr
const & pRowSpans
);
250 const TableBoxVectorPtr
& getTableBoxVector() const { return m_pTableBoxVector
;}
251 const WidthsPtr
& getWidths() const { return m_pWidths
;}
252 const RowSpansPtr
& getRowSpans() const { return m_pRowSpans
;}
255 class WW8TableCellGrid
257 typedef std::set
<tools::Long
> RowTops_t
;
258 typedef std::map
<tools::Long
, WW8TableCellGridRow::Pointer_t
> Rows_t
;
260 RowTops_t m_aRowTops
;
263 WW8TableCellGridRow::Pointer_t
getRow(tools::Long nTop
, bool bCreate
= true);
264 RowTops_t::const_iterator
getRowTopsBegin() const;
265 RowTops_t::const_iterator
getRowTopsEnd() const;
266 CellInfoMultiSet::const_iterator
getCellsBegin(tools::Long nTop
);
267 CellInfoMultiSet::const_iterator
getCellsEnd(tools::Long nTop
);
270 typedef std::shared_ptr
<WW8TableCellGrid
> Pointer_t
;
275 void insert(const SwRect
& rRect
, WW8TableNodeInfo
* pNodeInfo
,
276 tools::ULong
const * pFormatFrameWidth
= nullptr);
277 void addShadowCells();
278 WW8TableNodeInfo
*connectCells(RowEndInners_t
&rLastRowEnds
);
281 std::string
toString();
284 TableBoxVectorPtr
getTableBoxesOfRow(WW8TableNodeInfoInner
const * pNodeInfo
);
285 WidthsPtr
getWidthsOfRow(WW8TableNodeInfoInner
const * pNodeInfo
);
286 RowSpansPtr
getRowSpansOfRow(WW8TableNodeInfoInner
const * pNodeInfo
);
289 class WW8TableInfo final
291 friend class WW8TableNodeInfoInner
;
292 typedef std::unordered_map
<const SwNode
*, WW8TableNodeInfo::Pointer_t
, hashNode
> Map_t
;
295 typedef std::unordered_map
<const SwTable
*, WW8TableCellGrid::Pointer_t
, hashTable
> CellGridMap_t
;
296 CellGridMap_t mCellGridMap
;
298 typedef std::unordered_map
<const SwTable
*, const SwNode
*, hashTable
> FirstInTableMap_t
;
299 FirstInTableMap_t mFirstInTableMap
;
302 processTableLine(const SwTable
* pTable
,
303 const SwTableLine
* pTableLine
,
305 sal_uInt32 nDepth
, WW8TableNodeInfo
* pPrev
, RowEndInners_t
&rLastRowEnds
);
308 processTableBox(const SwTable
* pTable
,
309 const SwTableBox
* pTableBox
,
312 sal_uInt32 nDepth
, bool bEndOfLine
,
313 WW8TableNodeInfo
* pPrev
, RowEndInners_t
&rLastRowEnds
);
315 WW8TableNodeInfo::Pointer_t
316 processTableBoxLines(const SwTableBox
* pBox
,
317 const SwTable
* pTable
,
318 const SwTableBox
* pBoxToSet
,
323 WW8TableNodeInfo::Pointer_t
324 insertTableNodeInfo(const SwNode
* pNode
,
325 const SwTable
* pTable
,
326 const SwTableBox
* pTableBox
,
330 SwRect
const * pRect
= nullptr);
332 WW8TableCellGrid::Pointer_t
getCellGridForTable(const SwTable
* pTable
,
333 bool bCreate
= true);
336 typedef std::shared_ptr
<WW8TableInfo
> Pointer_t
;
341 void processSwTable(const SwTable
* pTable
);
342 WW8TableNodeInfo
* processSwTableByLayout(const SwTable
* pTable
, RowEndInners_t
&rLastRowEnds
);
343 WW8TableNodeInfo::Pointer_t
getTableNodeInfo(const SwNode
* pNode
);
344 const SwNode
* getNextNode(const SwNode
* pNode
);
346 WW8TableNodeInfo
* reorderByLayout(const SwTable
* pTable
, RowEndInners_t
&rLastRowEnds
);
350 #endif // INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */