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 {
23 namespace tablegenerator {
25 class TableBorderInfo FS_FINAL : public Object{
26  public:
32  typedef enum _TableBorderStyle {
38 
39 
43  , line_width(0.0f)
44  , color(0xff000000)
45  , dash_phase(0.0f)
46  , dashes(FloatArray()) {}
47 
64  ,color(color)
66  ,dashes(dashes) {}
67 
73  TableBorderInfo(const TableBorderInfo& table_border_info)
74  : table_border_style(table_border_info.table_border_style)
75  , line_width(table_border_info.line_width)
76  , color(table_border_info.color)
77  , dash_phase(table_border_info.dash_phase)
78  , dashes(table_border_info.dashes) {}
79 
89  line_width = data.line_width;
90  color = data.color;
91  dash_phase = data.dash_phase;
92  dashes = data.dashes;
93  return *this;
94  }
95 
103  bool operator == (const TableBorderInfo& table_border_info) const {
104  if (dashes.GetSize() != table_border_info.dashes.GetSize()) return false;
105  for (int i = 0; i < dashes.GetSize(); i++)
106  if (dashes.GetAt(i) != table_border_info.dashes.GetAt(i)) return false;
107 
108  return (table_border_style == table_border_info.table_border_style &&
109  fabs(line_width- table_border_info.line_width) <= FLT_EPSILON &&
110  color == table_border_info.color &&
111  dash_phase == table_border_info.dash_phase);
112  }
113 
121  bool operator != (const TableBorderInfo& data) const {
122  return !((*this) == data);
123  }
124 
141  this->table_border_style = table_border_style;
142  this->line_width = line_width;
143  this->color = color;
144  this->dash_phase = dash_phase;
145  this->dashes = dashes;
146  }
147 
153 
158  float line_width;
159 
162 
167  float dash_phase;
168 
175 };
176 
177 class TableCellData;
182 
184 class TableCellData FS_FINAL : public Object{
185  public:
188  : cell_text_style(foxit::pdf::RichTextStyle())
189  , cell_text(L"")
190  , cell_margin(RectF()) {}
191 
200  TableCellData(const foxit::pdf::RichTextStyle& cell_text_style, const WString& cell_text, const foxit::common::Image& cell_image, const RectF& cell_margin)
201  :cell_text_style(cell_text_style)
202  ,cell_text(cell_text)
203  ,cell_image(cell_image)
204  ,cell_margin(cell_margin) {}
205 
212  : cell_text_style(data.cell_text_style)
213  , cell_text(data.cell_text)
214  , cell_image(data.cell_image)
215  , cell_margin(data.cell_margin) {}
216 
224  TableCellData &operator = (const TableCellData& data) {
225  cell_text_style = data.cell_text_style;
226  cell_text = data.cell_text;
227  cell_image = data.cell_image;
228  cell_margin = data.cell_margin;
229  return *this;
230  }
231 
239  bool operator == (const TableCellData& data) const {
240  return (cell_text_style == data.cell_text_style &&
241  cell_text == data.cell_text &&
242  cell_image == data.cell_image &&
243  cell_margin == data.cell_margin);
244  }
245 
253  bool operator != (const TableCellData& data) const {
254  return !((*this) == data);
255  }
256 
267  void Set(const foxit::pdf::RichTextStyle& cell_text_style, const WString& cell_text, const foxit::common::Image& cell_image, const RectF& cell_margin) {
268  this->cell_text_style = cell_text_style;
269  this->cell_text = cell_text;
270  this->cell_image = cell_image;
271  this->cell_margin = cell_margin;
272  }
273 
276 
284 
292 
300 };
301 
304 
307 
308 
309 class TableData FS_FINAL : public Object {
310  public:
312  TableData() : rect(RectF())
313  ,row_count(0)
314  ,col_count(0)
315  ,outside_border_left(TableBorderInfo())
316  ,outside_border_right(TableBorderInfo())
317  ,outside_border_top(TableBorderInfo())
318  ,outside_border_bottom(TableBorderInfo())
319  ,inside_border_row(TableBorderInfo())
320  ,inside_border_col(TableBorderInfo()) {
321  }
322 
339  TableData(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
340  TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
341  TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
342  :rect(rect)
343  ,row_count(row_count)
344  ,col_count(col_count)
345  ,outside_border_left(outside_border_left)
346  ,outside_border_right(outside_border_right)
347  ,outside_border_top(outside_border_top)
348  ,outside_border_bottom(outside_border_bottom)
349  ,inside_border_row(inside_border_row)
350  ,inside_border_col(inside_border_col)
351  ,merge_cells(merge_cells)
352  ,row_height_array(row_height_array)
353  ,col_width_array(col_width_array) {
354  }
355 
361  TableData(const TableData& data)
362  :rect(data.rect)
363  ,row_count(data.row_count)
364  ,col_count(data.col_count)
365  ,outside_border_left(data.outside_border_left)
366  ,outside_border_right(data.outside_border_right)
367  ,outside_border_top(data.outside_border_top)
368  ,outside_border_bottom(data.outside_border_bottom)
369  ,inside_border_row(data.inside_border_row)
370  ,inside_border_col(data.inside_border_col)
371  ,merge_cells(data.merge_cells)
372  ,row_height_array(data.row_height_array)
373  ,col_width_array(data.col_width_array) {
374  }
375 
383  bool operator == (const TableData& data) const {
384  if (merge_cells.GetSize() != data.merge_cells.GetSize()) return false;
385  for (size_t i = 0; i < merge_cells.GetSize(); i++)
386  if (merge_cells.GetAt(i) != data.merge_cells.GetAt(i)) return false;
387  if (row_height_array.GetSize() != data.row_height_array.GetSize()) return false;
388  for (int i = 0; i < row_height_array.GetSize(); i++)
389  if (fabs(row_height_array.GetAt(i) - data.row_height_array.GetAt(i)) > FLT_EPSILON) return false;
390  if (col_width_array.GetSize() != data.col_width_array.GetSize()) return false;
391  for (int i = 0; i < col_width_array.GetSize(); i++)
392  if (fabs(col_width_array.GetAt(i) - data.col_width_array.GetAt(i)) > FLT_EPSILON) return false;
393  return (rect == data.rect &&
394  row_count == data.row_count &&
395  col_count == data.col_count &&
396  outside_border_left == data.outside_border_left &&
397  outside_border_right == data.outside_border_right &&
398  outside_border_top == data.outside_border_top &&
399  outside_border_bottom == data.outside_border_bottom &&
400  inside_border_row == data.inside_border_row &&
401  inside_border_col == data.inside_border_col);
402  }
403 
411  bool operator != (const TableData& data) const {
412  return !((*this) == data);
413  }
414 
422  TableData &operator = (const TableData& data) {
423  rect = data.rect;
424  row_count = data.row_count;
425  col_count = data.col_count;
426  outside_border_left = data.outside_border_left;
427  outside_border_right = data.outside_border_right;
428  outside_border_top = data.outside_border_top;
429  outside_border_bottom = data.outside_border_bottom;
430  inside_border_row = data.inside_border_row;
431  inside_border_col = data.inside_border_col;
432  merge_cells = data.merge_cells;
433  row_height_array = data.row_height_array;
434  col_width_array = data.col_width_array;
435  return *this;
436  }
437 
456  void Set(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
457  TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
458  TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array) {
459  this->rect = rect;
460  this->row_count = row_count;
461  this->col_count = col_count;
462  this->outside_border_left = outside_border_left;
463  this->outside_border_right = outside_border_right;
464  this->outside_border_top = outside_border_top;
465  this->outside_border_bottom = outside_border_bottom;
466  this->inside_border_row = inside_border_row;
467  this->inside_border_col = inside_border_col;
468  this->merge_cells = merge_cells;
469  this->row_height_array = row_height_array;
470  this->col_width_array = col_width_array;
471  }
472 
478 
481 
484 
487 
490 
493 
496 
499 
502 
511 
514 
517 };
518 
526 class TableGenerator FS_FINAL : public Base{
527  public:
542  static bool AddTableToPage(const foxit::pdf::PDFPage& page, const TableData& data, const TableCellDataArray& cell_array);
543 
567  static bool InsertTablePagesToDocument(const foxit::pdf::PDFDoc& doc, int dest_page_index, float page_width, float page_height, const TableData& data, const TableCellDataArray& cell_array, bool allow_to_cross_page);
568 };
569 }
570 }
571 }
572 #endif
FloatArray col_width_array
The column width array. The column width will be set as default value automatically if the member of ...
Definition: fs_tablegenerator.h:516
TableCellData()
Constructor.
Definition: fs_tablegenerator.h:187
Definition: fs_annot.h:203
ARGB color
The table border color. Format: 0xAARRGGBB.
Definition: fs_tablegenerator.h:161
CFX_Object Object
Object type.
Definition: fs_basictypes.h:217
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:174
TableData(const TableData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:361
Definition: fs_tablegenerator.h:184
TableBorderInfo outside_border_right
The right outside border info.
Definition: fs_tablegenerator.h:489
TableData()
Constructor.
Definition: fs_tablegenerator.h:312
Definition: fx_coordinates.h:30
int GetSize() const
Get the number of elements in the array.
Definition: fx_basic.h:1360
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:158
void Set(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
Set value.
Definition: fs_tablegenerator.h:140
foxit::common::Image cell_image
The image content of cell.
Definition: fs_tablegenerator.h:291
WIDE STRING CLASS.
Definition: fx_string.h:1452
bool operator !=(const TableBorderInfo &data) const
Not equal operator.
Definition: fs_tablegenerator.h:121
TableBorderInfo(const TableBorderInfo &table_border_info)
Constructor, with another table border information object.
Definition: fs_tablegenerator.h:73
foxit::pdf::RichTextStyle cell_text_style
The style of cell text.
Definition: fs_tablegenerator.h:275
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:456
Definition: fs_pdfdoc.h:613
int col_count
The count of columns in the table.
Definition: fs_tablegenerator.h:483
float dash_phase
Dash phase.It should not be negative. Only useful when parameter style</ i> is TableBorderInfo::e_Tab...
Definition: fs_tablegenerator.h:167
TableBorderInfo outside_border_top
The top outside border info.
Definition: fs_tablegenerator.h:492
Definition: fs_tablegenerator.h:181
TableBorderStyle table_border_style
Table border style. Please refer to values starting from TableBorderInfo::e_TableBorderStyleSolid and...
Definition: fs_tablegenerator.h:152
Definition: fs_tablegenerator.h:25
bool operator==(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are equal.
Definition: fs_basictypes.h:128
bool operator==(const TableBorderInfo &table_border_info) const
Equal operator.
Definition: fs_tablegenerator.h:103
WString cell_text
The text content of cell.
Definition: fs_tablegenerator.h:283
uint32 ARGB
ARGB color type, 32 bits, ((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:210
TableBorderInfo outside_border_bottom
The bottom outside border info.
Definition: fs_tablegenerator.h:495
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:510
Header file for annotation related definitions and classes.
TableBorderInfo inside_border_row
The row inside border info.
Definition: fs_tablegenerator.h:498
Definition: fs_tablegenerator.h:309
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:200
const TYPE GetAt(int nIndex) const
This method retrieves an element specified by an index number.
Definition: fx_basic.h:1396
TableBorderInfo & operator=(const TableBorderInfo &data)
Assign operator.
Definition: fs_tablegenerator.h:87
An array of table cell index.
Definition: fs_tablegenerator.h:306
static bool AddTableToPage(const foxit::pdf::PDFPage &page, const TableData &data, const TableCellDataArray &cell_array)
Add a new table to the PDF page.
Definition: fs_pdfpage.h:411
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:339
Header file for common definitions and classes.
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:303
TableBorderStyle
Enumeration for PDF annotation type.
Definition: fs_tablegenerator.h:32
Definition: fs_tablegenerator.h:526
TableBorderInfo outside_border_left
The left outside border info.
Definition: fs_tablegenerator.h:486
Table border style: Dashed.
Definition: fs_tablegenerator.h:36
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:513
RectF cell_margin
The cell margin between the content and cell border.
Definition: fs_tablegenerator.h:299
Definition: fs_basictypes.h:419
int row_count
The count of rows in the table.
Definition: fs_tablegenerator.h:480
size_t GetSize() const
Get the size of elements in current array.
TableCellData(const TableCellData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:211
Header file for PDF page related definitions and classes.
TableBorderInfo()
Constructor.
Definition: fs_tablegenerator.h:41
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:267
Foxit namespace.
Definition: fs_taggedpdf.h:27
TableCellIndex GetAt(size_t index) const
Retrieve a copy of the element at position specified by index in current array.
Table border style: Solid.
Definition: fs_tablegenerator.h:34
static bool InsertTablePagesToDocument(const foxit::pdf::PDFDoc &doc, int dest_page_index, float page_width, float page_height, const TableData &data, const TableCellDataArray &cell_array, bool allow_to_cross_page)
Insert a new table which is contained in one or multi pages into the document.
TableBorderInfo inside_border_col
The column inside border info.
Definition: fs_tablegenerator.h:501
TableBorderInfo(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
Constructor, with parameters.
Definition: fs_tablegenerator.h:61
This class represents an array of TableCellData objects,inserted in the order of the displayed table ...
Definition: fs_tablegenerator.h:179
RectF rect
Rectangle of the table which specifies the position in PDF page. It should be in PDF coordinate syste...
Definition: fs_tablegenerator.h:477
Definition: fs_image.h:448
Definition: fx_coordinates.h:771