1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* This file is part of the libsw602 project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*
* Structure to store and construct a table from an unstructured list
* of cell
*
*/
#ifndef INCLUDED_SW602_TABLE_H
#define INCLUDED_SW602_TABLE_H
#include <iostream>
#include <vector>
#include "SW602Cell.h"
#include "SW602Types.h"
namespace libsw602
{
/** a class used to recreate the table structure using cell informations, .... */
class SW602Table
{
public:
//! an enum used to indicate what the list of entries which are filled
enum DataSet
{
CellPositionBit=1, BoxBit=2, SizeBit=4, TableDimBit=8, TablePosToCellBit=0x10
};
/** an enum do define the table alignment.
\note Paragraph means using the default alignment, left page alignment and use left margin */
enum Alignment
{
Paragraph, Left, Center, Right
};
//! the constructor
explicit SW602Table(uint32_t givenData=BoxBit) :
m_givenData(givenData), m_setData(givenData), m_mergeBorders(true), m_cellsList(),
m_numRows(0), m_numCols(0), m_rowsSize(), m_colsSize(), m_alignment(Paragraph), m_leftMargin(0), m_rightMargin(0),
m_posToCellId(), m_hasExtraLines(false) {}
//! the destructor
virtual ~SW602Table();
//! add a new cells
void add(boost::shared_ptr<SW602Cell> cell)
{
if (!cell)
{
SW602_DEBUG_MSG(("SW602Table::add: must be called with a cell\n"));
return;
}
m_cellsList.push_back(cell);
}
//! returns true if we need to merge borders
bool mergeBorders() const
{
return m_mergeBorders;
}
//! sets the merge borders' value
bool setMergeBorders(bool val)
{
return m_mergeBorders=val;
}
/** defines the current alignment
\note: leftMargin,rightMargin are given in Points */
void setAlignment(Alignment align, float leftMargin=0, float rightMargin=0)
{
m_alignment = align;
m_leftMargin = leftMargin;
m_rightMargin = rightMargin;
}
//! returns the number of cell
int numCells() const
{
return int(m_cellsList.size());
}
/** returns the row size if defined (in point) */
std::vector<float> const &getRowsSize() const
{
return m_rowsSize;
}
/** define the row size (in point) */
void setRowsSize(std::vector<float> const &rSize)
{
m_rowsSize=rSize;
}
/** returns the columns size if defined (in point) */
std::vector<float> const &getColsSize() const
{
return m_colsSize;
}
/** define the columns size (in point) */
void setColsSize(std::vector<float> const &cSize)
{
m_colsSize=cSize;
}
//! returns the i^th cell
boost::shared_ptr<SW602Cell> get(int id);
/** try to build the table structures */
bool updateTable();
/** returns true if the table has extralines */
bool hasExtraLines()
{
if (!updateTable()) return false;
return m_hasExtraLines;
}
/** try to send the table
Note: either send the table ( and returns true ) or do nothing.
*/
bool sendTable(SW602ListenerPtr listener, bool inFrame=true);
/** try to send the table as basic text */
bool sendAsText(SW602ListenerPtr listener);
// interface with the content listener
//! adds the table properties to propList
void addTablePropertiesTo(librevenge::RVNGPropertyList &propList) const;
protected:
//! convert a cell position in a posToCellId's position
int getCellIdPos(int col, int row) const
{
if (col<0||col>=int(m_numCols))
return -1;
if (row<0||row>=int(m_numRows))
return -1;
return col*int(m_numRows)+row;
}
//! create the correspondance list, ...
bool buildStructures();
/** compute the rows and the cells size */
bool buildDims();
/** a function which fills to posToCellId vector using the cell position */
bool buildPosToCellId();
//! send extra line
void sendExtraLines(SW602ListenerPtr listener) const;
protected:
/** a int to indicate what data are given in entries*/
uint32_t m_givenData;
/** a int to indicate what data are been reconstruct*/
uint32_t m_setData;
/** do we need to merge cell borders ( default yes) */
bool m_mergeBorders;
/** the list of cells */
std::vector<boost::shared_ptr<SW602Cell> > m_cellsList;
/** the number of rows ( set by buildPosToCellId ) */
size_t m_numRows;
/** the number of cols ( set by buildPosToCellId ) */
size_t m_numCols;
/** the final row size (in point) */
std::vector<float> m_rowsSize;
/** the final col size (in point) */
std::vector<float> m_colsSize;
/** the table alignment */
Alignment m_alignment;
/** the left margin in point */
float m_leftMargin;
/** the right margin in point */
float m_rightMargin;
/** a vector used to store an id corresponding to each cell */
std::vector<int> m_posToCellId;
/** true if we need to send extra lines */
bool m_hasExtraLines;
};
}
#endif
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|