Foxit PDF SDK
fs_tablegenerator.h
1 #ifndef FS_TABLEGENERATOR_H_
2 #define FS_TABLEGENERATOR_H_
3 
4 #include "common/fs_common.h"
5 #include "pdf/fs_pdfpage.h"
6 #ifndef __EMSCRIPTEN_RENDER__
7 #include "pdf/annots/fs_annot.h"
8 #endif
9 
15 namespace foxit {
19 namespace addon {
21 class TableBorderInfo FS_FINAL : public Object{
22  public:
28  typedef enum _TableBorderStyle {
34 
35 
39  , line_width(0.0f)
40  , color(0xff000000)
41  , dash_phase(0.0f)
42  , dashes(FloatArray()) {}
43 
60  ,color(color)
62  ,dashes(dashes) {}
63 
69  TableBorderInfo(const TableBorderInfo& table_border_info)
70  : table_border_style(table_border_info.table_border_style)
71  , line_width(table_border_info.line_width)
72  , color(table_border_info.color)
73  , dash_phase(table_border_info.dash_phase)
74  , dashes(table_border_info.dashes) {}
75 
85  line_width = data.line_width;
86  color = data.color;
87  dash_phase = data.dash_phase;
88  dashes = data.dashes;
89  return *this;
90  }
91 
99  bool operator == (const TableBorderInfo& table_border_info) const {
100  if (dashes.GetSize() != table_border_info.dashes.GetSize()) return false;
101  for (int i = 0; i < dashes.GetSize(); i++)
102  if (dashes.GetAt(i) != table_border_info.dashes.GetAt(i)) return false;
103 
104  return (table_border_style == table_border_info.table_border_style &&
105  fabs(line_width- table_border_info.line_width) <= FLT_EPSILON &&
106  color == table_border_info.color &&
107  dash_phase == table_border_info.dash_phase);
108  }
109 
117  bool operator != (const TableBorderInfo& data) const {
118  return !((*this) == data);
119  }
120 
137  this->table_border_style = table_border_style;
138  this->line_width = line_width;
139  this->color = color;
140  this->dash_phase = dash_phase;
141  this->dashes = dashes;
142  }
143 
149 
154  float line_width;
155 
158 
163  float dash_phase;
164 
171 };
172 
173 class TableCellData;
178 
180 class TableCellData FS_FINAL : public Object{
181  public:
184  : cell_text_style(foxit::pdf::RichTextStyle())
185  , cell_text(L"")
186  , cell_margin(RectF()) {}
187 
196  TableCellData(const foxit::pdf::RichTextStyle& cell_text_style, const WString& cell_text, const foxit::common::Image& cell_image, const RectF& cell_margin)
197  :cell_text_style(cell_text_style)
198  ,cell_text(cell_text)
199  ,cell_image(cell_image)
200  ,cell_margin(cell_margin) {}
201 
208  : cell_text_style(data.cell_text_style)
209  , cell_text(data.cell_text)
210  , cell_image(data.cell_image)
211  , cell_margin(data.cell_margin) {}
212 
220  TableCellData &operator = (const TableCellData& data) {
221  cell_text_style = data.cell_text_style;
222  cell_text = data.cell_text;
223  cell_image = data.cell_image;
224  cell_margin = data.cell_margin;
225  return *this;
226  }
227 
235  bool operator == (const TableCellData& data) const {
236  return (cell_text_style == data.cell_text_style &&
237  cell_text == data.cell_text &&
238  cell_image == data.cell_image &&
239  cell_margin == data.cell_margin);
240  }
241 
249  bool operator != (const TableCellData& data) const {
250  return !((*this) == data);
251  }
252 
263  void Set(const foxit::pdf::RichTextStyle& cell_text_style, const WString& cell_text, const foxit::common::Image& cell_image, const RectF& cell_margin) {
264  this->cell_text_style = cell_text_style;
265  this->cell_text = cell_text;
266  this->cell_image = cell_image;
267  this->cell_margin = cell_margin;
268  }
269 
272 
280 
288 
296 };
297 
300 
303 
304 
305 class TableData FS_FINAL : public Object {
306  public:
308  TableData() : rect(RectF())
309  ,row_count(0)
310  ,col_count(0)
311  ,outside_border_left(TableBorderInfo())
312  ,outside_border_right(TableBorderInfo())
313  ,outside_border_top(TableBorderInfo())
314  ,outside_border_bottom(TableBorderInfo())
315  ,inside_border_row(TableBorderInfo())
316  ,inside_border_col(TableBorderInfo()) {
317  }
318 
335  TableData(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
336  TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
337  TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
338  :rect(rect)
339  ,row_count(row_count)
340  ,col_count(col_count)
341  ,outside_border_left(outside_border_left)
342  ,outside_border_right(outside_border_right)
343  ,outside_border_top(outside_border_top)
344  ,outside_border_bottom(outside_border_bottom)
345  ,inside_border_row(inside_border_row)
346  ,inside_border_col(inside_border_col)
347  ,merge_cells(merge_cells)
348  ,row_height_array(row_height_array)
349  ,col_width_array(col_width_array) {
350  }
351 
357  TableData(const TableData& data)
358  :rect(data.rect)
359  ,row_count(data.row_count)
360  ,col_count(data.col_count)
361  ,outside_border_left(data.outside_border_left)
362  ,outside_border_right(data.outside_border_right)
363  ,outside_border_top(data.outside_border_top)
364  ,outside_border_bottom(data.outside_border_bottom)
365  ,inside_border_row(data.inside_border_row)
366  ,inside_border_col(data.inside_border_col)
367  ,merge_cells(data.merge_cells)
368  ,row_height_array(data.row_height_array)
369  ,col_width_array(data.col_width_array) {
370  }
371 
379  bool operator == (const TableData& data) const {
380  if (merge_cells.GetSize() != data.merge_cells.GetSize()) return false;
381  for (size_t i = 0; i < merge_cells.GetSize(); i++)
382  if (merge_cells.GetAt(i) != data.merge_cells.GetAt(i)) return false;
383  if (row_height_array.GetSize() != data.row_height_array.GetSize()) return false;
384  for (int i = 0; i < row_height_array.GetSize(); i++)
385  if (fabs(row_height_array.GetAt(i) - data.row_height_array.GetAt(i)) > FLT_EPSILON) return false;
386  if (col_width_array.GetSize() != data.col_width_array.GetSize()) return false;
387  for (int i = 0; i < col_width_array.GetSize(); i++)
388  if (fabs(col_width_array.GetAt(i) - data.col_width_array.GetAt(i)) > FLT_EPSILON) return false;
389  return (rect == data.rect &&
390  row_count == data.row_count &&
391  col_count == data.col_count &&
392  outside_border_left == data.outside_border_left &&
393  outside_border_right == data.outside_border_right &&
394  outside_border_top == data.outside_border_top &&
395  outside_border_bottom == data.outside_border_bottom &&
396  inside_border_row == data.inside_border_row &&
397  inside_border_col == data.inside_border_col);
398  }
399 
407  bool operator != (const TableData& data) const {
408  return !((*this) == data);
409  }
410 
418  TableData &operator = (const TableData& data) {
419  rect = data.rect;
420  row_count = data.row_count;
421  col_count = data.col_count;
422  outside_border_left = data.outside_border_left;
423  outside_border_right = data.outside_border_right;
424  outside_border_top = data.outside_border_top;
425  outside_border_bottom = data.outside_border_bottom;
426  inside_border_row = data.inside_border_row;
427  inside_border_col = data.inside_border_col;
428  merge_cells = data.merge_cells;
429  row_height_array = data.row_height_array;
430  col_width_array = data.col_width_array;
431  return *this;
432  }
433 
452  void Set(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
453  TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
454  TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array) {
455  this->rect = rect;
456  this->row_count = row_count;
457  this->col_count = col_count;
458  this->outside_border_left = outside_border_left;
459  this->outside_border_right = outside_border_right;
460  this->outside_border_top = outside_border_top;
461  this->outside_border_bottom = outside_border_bottom;
462  this->inside_border_row = inside_border_row;
463  this->inside_border_col = inside_border_col;
464  this->merge_cells = merge_cells;
465  this->row_height_array = row_height_array;
466  this->col_width_array = col_width_array;
467  }
468 
474 
477 
480 
483 
486 
489 
492 
495 
498 
507 
510 
513 };
514 
518 class TableGenerator FS_FINAL : public Base{
519  public:
534  static bool AddTableToPage(const foxit::pdf::PDFPage& page, const TableData& data, const TableCellDataArray& cell_array);
535 };
536 }
537 }
538 #endif
bool operator==(const TableBorderInfo &table_border_info) const
Equal operator.
Definition: fs_tablegenerator.h:99
TableData(const TableData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:357
Definition: fs_annot.h:202
TableBorderInfo outside_border_right
The right outside border info.
Definition: fs_tablegenerator.h:485
TableCellIndexArray merge_cells
The merge cells. The length of this array must be even and the zero length means no merge cell.
Definition: fs_tablegenerator.h:506
TableCellIndex GetAt(size_t index) const
Retrieve a copy of the element at position specified by index in current array.
CFX_Object Object
Object type.
Definition: fs_basictypes.h:217
TableCellData(const TableCellData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:207
float line_width
Table border line width, in points. This should be a non-negative value. If this value is 0,...
Definition: fs_tablegenerator.h:154
Definition: fs_tablegenerator.h:180
void Set(const foxit::pdf::RichTextStyle &cell_text_style, const WString &cell_text, const foxit::common::Image &cell_image, const RectF &cell_margin)
Set value.
Definition: fs_tablegenerator.h:263
static bool AddTableToPage(const foxit::pdf::PDFPage &page, const TableData &data, const TableCellDataArray &cell_array)
Add a table to the PDF page.
int row_count
The count of rows in the table.
Definition: fs_tablegenerator.h:476
RectF cell_margin
The cell margin between the content and cell border.
Definition: fs_tablegenerator.h:295
Definition: fx_coordinates.h:30
TableCellData()
Constructor.
Definition: fs_tablegenerator.h:183
TableBorderInfo(const TableBorderInfo &table_border_info)
Constructor, with another table border information object.
Definition: fs_tablegenerator.h:69
TableBorderInfo(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
Constructor, with parameters.
Definition: fs_tablegenerator.h:57
int GetSize() const
Get the number of elements in the array.
Definition: fx_basic.h:1360
TableBorderInfo inside_border_col
The column inside border info.
Definition: fs_tablegenerator.h:497
WIDE STRING CLASS.
Definition: fx_string.h:1452
Table border style: Dashed.
Definition: fs_tablegenerator.h:32
Table border style: Solid.
Definition: fs_tablegenerator.h:30
Definition: fs_tablegenerator.h:21
TableBorderInfo outside_border_bottom
The bottom outside border info.
Definition: fs_tablegenerator.h:491
bool operator==(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are equal.
Definition: fs_basictypes.h:128
foxit::common::Image cell_image
The image content of cell.
Definition: fs_tablegenerator.h:287
TableData()
Constructor.
Definition: fs_tablegenerator.h:308
TableBorderStyle table_border_style
Table border style. Please refer to values starting from TableBorderInfo::e_TableBorderStyleSolid and...
Definition: fs_tablegenerator.h:148
size_t GetSize() const
Get the size of elements in current array.
TableBorderInfo & operator=(const TableBorderInfo &data)
Assign operator.
Definition: fs_tablegenerator.h:83
uint32 ARGB
ARGB color type, 32 bits, ((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:210
FloatArray dashes
A dash array that represents the dash patterns. The value of each element in this array should not be...
Definition: fs_tablegenerator.h:170
CFX_Point TableCellIndex
The table cell index.The x means the row index of cell and the y means the column index of cell.
Definition: fs_tablegenerator.h:299
Header file for annotation related definitions and classes.
Definition: fs_tablegenerator.h:177
int col_count
The count of columns in the table.
Definition: fs_tablegenerator.h:479
FloatArray row_height_array
The row height array. The row height will be set as default value automatically if the member of arra...
Definition: fs_tablegenerator.h:509
const TYPE GetAt(int nIndex) const
This method retrieves an element specified by an index number.
Definition: fx_basic.h:1396
WString cell_text
The text content of cell.
Definition: fs_tablegenerator.h:279
TableCellData(const foxit::pdf::RichTextStyle &cell_text_style, const WString &cell_text, const foxit::common::Image &cell_image, const RectF &cell_margin)
Constructor, with parameters.
Definition: fs_tablegenerator.h:196
Definition: fs_pdfpage.h:411
ARGB color
The table border color. Format: 0xAARRGGBB.
Definition: fs_tablegenerator.h:157
void Set(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left, TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom, TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
Set value.
Definition: fs_tablegenerator.h:452
Header file for common definitions and classes.
TableBorderInfo outside_border_left
The left outside border info.
Definition: fs_tablegenerator.h:482
Definition: fs_tablegenerator.h:305
This class represents an array of TableCellData objects,inserted in the order of the displayed table ...
Definition: fs_tablegenerator.h:175
Definition: fs_basictypes.h:407
Header file for PDF page related definitions and classes.
An array of table cell index.
Definition: fs_tablegenerator.h:302
float dash_phase
Dash phase.It should not be negative. Only useful when parameter style</ i> is TableBorderInfo::e_Tab...
Definition: fs_tablegenerator.h:163
Foxit namespace.
Definition: fs_taggedpdf.h:27
TableBorderInfo outside_border_top
The top outside border info.
Definition: fs_tablegenerator.h:488
TableBorderInfo inside_border_row
The row inside border info.
Definition: fs_tablegenerator.h:494
void Set(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
Set value.
Definition: fs_tablegenerator.h:136
RectF rect
Rectangle of the table which specifies the position in PDF page. It should be in PDF coordinate syste...
Definition: fs_tablegenerator.h:473
bool operator !=(const TableBorderInfo &data) const
Not equal operator.
Definition: fs_tablegenerator.h:117
Definition: fs_image.h:445
Definition: fs_tablegenerator.h:518
foxit::pdf::RichTextStyle cell_text_style
The style of cell text.
Definition: fs_tablegenerator.h:271
Definition: fx_coordinates.h:771
TableData(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left, TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom, TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
Constructor, with parameters.
Definition: fs_tablegenerator.h:335
TableBorderInfo()
Constructor.
Definition: fs_tablegenerator.h:37
FloatArray col_width_array
The col width array. The col width will be set as default value automatically if the member of array ...
Definition: fs_tablegenerator.h:512
TableBorderStyle
Enumeration for PDF annotation type.
Definition: fs_tablegenerator.h:28