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_fill_color(0xFFFFFFFF)
190  , cell_text(L"")
191  , cell_margin(RectF()) {}
192 
202  TableCellData(const foxit::pdf::RichTextStyle& cell_text_style, const ARGB cell_fill_color, const WString& cell_text, const foxit::common::Image& cell_image, const RectF& cell_margin)
203  :cell_text_style(cell_text_style)
204  ,cell_fill_color(cell_fill_color)
205  ,cell_text(cell_text)
206  ,cell_image(cell_image)
207  ,cell_margin(cell_margin) {}
208 
215  : cell_text_style(data.cell_text_style)
216  , cell_fill_color(data.cell_fill_color)
217  , cell_text(data.cell_text)
218  , cell_image(data.cell_image)
219  , cell_margin(data.cell_margin) {}
220 
228  TableCellData &operator = (const TableCellData& data) {
229  cell_text_style = data.cell_text_style;
230  cell_fill_color = data.cell_fill_color;
231  cell_text = data.cell_text;
232  cell_image = data.cell_image;
233  cell_margin = data.cell_margin;
234  return *this;
235  }
236 
244  bool operator == (const TableCellData& data) const {
245  return (cell_text_style == data.cell_text_style &&
246  cell_fill_color == data.cell_fill_color &&
247  cell_text == data.cell_text &&
248  cell_image == data.cell_image &&
249  cell_margin == data.cell_margin);
250  }
251 
259  bool operator != (const TableCellData& data) const {
260  return !((*this) == data);
261  }
262 
274  void Set(const foxit::pdf::RichTextStyle& cell_text_style, const ARGB cell_fill_color, const WString& cell_text, const foxit::common::Image& cell_image, const RectF& cell_margin) {
275  this->cell_text_style = cell_text_style;
276  this->cell_fill_color = cell_fill_color;
277  this->cell_text = cell_text;
278  this->cell_image = cell_image;
279  this->cell_margin = cell_margin;
280  }
281 
284 
287 
295 
303 
311 };
312 
315 
318 
319 
320 class TableData FS_FINAL : public Object {
321  public:
323  TableData() : rect(RectF())
324  ,row_count(0)
325  ,col_count(0)
326  ,outside_border_left(TableBorderInfo())
327  ,outside_border_right(TableBorderInfo())
328  ,outside_border_top(TableBorderInfo())
329  ,outside_border_bottom(TableBorderInfo())
330  ,inside_border_row(TableBorderInfo())
331  ,inside_border_col(TableBorderInfo()) {
332  }
333 
350  TableData(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
351  TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
352  TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
353  :rect(rect)
354  ,row_count(row_count)
355  ,col_count(col_count)
356  ,outside_border_left(outside_border_left)
357  ,outside_border_right(outside_border_right)
358  ,outside_border_top(outside_border_top)
359  ,outside_border_bottom(outside_border_bottom)
360  ,inside_border_row(inside_border_row)
361  ,inside_border_col(inside_border_col)
362  ,merge_cells(merge_cells)
363  ,row_height_array(row_height_array)
364  ,col_width_array(col_width_array) {
365  }
366 
372  TableData(const TableData& data)
373  :rect(data.rect)
374  ,row_count(data.row_count)
375  ,col_count(data.col_count)
376  ,outside_border_left(data.outside_border_left)
377  ,outside_border_right(data.outside_border_right)
378  ,outside_border_top(data.outside_border_top)
379  ,outside_border_bottom(data.outside_border_bottom)
380  ,inside_border_row(data.inside_border_row)
381  ,inside_border_col(data.inside_border_col)
382  ,merge_cells(data.merge_cells)
383  ,row_height_array(data.row_height_array)
384  ,col_width_array(data.col_width_array) {
385  }
386 
394  bool operator == (const TableData& data) const {
395  if (merge_cells.GetSize() != data.merge_cells.GetSize()) return false;
396  for (size_t i = 0; i < merge_cells.GetSize(); i++)
397  if (merge_cells.GetAt(i) != data.merge_cells.GetAt(i)) return false;
398  if (row_height_array.GetSize() != data.row_height_array.GetSize()) return false;
399  for (int i = 0; i < row_height_array.GetSize(); i++)
400  if (fabs(row_height_array.GetAt(i) - data.row_height_array.GetAt(i)) > FLT_EPSILON) return false;
401  if (col_width_array.GetSize() != data.col_width_array.GetSize()) return false;
402  for (int i = 0; i < col_width_array.GetSize(); i++)
403  if (fabs(col_width_array.GetAt(i) - data.col_width_array.GetAt(i)) > FLT_EPSILON) return false;
404  return (rect == data.rect &&
405  row_count == data.row_count &&
406  col_count == data.col_count &&
407  outside_border_left == data.outside_border_left &&
408  outside_border_right == data.outside_border_right &&
409  outside_border_top == data.outside_border_top &&
410  outside_border_bottom == data.outside_border_bottom &&
411  inside_border_row == data.inside_border_row &&
412  inside_border_col == data.inside_border_col);
413  }
414 
422  bool operator != (const TableData& data) const {
423  return !((*this) == data);
424  }
425 
433  TableData &operator = (const TableData& data) {
434  rect = data.rect;
435  row_count = data.row_count;
436  col_count = data.col_count;
437  outside_border_left = data.outside_border_left;
438  outside_border_right = data.outside_border_right;
439  outside_border_top = data.outside_border_top;
440  outside_border_bottom = data.outside_border_bottom;
441  inside_border_row = data.inside_border_row;
442  inside_border_col = data.inside_border_col;
443  merge_cells = data.merge_cells;
444  row_height_array = data.row_height_array;
445  col_width_array = data.col_width_array;
446  return *this;
447  }
448 
467  void Set(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
468  TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
469  TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array) {
470  this->rect = rect;
471  this->row_count = row_count;
472  this->col_count = col_count;
473  this->outside_border_left = outside_border_left;
474  this->outside_border_right = outside_border_right;
475  this->outside_border_top = outside_border_top;
476  this->outside_border_bottom = outside_border_bottom;
477  this->inside_border_row = inside_border_row;
478  this->inside_border_col = inside_border_col;
479  this->merge_cells = merge_cells;
480  this->row_height_array = row_height_array;
481  this->col_width_array = col_width_array;
482  }
483 
489 
492 
495 
498 
501 
504 
507 
510 
513 
522 
525 
528 };
529 
535  public:
541  virtual void Release() = 0;
542 
550  virtual float GetTableTopMarginToPage(int page_index) = 0;
551 };
552 
560 class TableGenerator FS_FINAL : public Base{
561  public:
576  static bool AddTableToPage(const foxit::pdf::PDFPage& page, const TableData& data, const TableCellDataArray& cell_array);
577 
603  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, TableGeneratorCallback* tablegenerator_callback = NULL);
604 };
605 }
606 }
607 }
608 #endif
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo(const TableBorderInfo &table_border_info)
Constructor, with another table border information object.
Definition: fs_tablegenerator.h:73
CFX_ArrayTemplate::GetSize
int GetSize() const
Get the number of elements in the array.
Definition: fx_basic.h:1360
foxit::addon::tablegenerator::TableData::col_width_array
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:527
foxit::addon::tablegenerator::TableGenerator::AddTableToPage
static bool AddTableToPage(const foxit::pdf::PDFPage &page, const TableData &data, const TableCellDataArray &cell_array)
Add a new table to the PDF page.
foxit::addon::tablegenerator::TableData
Definition: fs_tablegenerator.h:320
foxit::addon::tablegenerator::TableCellData::cell_text_style
foxit::pdf::RichTextStyle cell_text_style
The style of cell text.
Definition: fs_tablegenerator.h:283
foxit::Object
CFX_Object Object
Object type.
Definition: fs_basictypes.h:221
foxit::addon::tablegenerator::TableCellIndex
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:314
foxit::addon::tablegenerator::TableData::TableData
TableData(const TableData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:372
foxit::addon::tablegenerator::TableCellData::TableCellData
TableCellData(const foxit::pdf::RichTextStyle &cell_text_style, const ARGB cell_fill_color, const WString &cell_text, const foxit::common::Image &cell_image, const RectF &cell_margin)
Constructor, with parameters.
Definition: fs_tablegenerator.h:202
foxit::addon::tablegenerator::TableData::outside_border_right
TableBorderInfo outside_border_right
The right outside border info.
Definition: fs_tablegenerator.h:500
fs_common.h
Header file for common definitions and classes.
foxit::addon::tablegenerator::TableBorderInfo::dash_phase
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
foxit::addon::tablegenerator::TableData::TableData
TableData()
Constructor.
Definition: fs_tablegenerator.h:323
foxit::addon::tablegenerator::TableBorderInfo::e_TableBorderStyleDashed
Table border style: Dashed.
Definition: fs_tablegenerator.h:36
CFX_ArrayTemplate< float >
foxit::addon::tablegenerator::TableBorderInfo::e_TableBorderStyleSolid
Table border style: Solid.
Definition: fs_tablegenerator.h:34
foxit::addon::tablegenerator::TableBorderInfo::color
ARGB color
The table border color. Format: 0xAARRGGBB.
Definition: fs_tablegenerator.h:161
foxit::addon::tablegenerator::TableCellIndexArray
An array of table cell index.
Definition: fs_tablegenerator.h:317
foxit::ARGB
uint32 ARGB
ARGB color type, 32 bits, ((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:210
foxit::addon::tablegenerator::TableGeneratorCallback::GetTableTopMarginToPage
virtual float GetTableTopMarginToPage(int page_index)=0
A callback function to get the top margin of the table to be generated to a new page.
foxit::addon::tablegenerator::TableGenerator::InsertTablePagesToDocument
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, TableGeneratorCallback *tablegenerator_callback=0)
Insert a new table which is contained in one or multi pages into the document.
foxit::addon::tablegenerator::TableBorderInfo::dashes
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
foxit::addon::tablegenerator::TableCellData
Definition: fs_tablegenerator.h:184
foxit::addon::tablegenerator::TableBorderInfo::line_width
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
foxit::addon::tablegenerator::TableData::Set
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:467
foxit::addon::tablegenerator::TableData::col_count
int col_count
The count of columns in the table.
Definition: fs_tablegenerator.h:494
foxit::addon::tablegenerator::TableBorderInfo::operator=
TableBorderInfo & operator=(const TableBorderInfo &data)
Assign operator.
Definition: fs_tablegenerator.h:87
foxit::addon::tablegenerator::TableCellData::Set
void Set(const foxit::pdf::RichTextStyle &cell_text_style, const ARGB cell_fill_color, const WString &cell_text, const foxit::common::Image &cell_image, const RectF &cell_margin)
Set value.
Definition: fs_tablegenerator.h:274
foxit::addon::tablegenerator::TableData::outside_border_bottom
TableBorderInfo outside_border_bottom
The bottom outside border info.
Definition: fs_tablegenerator.h:506
foxit::pdf::RichTextStyle
Definition: fs_annot.h:203
foxit::addon::tablegenerator::TableData::outside_border_top
TableBorderInfo outside_border_top
The top outside border info.
Definition: fs_tablegenerator.h:503
foxit::addon::tablegenerator::TableCellDataColArray
This class represents an array of TableCellData objects,inserted in the order of the displayed table ...
Definition: fs_tablegenerator.h:179
foxit::addon::tablegenerator::TableCellData::TableCellData
TableCellData()
Constructor.
Definition: fs_tablegenerator.h:187
CFX_PSVTemplate
Definition: fx_coordinates.h:30
CFX_ArrayTemplate::GetAt
const TYPE GetAt(int nIndex) const
This method retrieves an element specified by an index number.
Definition: fx_basic.h:1396
foxit::addon::tablegenerator::TableData::merge_cells
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:521
foxit::addon::tablegenerator::TableCellData::cell_margin
RectF cell_margin
The cell margin between the content and cell border.
Definition: fs_tablegenerator.h:310
foxit::addon::tablegenerator::TableBorderInfo::table_border_style
TableBorderStyle table_border_style
Table border style. Please refer to values starting from TableBorderInfo::e_TableBorderStyleSolid and...
Definition: fs_tablegenerator.h:152
foxit::addon::tablegenerator::TableBorderInfo::TableBorderStyle
TableBorderStyle
Enumeration for PDF annotation type.
Definition: fs_tablegenerator.h:32
operator==
bool operator==(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are equal.
Definition: fs_basictypes.h:128
foxit::addon::tablegenerator::TableCellData::TableCellData
TableCellData(const TableCellData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:214
fs_pdfpage.h
Header file for PDF page related definitions and classes.
foxit::addon::tablegenerator::TableCellDataArray
Definition: fs_tablegenerator.h:181
foxit
Foxit namespace.
Definition: fs_taggedpdf.h:27
foxit::addon::tablegenerator::TableData::inside_border_row
TableBorderInfo inside_border_row
The row inside border info.
Definition: fs_tablegenerator.h:509
foxit::addon::tablegenerator::TableBorderInfo
Definition: fs_tablegenerator.h:25
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
Constructor, with parameters.
Definition: fs_tablegenerator.h:61
foxit::addon::tablegenerator::TableData::row_height_array
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:524
foxit::addon::tablegenerator::TableBorderInfo::operator==
bool operator==(const TableBorderInfo &table_border_info) const
Equal operator.
Definition: fs_tablegenerator.h:103
operator!=
bool operator!=(const char *str1, const CFX_ByteString &str2)
Check if two byte strings are not equal.
Definition: fs_basictypes.h:140
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo()
Constructor.
Definition: fs_tablegenerator.h:41
foxit::addon::tablegenerator::TableBorderInfo::operator!=
bool operator!=(const TableBorderInfo &data) const
Not equal operator.
Definition: fs_tablegenerator.h:121
foxit::addon::tablegenerator::TableData::TableData
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:350
foxit::addon::tablegenerator::TableCellData::cell_image
foxit::common::Image cell_image
The image content of cell.
Definition: fs_tablegenerator.h:302
NULL
#define NULL
The null-pointer value.
Definition: fx_system.h:780
foxit::addon::tablegenerator::TableData::outside_border_left
TableBorderInfo outside_border_left
The left outside border info.
Definition: fs_tablegenerator.h:497
CFX_FloatRect
Definition: fx_coordinates.h:771
foxit::addon::tablegenerator::TableCellIndexArray::GetAt
TableCellIndex GetAt(size_t index) const
Retrieve a copy of the element at position specified by index in current array.
foxit::addon::tablegenerator::TableData::row_count
int row_count
The count of rows in the table.
Definition: fs_tablegenerator.h:491
foxit::pdf::PDFDoc
Definition: fs_pdfdoc.h:610
foxit::pdf::PDFPage
Definition: fs_pdfpage.h:412
foxit::addon::tablegenerator::TableCellIndexArray::GetSize
size_t GetSize() const
Get the size of elements in current array.
foxit::addon::tablegenerator::TableGeneratorCallback::Release
virtual void Release()=0
A callback function used to release current callback object itself.
foxit::common::Image
Definition: fs_image.h:448
foxit::addon::tablegenerator::TableGeneratorCallback
Definition: fs_tablegenerator.h:534
foxit::addon::tablegenerator::TableGenerator
Definition: fs_tablegenerator.h:560
foxit::addon::tablegenerator::TableCellData::cell_fill_color
ARGB cell_fill_color
The fill color of cell. Format: 0xAARRGGBB.
Definition: fs_tablegenerator.h:286
fs_annot.h
Header file for annotation related definitions and classes.
foxit::addon::tablegenerator::TableData::inside_border_col
TableBorderInfo inside_border_col
The column inside border info.
Definition: fs_tablegenerator.h:512
CFX_WideString
WIDE STRING CLASS.
Definition: fx_string.h:1452
foxit::Base
Definition: fs_basictypes.h:427
foxit::addon::tablegenerator::TableBorderInfo::Set
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::addon::tablegenerator::TableCellData::cell_text
WString cell_text
The text content of cell.
Definition: fs_tablegenerator.h:294
foxit::addon::tablegenerator::TableData::rect
RectF rect
Rectangle of the table which specifies the position in PDF page. It should be in PDF coordinate syste...
Definition: fs_tablegenerator.h:488