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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
#ifndef LH_TABLE_H
#define LH_TABLE_H
#include <vector>
#include <memory>
#include "css_length.h"
namespace litehtml
{
class render_item;
struct table_row
{
using vector = std::vector<table_row>;
int height;
int border_top;
int border_bottom;
std::shared_ptr<render_item> el_row;
int top;
int bottom;
css_length css_height;
int min_height;
table_row()
{
min_height = 0;
top = 0;
bottom = 0;
border_bottom = 0;
border_top = 0;
height = 0;
el_row = nullptr;
css_height.predef(0);
}
table_row(int h, const std::shared_ptr<render_item>& row);
table_row(const table_row& val)
{
min_height = val.min_height;
top = val.top;
bottom = val.bottom;
border_bottom = val.border_bottom;
border_top = val.border_top;
height = val.height;
css_height = val.css_height;
el_row = val.el_row;
}
table_row(table_row&& val) noexcept
{
min_height = val.min_height;
top = val.top;
bottom = val.bottom;
border_bottom = val.border_bottom;
border_top = val.border_top;
height = val.height;
css_height = val.css_height;
el_row = std::move(val.el_row);
}
};
struct table_column
{
using vector = std::vector<table_column>;
int min_width;
int max_width;
int width;
css_length css_width;
int border_left;
int border_right;
int left;
int right;
table_column()
{
left = 0;
right = 0;
border_left = 0;
border_right = 0;
min_width = 0;
max_width = 0;
width = 0;
css_width.predef(0);
}
table_column(int min_w, int max_w)
{
left = 0;
right = 0;
border_left = 0;
border_right = 0;
max_width = max_w;
min_width = min_w;
width = 0;
css_width.predef(0);
}
table_column(const table_column& val)
{
left = val.left;
right = val.right;
border_left = val.border_left;
border_right = val.border_right;
max_width = val.max_width;
min_width = val.min_width;
width = val.width;
css_width = val.css_width;
}
};
class table_column_accessor
{
public:
virtual int& get(table_column& col) = 0;
protected:
~table_column_accessor() = default;
};
class table_column_accessor_max_width final : public table_column_accessor
{
public:
int& get(table_column& col) override;
};
class table_column_accessor_min_width final : public table_column_accessor
{
public:
int& get(table_column& col) override;
};
class table_column_accessor_width final : public table_column_accessor
{
public:
int& get(table_column& col) override;
};
struct table_cell
{
std::shared_ptr<render_item> el;
int colspan;
int rowspan;
int min_width;
int min_height;
int max_width;
int max_height;
int width;
int height;
margins borders;
table_cell()
{
min_width = 0;
min_height = 0;
max_width = 0;
max_height = 0;
width = 0;
height = 0;
colspan = 1;
rowspan = 1;
el = nullptr;
}
table_cell(const table_cell& val)
{
el = val.el;
colspan = val.colspan;
rowspan = val.rowspan;
width = val.width;
height = val.height;
min_width = val.min_width;
min_height = val.min_height;
max_width = val.max_width;
max_height = val.max_height;
borders = val.borders;
}
table_cell(table_cell&& val) noexcept
{
el = std::move(val.el);
colspan = val.colspan;
rowspan = val.rowspan;
width = val.width;
height = val.height;
min_width = val.min_width;
min_height = val.min_height;
max_width = val.max_width;
max_height = val.max_height;
borders = val.borders;
}
};
class table_grid
{
public:
using rows = std::vector<std::vector<table_cell>>;
private:
int m_rows_count;
int m_cols_count;
rows m_cells;
table_column::vector m_columns;
table_row::vector m_rows;
std::vector<std::shared_ptr<render_item>> m_captions;
int m_top_captions_height;
int m_bottom_captions_height;
public:
table_grid() :
m_rows_count(0),
m_cols_count(0),
m_top_captions_height(0),
m_bottom_captions_height(0)
{
}
void clear();
void begin_row(const std::shared_ptr<render_item>& row);
void add_cell(const std::shared_ptr<render_item>& el);
bool is_rowspanned(int r, int c);
void finish();
table_cell* cell(int t_col, int t_row);
table_column& column(int c) { return m_columns[c]; }
table_row& row(int r) { return m_rows[r]; }
std::vector<std::shared_ptr<render_item>>& captions() { return m_captions; }
int rows_count() const { return m_rows_count; }
int cols_count() const { return m_cols_count; }
void top_captions_height(int height) { m_top_captions_height = height; }
int top_captions_height() const { return m_top_captions_height; }
void bottom_captions_height(int height) { m_bottom_captions_height = height; }
int bottom_captions_height() const { return m_bottom_captions_height; }
void distribute_max_width(int width, int start, int end);
void distribute_min_width(int width, int start, int end);
void distribute_width(int width, int start, int end);
void distribute_width(int width, int start, int end, table_column_accessor* acc);
int calc_table_width(int block_width, bool is_auto, int& min_table_width, int& max_table_width);
void calc_horizontal_positions(const margins& table_borders, border_collapse bc, int bdr_space_x);
void calc_vertical_positions(const margins& table_borders, border_collapse bc, int bdr_space_y);
void calc_rows_height(int blockHeight, int borderSpacingY);
};
}
#endif // LH_TABLE_H
|