1//
2// Table.cpp
3//
4// Library: PDF
5// Package: PDFCore
6// Module: Table
7//
8// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/PDF/Table.h"
16
17
18namespace Poco {
19namespace PDF {
20
21
22Table::Table(int columnCount, int rowCount, const std::string& name, Cell::FontMapPtr pFontMap):
23 _name(name), _cells(rowCount, TableRow(columnCount))
24{
25 setFonts(pFontMap);
26}
27
28
29Table::~Table()
30{
31}
32
33
34void Table::addRow()
35{
36 _cells.push_back(TableRow(columns()));
37}
38
39
40void Table::addRow(const TableRow& row)
41{
42 if (_cells.empty())
43 {
44 _cells.push_back(row);
45 }
46 else
47 {
48 _cells.push_back(row);
49 _cells.back().resize(_cells.front().size());
50 }
51}
52
53
54void Table::setCell(int col, int row, const Cell& cell)
55{
56 _cells[row][col] = cell;
57 if (_pFontMap && !cell.getFonts()) _cells[row][col].setFonts(_pFontMap);
58}
59
60
61void Table::setColumnWidth(int col, double width)
62{
63}
64
65
66void Table::setFonts(Cell::FontMapPtr pFontMap)
67{
68 _pFontMap = pFontMap;
69 if (_pFontMap) { poco_assert(_pFontMap->size() == 4); }
70}
71
72
73void Table::draw(Page& page, float x, float y, float width, float height)
74{
75 if (_cells.size())
76 {
77 int rows = _cells.size();
78 int cols = _cells[0].size();
79 int r = 0;
80 for (auto& row : _cells)
81 {
82 float h = height / rows;
83 int c = 0;
84 for (auto& cell : row)
85 {
86 float w = width / cols;
87 cell.draw(page, x + (w * c), y - (h * r), w, h);
88 ++c;
89 }
90 ++r;
91 }
92 }
93}
94
95
96} } // namespace Poco::PDF
97