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_pdfdoc.h"
6 #include "pdf/fs_pdfpage.h"
7 #ifndef __EMSCRIPTEN_RENDER__
8 #include "pdf/annots/fs_annot.h"
9 #endif
10
16 namespace foxit {
20 namespace addon {
24 namespace tablegenerator {
26 class TableBorderInfo FS_FINAL : public Object{
27 public:
33 typedef enum _TableBorderStyle {
35 e_TableBorderStyleSolid = 0,
37 e_TableBorderStyleDashed = 1
38 } TableBorderStyle;
39
40
42 TableBorderInfo()
43 : table_border_style(e_TableBorderStyleSolid)
44 , line_width(0.0f)
45 , color(0xff000000)
46 , dash_phase(0.0f)
47 , dashes(FloatArray()) {}
48
62 TableBorderInfo(const TableBorderStyle& table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
63 :table_border_style(table_border_style)
64 ,line_width(line_width)
65 ,color(color)
66 ,dash_phase(dash_phase)
67 ,dashes(dashes) {}
68
74 TableBorderInfo(const TableBorderInfo& table_border_info)
75 : table_border_style(table_border_info.table_border_style)
76 , line_width(table_border_info.line_width)
77 , color(table_border_info.color)
78 , dash_phase(table_border_info.dash_phase)
79 , dashes(table_border_info.dashes) {}
80
88 TableBorderInfo &operator = (const TableBorderInfo& data) {
89 table_border_style = data.table_border_style;
90 line_width = data.line_width;
91 color = data.color;
92 dash_phase = data.dash_phase;
93 dashes = data.dashes;
94 return *this;
95 }
96
104 bool operator == (const TableBorderInfo& table_border_info) const {
105 if (dashes.GetSize() != table_border_info.dashes.GetSize()) return false;
106 for (int i = 0; i < dashes.GetSize(); i++)
107 if (dashes.GetAt(i) != table_border_info.dashes.GetAt(i)) return false;
108
109 return (table_border_style == table_border_info.table_border_style &&
110 fabs(line_width- table_border_info.line_width) <= FLT_EPSILON &&
111 color == table_border_info.color &&
112 dash_phase == table_border_info.dash_phase);
113 }
114
122 bool operator != (const TableBorderInfo& data) const {
123 return !((*this) == data);
124 }
125
141 void Set(const TableBorderStyle& table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes) {
142 this->table_border_style = table_border_style;
143 this->line_width = line_width;
144 this->color = color;
145 this->dash_phase = dash_phase;
146 this->dashes = dashes;
147 }
148
153 TableBorderStyle table_border_style;
154
159 float line_width;
160
162 ARGB color;
163
168 float dash_phase;
169
175 FloatArray dashes;
176 };
177
178 class TableCellData;
180 FSDK_DEFINE_ARRAY(TableCellDataColArray, TableCellData)
182 FSDK_DEFINE_ARRAY(TableCellDataArray, TableCellDataColArray)
183
185 class TableCellData FS_FINAL : public Object{
186 public:
188 TableCellData()
189 : cell_text_style(foxit::pdf::RichTextStyle())
190 , cell_fill_color(0xFFFFFFFF)
191 , cell_text(L"")
192 , cell_margin(RectF()) {}
193
203 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)
204 :cell_text_style(cell_text_style)
205 ,cell_fill_color(cell_fill_color)
206 ,cell_text(cell_text)
207 ,cell_image(cell_image)
208 ,cell_margin(cell_margin) {}
209
215 TableCellData(const TableCellData& data)
216 : cell_text_style(data.cell_text_style)
217 , cell_fill_color(data.cell_fill_color)
218 , cell_text(data.cell_text)
219 , cell_image(data.cell_image)
220 , cell_margin(data.cell_margin) {}
221
229 TableCellData &operator = (const TableCellData& data) {
230 cell_text_style = data.cell_text_style;
231 cell_fill_color = data.cell_fill_color;
232 cell_text = data.cell_text;
233 cell_image = data.cell_image;
234 cell_margin = data.cell_margin;
235 return *this;
236 }
237
245 bool operator == (const TableCellData& data) const {
246 return (cell_text_style == data.cell_text_style &&
247 cell_fill_color == data.cell_fill_color &&
248 cell_text == data.cell_text &&
249 cell_image == data.cell_image &&
250 cell_margin == data.cell_margin);
251 }
252
260 bool operator != (const TableCellData& data) const {
261 return !((*this) == data);
262 }
263
275 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) {
276 this->cell_text_style = cell_text_style;
277 this->cell_fill_color = cell_fill_color;
278 this->cell_text = cell_text;
279 this->cell_image = cell_image;
280 this->cell_margin = cell_margin;
281 }
282
284 foxit::pdf::RichTextStyle cell_text_style;
285
287 ARGB cell_fill_color;
288
295 WString cell_text;
296
303 foxit::common::Image cell_image;
304
311 RectF cell_margin;
312 };
313
315 typedef CFX_Point TableCellIndex;
316
318 FSDK_DEFINE_ARRAY(TableCellIndexArray, TableCellIndex)
319
320
321 class TableData FS_FINAL : public Object {
322 public:
324 TableData() : rect(RectF())
325 ,row_count(0)
326 ,col_count(0)
327 ,outside_border_left(TableBorderInfo())
328 ,outside_border_right(TableBorderInfo())
329 ,outside_border_top(TableBorderInfo())
330 ,outside_border_bottom(TableBorderInfo())
331 ,inside_border_row(TableBorderInfo())
332 ,inside_border_col(TableBorderInfo()) {
333 }
334
351 TableData(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
352 TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
353 TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
354 :rect(rect)
355 ,row_count(row_count)
356 ,col_count(col_count)
357 ,outside_border_left(outside_border_left)
358 ,outside_border_right(outside_border_right)
359 ,outside_border_top(outside_border_top)
360 ,outside_border_bottom(outside_border_bottom)
361 ,inside_border_row(inside_border_row)
362 ,inside_border_col(inside_border_col)
363 ,merge_cells(merge_cells)
364 ,row_height_array(row_height_array)
365 ,col_width_array(col_width_array) {
366 }
367
373 TableData(const TableData& data)
374 :rect(data.rect)
375 ,row_count(data.row_count)
376 ,col_count(data.col_count)
377 ,outside_border_left(data.outside_border_left)
378 ,outside_border_right(data.outside_border_right)
379 ,outside_border_top(data.outside_border_top)
380 ,outside_border_bottom(data.outside_border_bottom)
381 ,inside_border_row(data.inside_border_row)
382 ,inside_border_col(data.inside_border_col)
383 ,merge_cells(data.merge_cells)
384 ,row_height_array(data.row_height_array)
385 ,col_width_array(data.col_width_array) {
386 }
387
395 bool operator == (const TableData& data) const {
396 if (merge_cells.GetSize() != data.merge_cells.GetSize()) return false;
397 for (size_t i = 0; i < merge_cells.GetSize(); i++)
398 if (merge_cells.GetAt(i) != data.merge_cells.GetAt(i)) return false;
399 if (row_height_array.GetSize() != data.row_height_array.GetSize()) return false;
400 for (int i = 0; i < row_height_array.GetSize(); i++)
401 if (fabs(row_height_array.GetAt(i) - data.row_height_array.GetAt(i)) > FLT_EPSILON) return false;
402 if (col_width_array.GetSize() != data.col_width_array.GetSize()) return false;
403 for (int i = 0; i < col_width_array.GetSize(); i++)
404 if (fabs(col_width_array.GetAt(i) - data.col_width_array.GetAt(i)) > FLT_EPSILON) return false;
405 return (rect == data.rect &&
406 row_count == data.row_count &&
407 col_count == data.col_count &&
408 outside_border_left == data.outside_border_left &&
409 outside_border_right == data.outside_border_right &&
410 outside_border_top == data.outside_border_top &&
411 outside_border_bottom == data.outside_border_bottom &&
412 inside_border_row == data.inside_border_row &&
413 inside_border_col == data.inside_border_col);
414 }
415
423 bool operator != (const TableData& data) const {
424 return !((*this) == data);
425 }
426
434 TableData &operator = (const TableData& data) {
435 rect = data.rect;
436 row_count = data.row_count;
437 col_count = data.col_count;
438 outside_border_left = data.outside_border_left;
439 outside_border_right = data.outside_border_right;
440 outside_border_top = data.outside_border_top;
441 outside_border_bottom = data.outside_border_bottom;
442 inside_border_row = data.inside_border_row;
443 inside_border_col = data.inside_border_col;
444 merge_cells = data.merge_cells;
445 row_height_array = data.row_height_array;
446 col_width_array = data.col_width_array;
447 return *this;
448 }
449
468 void Set(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
469 TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
470 TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array) {
471 this->rect = rect;
472 this->row_count = row_count;
473 this->col_count = col_count;
474 this->outside_border_left = outside_border_left;
475 this->outside_border_right = outside_border_right;
476 this->outside_border_top = outside_border_top;
477 this->outside_border_bottom = outside_border_bottom;
478 this->inside_border_row = inside_border_row;
479 this->inside_border_col = inside_border_col;
480 this->merge_cells = merge_cells;
481 this->row_height_array = row_height_array;
482 this->col_width_array = col_width_array;
483 }
484
489 RectF rect;
490
492 int row_count;
493
495 int col_count;
496
498 TableBorderInfo outside_border_left;
499
501 TableBorderInfo outside_border_right;
502
504 TableBorderInfo outside_border_top;
505
507 TableBorderInfo outside_border_bottom;
508
510 TableBorderInfo inside_border_row;
511
513 TableBorderInfo inside_border_col;
514
522 TableCellIndexArray merge_cells;
523
525 FloatArray row_height_array;
526
528 FloatArray col_width_array;
529 };
530
535 class TableGeneratorCallback {
536 public:
542 virtual void Release() = 0;
543
551 virtual float GetTableTopMarginToPage(int page_index) = 0;
552
566 virtual foxit::pdf::PageBasicInfo GetNewPageBasicInfo(int page_index, float rest_table_height, float table_width) = 0;
567 };
568
576 class TableGenerator FS_FINAL : public Base{
577 public:
592 static bool AddTableToPage(const foxit::pdf::PDFPage& page, const TableData& data, const TableCellDataArray& cell_array);
593
619 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);
620 };
621 }
622 }
623 }
624 #endif
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo(const TableBorderInfo &table_border_info)
Constructor, with another table border information object.
Definition: fs_tablegenerator.h:74
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:528
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:321
foxit::addon::tablegenerator::TableCellData::cell_text_style
foxit::pdf::RichTextStyle cell_text_style
The style of cell text.
Definition: fs_tablegenerator.h:284
foxit::Object
CFX_Object Object
Object type.
Definition: fs_basictypes.h:220
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:315
foxit::addon::tablegenerator::TableData::TableData
TableData(const TableData &data)
Constructor, with another table cell data object.
Definition: fs_tablegenerator.h:373
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:203
foxit::addon::tablegenerator::TableData::outside_border_right
TableBorderInfo outside_border_right
The right outside border info.
Definition: fs_tablegenerator.h:501
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:168
foxit::addon::tablegenerator::TableData::TableData
TableData()
Constructor.
Definition: fs_tablegenerator.h:324
foxit::addon::tablegenerator::TableBorderInfo::e_TableBorderStyleDashed
Table border style: Dashed.
Definition: fs_tablegenerator.h:37
CFX_ArrayTemplate< float >
foxit::addon::tablegenerator::TableBorderInfo::e_TableBorderStyleSolid
Table border style: Solid.
Definition: fs_tablegenerator.h:35
foxit::addon::tablegenerator::TableBorderInfo::color
ARGB color
The table border color. Format: 0xAARRGGBB.
Definition: fs_tablegenerator.h:162
foxit::addon::tablegenerator::TableCellIndexArray
An array of table cell index.
Definition: fs_tablegenerator.h:318
foxit::ARGB
uint32 ARGB
ARGB color type, 32 bits, ((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:209
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:175
foxit::addon::tablegenerator::TableCellData
Definition: fs_tablegenerator.h:185
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:159
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:468
foxit::addon::tablegenerator::TableData::col_count
int col_count
The count of columns in the table.
Definition: fs_tablegenerator.h:495
foxit::addon::tablegenerator::TableBorderInfo::operator=
TableBorderInfo & operator=(const TableBorderInfo &data)
Assign operator.
Definition: fs_tablegenerator.h:88
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:275
foxit::addon::tablegenerator::TableData::outside_border_bottom
TableBorderInfo outside_border_bottom
The bottom outside border info.
Definition: fs_tablegenerator.h:507
foxit::pdf::RichTextStyle
Definition: fs_annot.h:210
foxit::addon::tablegenerator::TableData::outside_border_top
TableBorderInfo outside_border_top
The top outside border info.
Definition: fs_tablegenerator.h:504
foxit::addon::tablegenerator::TableCellDataColArray
This class represents an array of TableCellData objects,inserted in the order of the displayed table ...
Definition: fs_tablegenerator.h:180
foxit::addon::tablegenerator::TableCellData::TableCellData
TableCellData()
Constructor.
Definition: fs_tablegenerator.h:188
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:522
foxit::addon::tablegenerator::TableCellData::cell_margin
RectF cell_margin
The cell margin between the content and cell border.
Definition: fs_tablegenerator.h:311
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:153
foxit::addon::tablegenerator::TableBorderInfo::TableBorderStyle
TableBorderStyle
Enumeration for PDF annotation type.
Definition: fs_tablegenerator.h:33
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:215
foxit::addon::tablegenerator::TableGeneratorCallback::GetNewPageBasicInfo
virtual foxit::pdf::PageBasicInfo GetNewPageBasicInfo(int page_index, float rest_table_height, float table_width)=0
A callback function to get new page basic information to be generated to a new page.
foxit::pdf::PageBasicInfo
Definition: fs_pdfdoc.h:496
fs_pdfpage.h
Header file for PDF page related definitions and classes.
foxit::addon::tablegenerator::TableCellDataArray
Definition: fs_tablegenerator.h:182
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:510
foxit::addon::tablegenerator::TableBorderInfo
Definition: fs_tablegenerator.h:26
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:62
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:525
foxit::addon::tablegenerator::TableBorderInfo::operator==
bool operator==(const TableBorderInfo &table_border_info) const
Equal operator.
Definition: fs_tablegenerator.h:104
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:42
foxit::addon::tablegenerator::TableBorderInfo::operator!=
bool operator!=(const TableBorderInfo &data) const
Not equal operator.
Definition: fs_tablegenerator.h:122
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:351
fs_pdfdoc.h
Header file for PDF document related definitions and classes.
foxit::addon::tablegenerator::TableCellData::cell_image
foxit::common::Image cell_image
The image content of cell.
Definition: fs_tablegenerator.h:303
NULL
#define NULL
The null-pointer value.
Definition: fx_system.h:792
foxit::addon::tablegenerator::TableData::outside_border_left
TableBorderInfo outside_border_left
The left outside border info.
Definition: fs_tablegenerator.h:498
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:492
foxit::pdf::PDFDoc
Definition: fs_pdfdoc.h:776
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:459
foxit::addon::tablegenerator::TableGeneratorCallback
Definition: fs_tablegenerator.h:535
foxit::addon::tablegenerator::TableGenerator
Definition: fs_tablegenerator.h:576
foxit::addon::tablegenerator::TableCellData::cell_fill_color
ARGB cell_fill_color
The fill color of cell. Format: 0xAARRGGBB.
Definition: fs_tablegenerator.h:287
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:513
CFX_WideString
WIDE STRING CLASS.
Definition: fx_string.h:1461
foxit::Base
Definition: fs_basictypes.h:451
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:141
foxit::addon::tablegenerator::TableCellData::cell_text
WString cell_text
The text content of cell.
Definition: fs_tablegenerator.h:295
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:489