2018-02-02 12:24:16 -06:00
|
|
|
//
|
|
|
|
// Table.cpp
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Poco/PDF/Table.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Poco {
|
|
|
|
namespace PDF {
|
|
|
|
|
|
|
|
|
|
|
|
Table::Table(int columnCount, int rowCount, const std::string& name, Cell::FontMapPtr pFontMap):
|
|
|
|
_name(name), _cells(rowCount, TableRow(columnCount))
|
|
|
|
{
|
|
|
|
setFonts(pFontMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Table::~Table()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Table::addRow()
|
|
|
|
{
|
|
|
|
_cells.push_back(TableRow(columns()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Table::addRow(const TableRow& row)
|
|
|
|
{
|
|
|
|
if (_cells.empty())
|
|
|
|
{
|
|
|
|
_cells.push_back(row);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_cells.push_back(row);
|
|
|
|
_cells.back().resize(_cells.front().size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Table::setCell(int col, int row, const Cell& cell)
|
|
|
|
{
|
|
|
|
_cells[row][col] = cell;
|
|
|
|
if (_pFontMap && !cell.getFonts()) _cells[row][col].setFonts(_pFontMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Table::setColumnWidth(int col, double width)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Table::setFonts(Cell::FontMapPtr pFontMap)
|
|
|
|
{
|
|
|
|
_pFontMap = pFontMap;
|
|
|
|
if (_pFontMap) { poco_assert(_pFontMap->size() == 4); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Table::draw(Page& page, float x, float y, float width, float height)
|
|
|
|
{
|
|
|
|
if (_cells.size())
|
|
|
|
{
|
|
|
|
int rows = _cells.size();
|
|
|
|
int cols = _cells[0].size();
|
|
|
|
int r = 0;
|
2018-03-07 10:14:49 +01:00
|
|
|
for (Cells::iterator it = _cells.begin(); it != _cells.end(); ++it)
|
2018-02-02 12:24:16 -06:00
|
|
|
{
|
2018-03-07 10:14:49 +01:00
|
|
|
TableRow& row(*it);
|
2018-02-02 12:24:16 -06:00
|
|
|
float h = height / rows;
|
|
|
|
int c = 0;
|
2018-03-07 10:14:49 +01:00
|
|
|
for (TableRow::iterator itr = row.begin(); itr != row.end(); ++itr)
|
2018-02-02 12:24:16 -06:00
|
|
|
{
|
2018-03-07 10:14:49 +01:00
|
|
|
Cell& cell(*itr);
|
2018-02-02 12:24:16 -06:00
|
|
|
float w = width / cols;
|
|
|
|
cell.draw(page, x + (w * c), y - (h * r), w, h);
|
|
|
|
++c;
|
|
|
|
}
|
|
|
|
++r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} } // namespace Poco::PDF
|