LibreOffice Module sw (master) 1
WW8TableInfo.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
20#ifndef INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
21#define INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
22#include <string>
23#include <map>
24#include <memory>
25#include <set>
26#include <functional>
27#include <unordered_map>
28#include <vector>
29#include <sal/types.h>
30#include <swrect.hxx>
31
32class SwTable;
33class SwTableLine;
34class SwTableBox;
35class SwNode;
37
38namespace ww8
39{
40const unsigned int MAXTABLECELLS = 63;
41
43typedef std::vector<const SwTableBox *> TableBoxVector;
44typedef std::shared_ptr<TableBoxVector> TableBoxVectorPtr;
45typedef std::vector<sal_uInt32> GridCols;
46typedef std::shared_ptr<GridCols> GridColsPtr;
47typedef std::vector<sal_Int32> RowSpans;
48typedef std::shared_ptr<RowSpans> RowSpansPtr;
49typedef std::vector<sal_uInt32> Widths;
50typedef std::shared_ptr<Widths> WidthsPtr;
51
53{
55 sal_uInt32 mnDepth;
56 sal_uInt32 mnCell;
57 sal_uInt32 mnRow;
58 sal_uInt32 mnShadowsBefore;
59 sal_uInt32 mnShadowsAfter;
68
69public:
70 typedef std::shared_ptr<WW8TableNodeInfoInner> Pointer_t;
71
72 explicit WW8TableNodeInfoInner(WW8TableNodeInfo * pParent);
73
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);
87
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;}
100
101 const SwNode * getNode() const;
102
106 GridColsPtr getGridColsOfRow(AttributeOutputBase & rBase, bool calculateColumnsFromAllRows = false);
108
109#ifdef DBG_UTIL
110 std::string toString() const;
111#endif
112};
113
115{
119
120public:
121 CellInfo(const SwRect & aRect, WW8TableNodeInfo * pNodeInfo);
122
123 CellInfo(const CellInfo & aRectAndTableInfo)
124 : m_aRect(aRectAndTableInfo.m_aRect),
125 m_pNodeInfo(aRectAndTableInfo.m_pNodeInfo),
127 {
128 }
129
130 bool operator < (const CellInfo & aCellInfo) const;
131
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; }
140 { return m_pNodeInfo; }
142 {
143 return m_nFormatFrameWidth;
144 }
145
146 void setFormatFrameWidth(tools::ULong nFormatFrameWidth)
147 {
148 m_nFormatFrameWidth = nFormatFrameWidth;
149 }
150
151#ifdef DBG_UTIL
152 std::string toString() const;
153#endif
154};
155
156typedef std::multiset<CellInfo> CellInfoMultiSet;
157typedef std::map<sal_uInt32, WW8TableNodeInfoInner*,
158 std::greater<sal_uInt32> > RowEndInners_t;
159
160
161class WW8TableInfo;
163{
164public:
165 typedef std::map<sal_uInt32, WW8TableNodeInfoInner::Pointer_t,
166 std::greater<sal_uInt32> > Inners_t;
167
168private:
170 sal_uInt32 mnDepth;
171 const SwNode * mpNode;
175
176public:
177 typedef std::shared_ptr<WW8TableNodeInfo> Pointer_t;
178
179 WW8TableNodeInfo(WW8TableInfo * pParent, const SwNode * pTextNode);
181
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);
196
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;}
203
204 const Inners_t & getInners() const { return mInners;}
206 WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const;
207
208 sal_uInt32 getCell() const;
209 sal_uInt32 getRow() const;
210
211#ifdef DBG_UTIL
212 std::string toString() const;
213#endif
214
215 bool operator < (const WW8TableNodeInfo & rInfo) const;
216};
217
219{
220 size_t operator()(const SwNode * pNode) const
221 { return reinterpret_cast<size_t>(pNode); }
222};
223
225{
226 size_t operator()(const SwTable * pTable) const
227 { return reinterpret_cast<size_t>(pTable); }
228};
229
231{
232 std::shared_ptr<CellInfoMultiSet> m_pCellInfos;
236
237public:
238 typedef std::shared_ptr<WW8TableCellGridRow> Pointer_t;
241
242 void insert(const CellInfo & rCellInfo);
243 CellInfoMultiSet::const_iterator begin() const;
244 CellInfoMultiSet::const_iterator end() const;
245
246 void setTableBoxVector(TableBoxVectorPtr const & pTableBoxVector);
247 void setWidths(WidthsPtr const & pGridCols);
248 void setRowSpans(RowSpansPtr const & pRowSpans);
249
251 const WidthsPtr& getWidths() const { return m_pWidths;}
252 const RowSpansPtr& getRowSpans() const { return m_pRowSpans;}
253};
254
256{
257 typedef std::set<tools::Long> RowTops_t;
258 typedef std::map<tools::Long, WW8TableCellGridRow::Pointer_t> Rows_t;
259
262
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);
268
269public:
270 typedef std::shared_ptr<WW8TableCellGrid> Pointer_t;
271
274
275 void insert(const SwRect & rRect, WW8TableNodeInfo * pNodeInfo,
276 tools::ULong const * pFormatFrameWidth = nullptr);
277 void addShadowCells();
279
280#ifdef DBG_UTIL
281 std::string toString();
282#endif
283
287};
288
289class WW8TableInfo final
290{
292 typedef std::unordered_map<const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t;
294
295 typedef std::unordered_map<const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t;
297
298 typedef std::unordered_map<const SwTable *, const SwNode *, hashTable > FirstInTableMap_t;
300
302 processTableLine(const SwTable * pTable,
303 const SwTableLine * pTableLine,
304 sal_uInt32 nRow,
305 sal_uInt32 nDepth, WW8TableNodeInfo * pPrev, RowEndInners_t &rLastRowEnds);
306
308 processTableBox(const SwTable * pTable,
309 const SwTableBox * pTableBox,
310 sal_uInt32 nRow,
311 sal_uInt32 nCell,
312 sal_uInt32 nDepth, bool bEndOfLine,
313 WW8TableNodeInfo * pPrev, RowEndInners_t &rLastRowEnds);
314
316 processTableBoxLines(const SwTableBox * pBox,
317 const SwTable * pTable,
318 const SwTableBox * pBoxToSet,
319 sal_uInt32 nRow,
320 sal_uInt32 nCell,
321 sal_uInt32 nDepth);
322
324 insertTableNodeInfo(const SwNode * pNode,
325 const SwTable * pTable,
326 const SwTableBox * pTableBox,
327 sal_uInt32 nRow,
328 sal_uInt32 nCell,
329 sal_uInt32 nDepth,
330 SwRect const * pRect = nullptr);
331
333 bool bCreate = true);
334
335public:
336 typedef std::shared_ptr<WW8TableInfo> Pointer_t;
337
338 WW8TableInfo();
340
341 void processSwTable(const SwTable * pTable);
342 WW8TableNodeInfo * processSwTableByLayout(const SwTable * pTable, RowEndInners_t &rLastRowEnds);
344 const SwNode * getNextNode(const SwNode * pNode);
345
346 WW8TableNodeInfo * reorderByLayout(const SwTable * pTable, RowEndInners_t &rLastRowEnds);
347};
348
349}
350#endif // INCLUDED_SW_SOURCE_FILTER_WW8_WW8TABLEINFO_HXX
351
352/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class of the Writer document model elements.
Definition: node.hxx:98
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
void Right(const tools::Long nRight)
Definition: swrect.hxx:202
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
void Width(tools::Long nNew)
Definition: swrect.hxx:189
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwTableLine is one table row in the document model.
Definition: swtable.hxx:376
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
tools::ULong getFormatFrameWidth() const
WW8TableNodeInfo * getTableNodeInfo() const
const SwRect & getRect() const
tools::Long top() const
tools::Long height() const
tools::Long width() const
tools::ULong m_nFormatFrameWidth
tools::Long left() const
bool operator<(const CellInfo &aCellInfo) const
std::string toString() const
CellInfo(const SwRect &aRect, WW8TableNodeInfo *pNodeInfo)
WW8TableNodeInfo * m_pNodeInfo
tools::Long bottom() const
CellInfo(const CellInfo &aRectAndTableInfo)
void setFormatFrameWidth(tools::ULong nFormatFrameWidth)
tools::Long right() const
CellInfoMultiSet::const_iterator begin() const
void insert(const CellInfo &rCellInfo)
CellInfoMultiSet::const_iterator end() const
void setWidths(WidthsPtr const &pGridCols)
std::shared_ptr< WW8TableCellGridRow > Pointer_t
void setTableBoxVector(TableBoxVectorPtr const &pTableBoxVector)
const RowSpansPtr & getRowSpans() const
std::shared_ptr< CellInfoMultiSet > m_pCellInfos
const WidthsPtr & getWidths() const
const TableBoxVectorPtr & getTableBoxVector() const
TableBoxVectorPtr m_pTableBoxVector
void setRowSpans(RowSpansPtr const &pRowSpans)
std::shared_ptr< WW8TableCellGrid > Pointer_t
WidthsPtr getWidthsOfRow(WW8TableNodeInfoInner const *pNodeInfo)
std::map< tools::Long, WW8TableCellGridRow::Pointer_t > Rows_t
WW8TableCellGridRow::Pointer_t getRow(tools::Long nTop, bool bCreate=true)
RowSpansPtr getRowSpansOfRow(WW8TableNodeInfoInner const *pNodeInfo)
WW8TableNodeInfo * connectCells(RowEndInners_t &rLastRowEnds)
RowTops_t::const_iterator getRowTopsEnd() const
void insert(const SwRect &rRect, WW8TableNodeInfo *pNodeInfo, tools::ULong const *pFormatFrameWidth=nullptr)
CellInfoMultiSet::const_iterator getCellsBegin(tools::Long nTop)
CellInfoMultiSet::const_iterator getCellsEnd(tools::Long nTop)
RowTops_t::const_iterator getRowTopsBegin() const
std::set< tools::Long > RowTops_t
TableBoxVectorPtr getTableBoxesOfRow(WW8TableNodeInfoInner const *pNodeInfo)
WW8TableNodeInfo * processTableBox(const SwTable *pTable, const SwTableBox *pTableBox, sal_uInt32 nRow, sal_uInt32 nCell, sal_uInt32 nDepth, bool bEndOfLine, WW8TableNodeInfo *pPrev, RowEndInners_t &rLastRowEnds)
std::unordered_map< const SwTable *, WW8TableCellGrid::Pointer_t, hashTable > CellGridMap_t
WW8TableNodeInfo::Pointer_t getTableNodeInfo(const SwNode *pNode)
FirstInTableMap_t mFirstInTableMap
WW8TableCellGrid::Pointer_t getCellGridForTable(const SwTable *pTable, bool bCreate=true)
std::unordered_map< const SwNode *, WW8TableNodeInfo::Pointer_t, hashNode > Map_t
WW8TableNodeInfo * processTableLine(const SwTable *pTable, const SwTableLine *pTableLine, sal_uInt32 nRow, sal_uInt32 nDepth, WW8TableNodeInfo *pPrev, RowEndInners_t &rLastRowEnds)
WW8TableNodeInfo * reorderByLayout(const SwTable *pTable, RowEndInners_t &rLastRowEnds)
WW8TableNodeInfo * processSwTableByLayout(const SwTable *pTable, RowEndInners_t &rLastRowEnds)
std::unordered_map< const SwTable *, const SwNode *, hashTable > FirstInTableMap_t
std::shared_ptr< WW8TableInfo > Pointer_t
void processSwTable(const SwTable *pTable)
WW8TableNodeInfo::Pointer_t insertTableNodeInfo(const SwNode *pNode, const SwTable *pTable, const SwTableBox *pTableBox, sal_uInt32 nRow, sal_uInt32 nCell, sal_uInt32 nDepth, SwRect const *pRect=nullptr)
WW8TableNodeInfo::Pointer_t processTableBoxLines(const SwTableBox *pBox, const SwTable *pTable, const SwTableBox *pBoxToSet, sal_uInt32 nRow, sal_uInt32 nCell, sal_uInt32 nDepth)
const SwNode * getNextNode(const SwNode *pNode)
CellGridMap_t mCellGridMap
void setTableBox(const SwTableBox *pTableBox)
const SwNode * getNode() const
const SwTableBox * mpTableBox
const SwTableBox * getTableBox() const
void setRect(const SwRect &rRect)
GridColsPtr getGridColsOfRow(AttributeOutputBase &rBase, bool calculateColumnsFromAllRows=false)
const SwTable * getTable() const
sal_uInt32 getDepth() const
sal_uInt32 getShadowsAfter() const
void setFinalEndOfLine(bool bEndOfLine)
WidthsPtr getColumnWidthsBasedOnAllRows() const
void setEndOfLine(bool bEndOfLine)
RowSpansPtr getRowSpansOfRow() const
std::string toString() const
void setCell(sal_uInt32 nCell)
void setFirstInTable(bool bFirstInTable)
TableBoxVectorPtr getTableBoxesOfRow() const
void setShadowsBefore(sal_uInt32 nShadowsBefore)
WW8TableNodeInfoInner(WW8TableNodeInfo *pParent)
WW8TableNodeInfo * mpParent
void setDepth(sal_uInt32 nDepth)
void setRow(sal_uInt32 nRow)
sal_uInt32 getShadowsBefore() const
sal_uInt32 getRow() const
const SwRect & getRect() const
WidthsPtr getWidthsOfRow() const
sal_uInt32 getCell() const
void setEndOfCell(bool bEndOfCell)
void setVertMerge(bool bVertMerge)
std::shared_ptr< WW8TableNodeInfoInner > Pointer_t
void setTable(const SwTable *pTable)
void setShadowsAfter(sal_uInt32 nShadowsAfter)
WW8TableInfo * getParent() const
WW8TableNodeInfoInner::Pointer_t getFirstInner() const
void setNextNode(const SwNode *pNode)
std::map< sal_uInt32, WW8TableNodeInfoInner::Pointer_t, std::greater< sal_uInt32 > > Inners_t
void setShadowsAfter(sal_uInt32 nShadowsAfter)
void setRect(const SwRect &rRect)
const SwNode * getNextNode() const
void setVertMerge(bool bVertMerge)
void setCell(sal_uInt32 nCell)
void setEndOfLine(bool bEndOfLine)
void setNext(WW8TableNodeInfo *pNext)
WW8TableNodeInfo * getNext() const
void setEndOfCell(bool bEndOfCell)
const SwNode * getNode() const
void setTableBox(const SwTableBox *pTableBox)
sal_uInt32 getCell() const
void setShadowsBefore(sal_uInt32 nShadowsBefore)
void setDepth(sal_uInt32 nDepth)
WW8TableNodeInfo * mpNext
sal_uInt32 getDepth() const
void setFirstInTable(bool bFirstInTable)
WW8TableNodeInfo(WW8TableInfo *pParent, const SwNode *pTextNode)
const Inners_t & getInners() const
const SwTableBox * getTableBox() const
std::shared_ptr< WW8TableNodeInfo > Pointer_t
void setRow(sal_uInt32 nRow)
std::string toString() const
WW8TableInfo * mpParent
WW8TableNodeInfoInner::Pointer_t getInnerForDepth(sal_uInt32 nDepth) const
bool operator<(const WW8TableNodeInfo &rInfo) const
void setTable(const SwTable *pTable)
sal_uInt32 getRow() const
const SwNode * mpNextNode
const SwNode * mpNode
unsigned long ULong
long Long
std::shared_ptr< RowSpans > RowSpansPtr
std::vector< sal_uInt32 > Widths
std::shared_ptr< GridCols > GridColsPtr
std::shared_ptr< TableBoxVector > TableBoxVectorPtr
std::multiset< CellInfo > CellInfoMultiSet
std::vector< sal_Int32 > RowSpans
std::shared_ptr< Widths > WidthsPtr
std::map< sal_uInt32, WW8TableNodeInfoInner *, std::greater< sal_uInt32 > > RowEndInners_t
const unsigned int MAXTABLECELLS
std::vector< const SwTableBox * > TableBoxVector
std::vector< sal_uInt32 > GridCols
size_t operator()(const SwNode *pNode) const
size_t operator()(const SwTable *pTable) const