1
///////////////////////////////////////////////////////////////////////////////
4
// Author: Ulrich Telle
7
// Copyright: (c) Ulrich Telle
8
// Licence: wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
11
/// \file pdfxml.h Interface of the wxPdfDocument markup
17
#include <wx/string.h>
18
#include <wx/wfstream.h>
20
// wxPdfDocument headers
21
#include "wx/pdfdocdef.h"
22
#include "wx/pdfdocument.h"
24
class WXDLLIMPEXP_FWD_PDFDOC wxPdfTable;
26
/// Class representing cell context objects. (For internal use only)
27
class WXDLLIMPEXP_PDFDOC wxPdfCellContext
31
wxPdfCellContext(double maxWidth, wxPdfAlignment hAlign = wxPDF_ALIGN_JUSTIFY, wxPdfAlignment vAlign = wxPDF_ALIGN_TOP);
34
virtual ~wxPdfCellContext();
36
/// Increase total height of cell
37
void AddHeight(double height) { m_height += height; }
39
/// Get total height of cell
40
double GetHeight() { return m_height; }
42
/// Get maximal width of cell
43
double GetMaxWidth() { return m_maxWidth; }
45
/// Get horizontal alignment
46
wxPdfAlignment GetHAlign() { return m_hAlign; }
48
/// Set vertical alignment
49
void SetVAlign(wxPdfAlignment vAlign) { m_vAlign = vAlign; }
51
/// Get vertical alignment
52
wxPdfAlignment GetVAlign() { return m_vAlign; }
54
/// Add a line to cell
57
/// Get number of lines in cell
58
unsigned int GetLineCount() { return (unsigned int) m_linewidth.GetCount(); }
60
/// Add width and number of spaces of the last line of the current context
61
void AddLastLineValues(double width, int spaces);
63
/// Get the width of the last line
64
double GetLastLineWidth();
66
/// Mark the current line as the last line
69
/// Check whether current line is marked as last line
70
bool IsCurrentLineMarked();
72
/// Adjust width of current line
73
void AddCurrentLineWidth(double width);
75
/// Adjust number of spaces of current line
76
void AddCurrentLineSpaces(int spaces);
78
/// Get width of current line
79
double GetCurrentLineWidth();
81
/// Get number of spaces of current line
82
int GetCurrentLineSpaces();
84
/// Get number of current line
85
unsigned int GetCurrentLine() { return m_currentLine; }
87
/// Increment line counter
88
void IncrementCurrentLine();
90
/// Get line delta measure
91
double GetLineDelta();
93
/// Check whether alignment has been taken care of
94
bool GetAligned() { return m_aligned; }
96
/// Set flag that alignment has been taken care of
97
void SetAligned() { m_aligned = true; }
99
/// Get cell fill style
100
int GetFillStyle() { return m_fillStyle; }
102
/// Set cell fill style
103
void SetFillStyle(int fillStyle) { m_fillStyle = fillStyle; }
105
/// Get the number of contexts
106
unsigned int GetContextCount() { return (unsigned int) m_contexts.GetCount(); }
108
/// Increment current context
109
void IncrementCurrentContext();
111
/// Get current context
112
wxPdfCellContext* GetCurrentContext();
114
/// Append context to context list
115
void AppendContext(wxPdfCellContext* context);
117
/// Remember the last character of the last chunk
118
void SetLastChar(wxChar c) { m_lastChar = c; }
120
/// Get last character of previous chunk
121
wxChar GetLastChar() { return m_lastChar; }
123
/// Remember the width of the last space character
124
void SetLastSpaceWidth(double w) { m_spaceWidth = w; }
126
/// Get width of last space character
127
double GetLastSpaceWidth() { return m_spaceWidth; }
129
/// Set hyper link reference
130
void SetHRef(const wxString& href) { m_href = href; }
132
/// Get hyper link reference
133
wxString& GetHRef() { return m_href; }
135
/// Set table reference
136
void SetTable(wxPdfTable* table) { m_table = table; }
138
/// Get table reference
139
wxPdfTable* GetTable() { return m_table; }
142
double m_maxWidth; ///< maximal line width
143
double m_lineDelta; ///< line delta measure
144
wxPdfAlignment m_hAlign; ///< horizontal alignment
145
wxPdfAlignment m_vAlign; ///< vertical alignment
146
double m_height; ///< height of cell
147
unsigned int m_currentContext; ///< index of current context
148
wxArrayPtrVoid m_contexts; ///< list of contexts
149
unsigned int m_currentLine; ///< index of current line
150
bool m_aligned; ///< alignment flag
151
int m_fillStyle; ///< cell fill style
152
wxPdfArrayDouble m_linewidth; ///< list of line widths
153
wxArrayInt m_spaces; ///< list of space counters
154
wxChar m_lastChar; ///< last character of a chunk
155
double m_spaceWidth; ///< width of space character
156
wxString m_href; ///< hyper link reference
157
wxPdfTable* m_table; ///< table reference
160
/// Class representing table cells. (For internal use only)
161
class WXDLLIMPEXP_PDFDOC wxPdfTableCell
165
wxPdfTableCell(wxXmlNode* cell, unsigned int row, unsigned int col, unsigned int rows, unsigned int cols);
168
virtual ~wxPdfTableCell();
171
unsigned int GetRow() const { return m_row; }
173
/// Get column of cell
174
unsigned int GetCol() const { return m_col; }
176
/// Get row span of cell
177
unsigned int GetRowSpan() const { return m_rowSpan;};
179
/// Get column span of cell
180
unsigned int GetColSpan() const { return m_colSpan;};
182
/// Set width of cell
183
void SetWidth(double w) { m_width = w;};
185
/// Set height of cell
186
void SetHeight(double h) { m_height = h;};
188
/// Get height of cell
189
double GetHeight() const { return m_height;};
191
/// Get width of cell
192
double GetWidth() const { return m_width;};
195
void SetContext(wxPdfCellContext* context) { m_context = context; }
198
wxPdfCellContext* GetContext() { return m_context; }
200
/// Set horizontal alignment
201
void SetHAlign(wxPdfAlignment hAlign) { m_hAlign = hAlign; }
203
/// Get horizontal alignment
204
wxPdfAlignment GetHAlign() { return m_hAlign; }
206
/// Set vertical alignment
207
void SetVAlign(wxPdfAlignment vAlign) { m_vAlign = vAlign; }
209
/// Get vertical alignment
210
wxPdfAlignment GetVAlign() { return m_vAlign; }
213
void SetBorder(int border) { m_border = border; }
216
int GetBorder() { return m_border; }
218
/// Check whether cell has a coloured or transparent background
219
bool HasCellColour() const { return m_hasCellColour; };
221
/// Set background colour of cell
222
void SetCellColour(wxPdfColour colour) { m_hasCellColour = true; m_colourCell = colour;};
224
/// Get background colour of cell
225
wxPdfColour GetCellColour() const { return m_colourCell; };
227
/// Get root node of cell
228
wxXmlNode* GetXmlNode() { return m_cell; }
231
unsigned int m_row; ///< row index
232
unsigned int m_col; ///< column index
233
unsigned int m_rowSpan; ///< row span
234
unsigned int m_colSpan; ///< column span
236
wxPdfCellContext* m_context; ///< table cell context
237
wxXmlNode* m_cell; ///< xml root node of cell
238
wxPdfAlignment m_hAlign; ///< horizontal alignment
239
wxPdfAlignment m_vAlign; ///< vertical alignment
240
int m_border; ///< border
241
double m_width; ///< cell width
242
double m_height; ///< cell height
244
bool m_hasCellColour; ///< flag whether cell has background colour or is transparent
245
wxPdfColour m_colourCell; ///< cell background colour
248
/// Hashmap class for document links
249
WX_DECLARE_HASH_MAP_WITH_DECL(long, wxPdfTableCell*, wxIntegerHash, wxIntegerEqual, wxPdfCellHashMap, class WXDLLIMPEXP_PDFDOC);
251
/// Class representing tables within a cell. (For internal use only)
252
class WXDLLIMPEXP_PDFDOC wxPdfTable
256
wxPdfTable(wxPdfDocument* document);
259
virtual ~wxPdfTable();
261
/// Set minimal required row height
262
void SetMinRowHeight(int row, double height) { m_minHeights[row] = height; }
264
/// Set width of column
265
void SetColumnWidth(int col, double width);
267
/// Calculate cell dimensions respecting a maximal allowed width
268
void SetCellDimensions(double maxWidth);
270
/// Insert a cell into the cell array
271
void InsertCell(wxPdfTableCell* c);
273
/// Get height of row
274
double GetRowHeight(int row) { const double height = m_rowHeights[row]; return height; };
276
/// Write table to document
279
/// Write one table row to the document
280
void WriteRow(unsigned int row, double x, double y);
283
void SetPad(double pad) { m_pad = pad; }
286
double GetPad() { return m_pad; }
289
void SetBorder(bool border) { m_border = border; }
291
/// Check whether border should be drawn
292
bool HasBorder() { return m_border; }
294
/// Get total width of table
295
double GetTotalWidth() { return m_totalWidth; }
297
/// Get total height of table
298
double GetTotalHeight() { return m_totalHeight; }
300
/// Set index of first header row
301
void SetHeadRowFirst(unsigned int row) { m_headRowFirst = row; }
303
/// Set index of last header row
304
void SetHeadRowLast(unsigned int row) { m_headRowLast = row; }
306
/// Set index of first body row
307
void SetBodyRowFirst(unsigned int row) { m_bodyRowFirst = row; }
309
/// Set index of last body row
310
void SetBodyRowLast(unsigned int row) { m_bodyRowLast = row; }
313
wxPdfDocument* m_document; ///< document reference
314
wxPdfDoubleHashMap m_minHeights; ///< array of minimal row heights
315
wxPdfDoubleHashMap m_rowHeights; ///< array of row heights
316
wxPdfDoubleHashMap m_colWidths; ///< array of column widths
318
double m_maxWidth; ///< maximal allowed width
319
double m_totalWidth; ///< total width
320
double m_totalHeight; ///< total height
321
double m_headHeight; ///< total height of table header
323
unsigned int m_headRowFirst; ///< index of first header row
324
unsigned int m_headRowLast; ///< index of last header row
325
unsigned int m_bodyRowFirst; ///< index of first body row
326
unsigned int m_bodyRowLast; ///< index of last body row
328
unsigned int m_nRows; ///< number of rows
329
unsigned int m_nCols; ///< number of columns
330
wxPdfCellHashMap m_table; ///< array of table cells
331
double m_pad; ///< cell padding
332
bool m_border; ///< border flag