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 #include "pdf/annots/fs_annot.h"
8
14 namespace foxit {
18 namespace addon {
22 namespace tablegenerator {
24 class TableBorderInfo FS_FINAL : public Object{
25 public:
31 typedef enum _TableBorderStyle {
33 e_TableBorderStyleSolid = 0,
35 e_TableBorderStyleDashed = 1
36 } TableBorderStyle;
37
38
40 TableBorderInfo()
41 : table_border_style(e_TableBorderStyleSolid)
42 , line_width(0.0f)
43 , color(0xff000000)
44 , dash_phase(0.0f)
45 , dashes(FloatArray()) {}
46
60 TableBorderInfo(const TableBorderStyle& table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
61 :table_border_style(table_border_style)
62 ,line_width(line_width)
63 ,color(color)
64 ,dash_phase(dash_phase)
65 ,dashes(dashes) {}
66
72 TableBorderInfo(const TableBorderInfo& table_border_info)
73 : table_border_style(table_border_info.table_border_style)
74 , line_width(table_border_info.line_width)
75 , color(table_border_info.color)
76 , dash_phase(table_border_info.dash_phase)
77 , dashes(table_border_info.dashes) {}
78
86 TableBorderInfo &operator = (const TableBorderInfo& data) {
87 table_border_style = data.table_border_style;
88 line_width = data.line_width;
89 color = data.color;
90 dash_phase = data.dash_phase;
91 dashes = data.dashes;
92 return *this;
93 }
94
102 bool operator == (const TableBorderInfo& table_border_info) const {
103 if (dashes.GetSize() != table_border_info.dashes.GetSize()) return false;
104 for (int i = 0; i < dashes.GetSize(); i++)
105 if (dashes.GetAt(i) != table_border_info.dashes.GetAt(i)) return false;
106
107 return (table_border_style == table_border_info.table_border_style &&
108 fabs(line_width- table_border_info.line_width) <= FLT_EPSILON &&
109 color == table_border_info.color &&
110 dash_phase == table_border_info.dash_phase);
111 }
112
120 bool operator != (const TableBorderInfo& data) const {
121 return !((*this) == data);
122 }
123
139 void Set(const TableBorderStyle& table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes) {
140 this->table_border_style = table_border_style;
141 this->line_width = line_width;
142 this->color = color;
143 this->dash_phase = dash_phase;
144 this->dashes = dashes;
145 }
146
151 TableBorderStyle table_border_style;
152
157 float line_width;
158
160 ARGB color;
161
166 float dash_phase;
167
173 FloatArray dashes;
174 };
175
176 class TableCellData;
178 FSDK_DEFINE_ARRAY(TableCellDataColArray, TableCellData)
180 FSDK_DEFINE_ARRAY(TableCellDataArray, TableCellDataColArray)
181
183 class TableCellData FS_FINAL : public Object{
184 public:
186 TableCellData()
187 : cell_text_style(foxit::pdf::RichTextStyle())
188 , cell_fill_color(0xFFFFFFFF)
189 , cell_text(L"")
190 , cell_margin(RectF()) {}
191
201 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)
202 :cell_text_style(cell_text_style)
203 ,cell_fill_color(cell_fill_color)
204 ,cell_text(cell_text)
205 ,cell_image(cell_image)
206 ,cell_margin(cell_margin) {}
207
213 TableCellData(const TableCellData& data)
214 : cell_text_style(data.cell_text_style)
215 , cell_fill_color(data.cell_fill_color)
216 , cell_text(data.cell_text)
217 , cell_image(data.cell_image)
218 , cell_margin(data.cell_margin) {}
219
227 TableCellData &operator = (const TableCellData& data) {
228 cell_text_style = data.cell_text_style;
229 cell_fill_color = data.cell_fill_color;
230 cell_text = data.cell_text;
231 cell_image = data.cell_image;
232 cell_margin = data.cell_margin;
233 return *this;
234 }
235
243 bool operator == (const TableCellData& data) const {
244 return (cell_text_style == data.cell_text_style &&
245 cell_fill_color == data.cell_fill_color &&
246 cell_text == data.cell_text &&
247 cell_image == data.cell_image &&
248 cell_margin == data.cell_margin);
249 }
250
258 bool operator != (const TableCellData& data) const {
259 return !((*this) == data);
260 }
261
273 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) {
274 this->cell_text_style = cell_text_style;
275 this->cell_fill_color = cell_fill_color;
276 this->cell_text = cell_text;
277 this->cell_image = cell_image;
278 this->cell_margin = cell_margin;
279 }
280
282 foxit::pdf::RichTextStyle cell_text_style;
283
285 ARGB cell_fill_color;
286
293 WString cell_text;
294
301 foxit::common::Image cell_image;
302
309 RectF cell_margin;
310 };
311
313 typedef CFX_Point TableCellIndex;
314
316 FSDK_DEFINE_ARRAY(TableCellIndexArray, TableCellIndex)
317
318
319 class TableData FS_FINAL : public Object {
320 public:
322 TableData() : rect(RectF())
323 ,row_count(0)
324 ,col_count(0)
325 ,outside_border_left(TableBorderInfo())
326 ,outside_border_right(TableBorderInfo())
327 ,outside_border_top(TableBorderInfo())
328 ,outside_border_bottom(TableBorderInfo())
329 ,inside_border_row(TableBorderInfo())
330 ,inside_border_col(TableBorderInfo()) {
331 }
332
349 TableData(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
350 TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
351 TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array)
352 :rect(rect)
353 ,row_count(row_count)
354 ,col_count(col_count)
355 ,outside_border_left(outside_border_left)
356 ,outside_border_right(outside_border_right)
357 ,outside_border_top(outside_border_top)
358 ,outside_border_bottom(outside_border_bottom)
359 ,inside_border_row(inside_border_row)
360 ,inside_border_col(inside_border_col)
361 ,merge_cells(merge_cells)
362 ,row_height_array(row_height_array)
363 ,col_width_array(col_width_array) {
364 }
365
371 TableData(const TableData& data)
372 :rect(data.rect)
373 ,row_count(data.row_count)
374 ,col_count(data.col_count)
375 ,outside_border_left(data.outside_border_left)
376 ,outside_border_right(data.outside_border_right)
377 ,outside_border_top(data.outside_border_top)
378 ,outside_border_bottom(data.outside_border_bottom)
379 ,inside_border_row(data.inside_border_row)
380 ,inside_border_col(data.inside_border_col)
381 ,merge_cells(data.merge_cells)
382 ,row_height_array(data.row_height_array)
383 ,col_width_array(data.col_width_array) {
384 }
385
393 bool operator == (const TableData& data) const {
394 if (merge_cells.GetSize() != data.merge_cells.GetSize()) return false;
395 for (size_t i = 0; i < merge_cells.GetSize(); i++)
396 if (merge_cells.GetAt(i) != data.merge_cells.GetAt(i)) return false;
397 if (row_height_array.GetSize() != data.row_height_array.GetSize()) return false;
398 for (int i = 0; i < row_height_array.GetSize(); i++)
399 if (fabs(row_height_array.GetAt(i) - data.row_height_array.GetAt(i)) > FLT_EPSILON) return false;
400 if (col_width_array.GetSize() != data.col_width_array.GetSize()) return false;
401 for (int i = 0; i < col_width_array.GetSize(); i++)
402 if (fabs(col_width_array.GetAt(i) - data.col_width_array.GetAt(i)) > FLT_EPSILON) return false;
403 return (rect == data.rect &&
404 row_count == data.row_count &&
405 col_count == data.col_count &&
406 outside_border_left == data.outside_border_left &&
407 outside_border_right == data.outside_border_right &&
408 outside_border_top == data.outside_border_top &&
409 outside_border_bottom == data.outside_border_bottom &&
410 inside_border_row == data.inside_border_row &&
411 inside_border_col == data.inside_border_col);
412 }
413
421 bool operator != (const TableData& data) const {
422 return !((*this) == data);
423 }
424
432 TableData &operator = (const TableData& data) {
433 rect = data.rect;
434 row_count = data.row_count;
435 col_count = data.col_count;
436 outside_border_left = data.outside_border_left;
437 outside_border_right = data.outside_border_right;
438 outside_border_top = data.outside_border_top;
439 outside_border_bottom = data.outside_border_bottom;
440 inside_border_row = data.inside_border_row;
441 inside_border_col = data.inside_border_col;
442 merge_cells = data.merge_cells;
443 row_height_array = data.row_height_array;
444 col_width_array = data.col_width_array;
445 return *this;
446 }
447
466 void Set(RectF rect, int row_count, int col_count, TableBorderInfo outside_border_left,
467 TableBorderInfo outside_border_right, TableBorderInfo outside_border_top, TableBorderInfo outside_border_bottom,
468 TableBorderInfo inside_border_row, TableBorderInfo inside_border_col, TableCellIndexArray merge_cells, FloatArray row_height_array, FloatArray col_width_array) {
469 this->rect = rect;
470 this->row_count = row_count;
471 this->col_count = col_count;
472 this->outside_border_left = outside_border_left;
473 this->outside_border_right = outside_border_right;
474 this->outside_border_top = outside_border_top;
475 this->outside_border_bottom = outside_border_bottom;
476 this->inside_border_row = inside_border_row;
477 this->inside_border_col = inside_border_col;
478 this->merge_cells = merge_cells;
479 this->row_height_array = row_height_array;
480 this->col_width_array = col_width_array;
481 }
482
487 RectF rect;
488
490 int row_count;
491
493 int col_count;
494
496 TableBorderInfo outside_border_left;
497
499 TableBorderInfo outside_border_right;
500
502 TableBorderInfo outside_border_top;
503
505 TableBorderInfo outside_border_bottom;
506
508 TableBorderInfo inside_border_row;
509
511 TableBorderInfo inside_border_col;
512
520 TableCellIndexArray merge_cells;
521
523 FloatArray row_height_array;
524
526 FloatArray col_width_array;
527 };
528
533 class TableGeneratorCallback {
534 public:
540 virtual void Release() = 0;
541
549 virtual float GetTableTopMarginToPage(int page_index) = 0;
550
564 virtual foxit::pdf::PageBasicInfo GetNewPageBasicInfo(int page_index, float rest_table_height, float table_width) = 0;
565 };
566
574 class TableGenerator FS_FINAL : public Base{
575 public:
590 static bool AddTableToPage(const foxit::pdf::PDFPage& page, const TableData& data, const TableCellDataArray& cell_array);
591
617 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);
618 };
619 }
620 }
621 }
622 #endif
foxit::addon::tablegenerator::TableData::col_width_array
FloatArray col_width_array
列宽数组。如果数组成员为零，列宽将自动设置为默认值。默认值：(rect 的宽度)/col_count。
Definition: fs_tablegenerator.h:526
foxit::addon::tablegenerator::TableCellData::TableCellData
TableCellData()
构造函数。
Definition: fs_tablegenerator.h:186
foxit::pdf::RichTextStyle
Definition: fs_annot.h:201
foxit::addon::tablegenerator::TableBorderInfo::color
ARGB color
表格边框颜色。格式：0xAARRGGBB。
Definition: fs_tablegenerator.h:160
foxit::Object
CFX_Object Object
对象类型。
Definition: fs_basictypes.h:220
foxit::addon::tablegenerator::TableBorderInfo::dashes
FloatArray dashes
表示虚线模式的虚线数组。此数组中每个元素的值 不应为负。仅当 style 为 TableBorderInfo::e_TableBorderStyleDashed 时有用。 更多详细信息请参考 <PDF ...
Definition: fs_tablegenerator.h:173
foxit::addon::tablegenerator::TableData::TableData
TableData(const TableData &data)
拷贝构造函数。
Definition: fs_tablegenerator.h:371
fs_pdfdoc.h
PDF文档相关定义和类的头文件。
foxit::addon::tablegenerator::TableCellData
Definition: fs_tablegenerator.h:183
foxit::addon::tablegenerator::TableData::outside_border_right
TableBorderInfo outside_border_right
右外边框信息。
Definition: fs_tablegenerator.h:499
foxit::addon::tablegenerator::TableData::TableData
TableData()
构造函数。
Definition: fs_tablegenerator.h:322
CFX_PSVTemplate
Definition: fx_coordinates.h:30
CFX_ArrayTemplate::GetSize
int GetSize() const
获取数组中元素的数量。
Definition: fx_basic.h:1341
foxit::addon::tablegenerator::TableBorderInfo::line_width
float line_width
表格边框线宽，以点为单位。应该是非负值。 如果此值为 0，则不绘制边框。
Definition: fs_tablegenerator.h:157
foxit::addon::tablegenerator::TableBorderInfo::Set
void Set(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
设置值。
Definition: fs_tablegenerator.h:139
foxit::addon::tablegenerator::TableCellData::cell_image
foxit::common::Image cell_image
单元格的图像内容。
Definition: fs_tablegenerator.h:301
CFX_WideString
宽字符串类
Definition: fx_string.h:1457
foxit::addon::tablegenerator::TableBorderInfo::operator !=
bool operator !=(const TableBorderInfo &data) const
不等操作符。
Definition: fs_tablegenerator.h:120
foxit::addon::tablegenerator::TableGeneratorCallback::Release
virtual void Release()=0
用于释放当前回调对象本身的回调函数。
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo(const TableBorderInfo &table_border_info)
拷贝构造函数。
Definition: fs_tablegenerator.h:72
foxit::addon::tablegenerator::TableCellData::cell_text_style
foxit::pdf::RichTextStyle cell_text_style
单元格文本样式。
Definition: fs_tablegenerator.h:282
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)
设置值。
Definition: fs_tablegenerator.h:466
foxit::pdf::PDFDoc
Definition: fs_pdfdoc.h:768
foxit::addon::tablegenerator::TableData::col_count
int col_count
表格中的列数。
Definition: fs_tablegenerator.h:493
foxit::addon::tablegenerator::TableBorderInfo::dash_phase
float dash_phase
虚线相位。不应为负。仅当参数 style 为 TableBorderInfo::e_TableBorderStyleDashed 时有用。 更多详细信息请参考 <PDF Reference 1....
Definition: fs_tablegenerator.h:166
foxit::addon::tablegenerator::TableCellData::cell_fill_color
ARGB cell_fill_color
单元格的填充颜色。格式：0xAARRGGBB。
Definition: fs_tablegenerator.h:285
foxit::addon::tablegenerator::TableData::outside_border_top
TableBorderInfo outside_border_top
上外边框信息。
Definition: fs_tablegenerator.h:502
foxit::addon::tablegenerator::TableCellDataArray
Definition: fs_tablegenerator.h:180
foxit::addon::tablegenerator::TableBorderInfo::table_border_style
TableBorderStyle table_border_style
表格边框样式。请参考从 TableBorderInfo::e_TableBorderStyleSolid 开始的值， 应该是这些值中的一个。
Definition: fs_tablegenerator.h:151
foxit::addon::tablegenerator::TableBorderInfo
Definition: fs_tablegenerator.h:24
operator==
bool operator==(const char *str1, const CFX_ByteString &str2)
检查两个字节字符串是否相等。
Definition: fs_basictypes.h:128
foxit::addon::tablegenerator::TableBorderInfo::operator==
bool operator==(const TableBorderInfo &table_border_info) const
相等操作符。
Definition: fs_tablegenerator.h:102
foxit::addon::tablegenerator::TableCellData::cell_text
WString cell_text
单元格的文本内容。
Definition: fs_tablegenerator.h:293
foxit::ARGB
uint32 ARGB
ARGB 颜色类型，32 位，((b) | ((g) << 8) | ((r) << 16)) | ((a) << 24)
Definition: fs_basictypes.h:209
foxit::pdf::PageBasicInfo
Definition: fs_pdfdoc.h:489
foxit::addon::tablegenerator::TableData::outside_border_bottom
TableBorderInfo outside_border_bottom
下外边框信息。
Definition: fs_tablegenerator.h:505
foxit::addon::tablegenerator::TableData::merge_cells
TableCellIndexArray merge_cells
合并单元格。此数组的长度必须是偶数，零长度表示没有合并单元格。
Definition: fs_tablegenerator.h:520
fs_annot.h
注释相关定义和类的头文件。
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)
构造函数，带参数。
Definition: fs_tablegenerator.h:201
foxit::addon::tablegenerator::TableData::inside_border_row
TableBorderInfo inside_border_row
行内边框信息。
Definition: fs_tablegenerator.h:508
foxit::addon::tablegenerator::TableData
Definition: fs_tablegenerator.h:319
CFX_ArrayTemplate< float >
CFX_ArrayTemplate::GetAt
const TYPE GetAt(int nIndex) const
此方法检索由索引号指定的元素。
Definition: fx_basic.h:1377
foxit::addon::tablegenerator::TableBorderInfo::operator=
TableBorderInfo & operator=(const TableBorderInfo &data)
赋值操作符。
Definition: fs_tablegenerator.h:86
foxit::addon::tablegenerator::TableCellIndexArray
表格单元格索引的数组。
Definition: fs_tablegenerator.h:316
foxit::addon::tablegenerator::TableGenerator::AddTableToPage
static bool AddTableToPage(const foxit::pdf::PDFPage &page, const TableData &data, const TableCellDataArray &cell_array)
向 PDF 页面添加新表格。
foxit::pdf::PDFPage
Definition: fs_pdfpage.h:417
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)
构造函数，带参数。
Definition: fs_tablegenerator.h:349
fs_common.h
通用定义和类的头文件。
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)
设置值。
Definition: fs_tablegenerator.h:273
foxit::addon::tablegenerator::TableCellIndex
CFX_Point TableCellIndex
表格单元格索引。x 表示单元格的行索引，y 表示单元格的列索引。
Definition: fs_tablegenerator.h:313
foxit::addon::tablegenerator::TableBorderInfo::TableBorderStyle
TableBorderStyle
PDF 表格边框样式的枚举。
Definition: fs_tablegenerator.h:31
foxit::addon::tablegenerator::TableGenerator
Definition: fs_tablegenerator.h:574
foxit::addon::tablegenerator::TableData::outside_border_left
TableBorderInfo outside_border_left
左外边框信息。
Definition: fs_tablegenerator.h:496
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)
向文档插入包含在一页或多页中的新表格。
foxit::addon::tablegenerator::TableBorderInfo::e_TableBorderStyleDashed
表格边框样式：虚线。
Definition: fs_tablegenerator.h:35
foxit::addon::tablegenerator::TableData::row_height_array
FloatArray row_height_array
行高数组。如果数组成员为零，行高将自动设置为默认值。默认值：(rect 的高度)/row_count。
Definition: fs_tablegenerator.h:523
foxit::addon::tablegenerator::TableCellData::cell_margin
RectF cell_margin
内容与单元格边框之间的单元格边距。
Definition: fs_tablegenerator.h:309
foxit::Base
Definition: fs_basictypes.h:465
foxit::addon::tablegenerator::TableData::row_count
int row_count
表格中的行数。
Definition: fs_tablegenerator.h:490
foxit::addon::tablegenerator::TableCellIndexArray::GetSize
size_t GetSize() const
获取当前数组中元素的大小。
foxit::addon::tablegenerator::TableCellData::TableCellData
TableCellData(const TableCellData &data)
拷贝构造函数。
Definition: fs_tablegenerator.h:213
fs_pdfpage.h
PDF页面相关定义和类的头文件。
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo()
构造函数。
Definition: fs_tablegenerator.h:40
foxit
Foxit命名空间。
Definition: fs_taggedpdf.h:27
foxit::addon::tablegenerator::TableGeneratorCallback::GetTableTopMarginToPage
virtual float GetTableTopMarginToPage(int page_index)=0
获取要生成到新页面的表格的上边距的回调函数。
foxit::addon::tablegenerator::TableCellIndexArray::GetAt
TableCellIndex GetAt(size_t index) const
检索当前数组中由索引指定位置的元素副本。
foxit::addon::tablegenerator::TableBorderInfo::e_TableBorderStyleSolid
表格边框样式：实线。
Definition: fs_tablegenerator.h:33
foxit::addon::tablegenerator::TableData::inside_border_col
TableBorderInfo inside_border_col
列内边框信息。
Definition: fs_tablegenerator.h:511
NULL
#define NULL
空指针值。
Definition: fx_system.h:792
foxit::addon::tablegenerator::TableBorderInfo::TableBorderInfo
TableBorderInfo(const TableBorderStyle &table_border_style, float line_width, ARGB color, float dash_phase, FloatArray dashes)
构造函数，带参数。
Definition: fs_tablegenerator.h:60
foxit::addon::tablegenerator::TableGeneratorCallback::GetNewPageBasicInfo
virtual foxit::pdf::PageBasicInfo GetNewPageBasicInfo(int page_index, float rest_table_height, float table_width)=0
获取要生成到新页面的新页面基本信息的回调函数。
foxit::addon::tablegenerator::TableCellDataColArray
此类表示 TableCellData 对象的数组，按显示表格的从左到右顺序插入。
Definition: fs_tablegenerator.h:178
foxit::addon::tablegenerator::TableGeneratorCallback
Definition: fs_tablegenerator.h:533
foxit::addon::tablegenerator::TableData::rect
RectF rect
表格的矩形，指定在 PDF 页面中的位置。 应该在 PDF 坐标系 中。
Definition: fs_tablegenerator.h:487
foxit::common::Image
Definition: fs_image.h:450
CFX_FloatRect
Definition: fx_coordinates.h:771