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
|
// Copyright © 2011, 2012 Richard Kettlewell.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <config.h>
#include "Document.h"
#include <cstdio>
// Node -----------------------------------------------------------------------
Document::Node::~Node() {
}
// LinearContainer ------------------------------------------------------------
Document::LinearContainer::~LinearContainer() {
for(size_t n = 0; n < nodes.size(); ++n)
delete nodes[n];
}
// String ---------------------------------------------------------------------
Document::String::String(int n) {
char buffer[64];
snprintf(buffer, sizeof buffer, "%d", n);
text = buffer;
}
// Table ----------------------------------------------------------------------
Document::Table::~Table() {
for(size_t n = 0; n < cells.size(); ++n)
delete cells[n];
}
int Document::Table::width() const {
int w = 0;
for(size_t n = 0; n < cells.size(); ++n) {
const Cell *cell = cells[n];
int ww = cell->x + cell->w;
if(ww > w)
w = ww;
}
return w;
}
int Document::Table::height() const {
int h = 0;
for(size_t n = 0; n < cells.size(); ++n) {
const Cell *cell = cells[n];
int hh = cell->y + cell->h;
if(hh > h)
h = hh;
}
return h;
}
Document::Cell *Document::Table::addCell(Cell *cell) {
addCell(cell, x, y);
while(occupied(x, y))
++x;
return cell;
}
void Document::Table::newRow() {
x = 0;
++y;
while(occupied(x, y))
++x;
}
Document::Cell *Document::Table::addCell(Cell *cell, int x, int y) {
cell->x = x;
cell->y = y;
cells.push_back(cell);
return cell;
}
Document::Cell *Document::Table::occupied(int x, int y) const {
for(size_t n = 0; n < cells.size(); ++n) {
Cell *cell = cells[n];
if(x >= cell->x && x < cell->x + cell->w
&& y >= cell->y && y < cell->y + cell->h)
return cell;
}
return nullptr;
}
|