Foxit PDF SDK
fs_search.h
浏览该文件的文档.
1 
15 #ifndef FS_SEARCH_H_
16 #define FS_SEARCH_H_
17 
18 #include "common/fs_common.h"
19 #include "pdf/annots/fs_annot.h"
20 #include "pdf/fs_pdfpage.h"
21 #ifndef _FX_NO_XFA_
22 #include "addon/xfa/fs_xfa.h"
23 #endif // #ifndef _FX_NO_XFA_
24 
30 namespace foxit {
34 namespace pdf {
40 {
41  public:
48  virtual bool NeedToCancelNow() = 0;
49 };
50 
52 class TextPageCharInfo FS_FINAL : public Object {
53  public:
59  typedef enum _TextCharFlag {
61  e_Unknown = -1,
63  e_Normal = 0,
69  e_Hyphen = 3,
72  } TextCharFlag;
73 
74 
91  const RectF& char_box, const RectF& char_outbox, const Matrix& matrix) {
92  this->font = font;
93  this->flag = flag;
94  this->font_size = font_size;
95  this->origin_x = origin_x;
96  this->origin_y = origin_y;
97  this->char_box = char_box;
98  this->char_outbox = char_outbox;
99  this->matrix = matrix;
100  }
101 
105  , font_size(0)
106  , origin_x(0)
107  , origin_y(0) {}
108 
114  TextPageCharInfo(const TextPageCharInfo& char_info) {
115  this->font = char_info.font;
116  this->flag = char_info.flag;
117  this->font_size = char_info.font_size;
118  this->origin_x = char_info.origin_x;
119  this->origin_y = char_info.origin_y;
120  this->char_box = char_info.char_box;
121  this->char_outbox = char_info.char_outbox;
122  this->matrix = char_info.matrix;
123  }
124 
133  this->font = char_info.font;
134  this->flag = char_info.flag;
135  this->font_size = char_info.font_size;
136  this->origin_x = char_info.origin_x;
137  this->origin_y = char_info.origin_y;
138  this->char_box = char_info.char_box;
139  this->char_outbox = char_info.char_outbox;
140  this->matrix = char_info.matrix;
141  return *this;
142  }
143 
151  bool operator == (const TextPageCharInfo& char_info) const {
152  if (font != char_info.font || flag != char_info.flag || fabs(font_size - char_info.font_size) > FLT_EPSILON ||
153  fabs(origin_x - char_info.origin_x) > FLT_EPSILON || fabs(origin_y - char_info.origin_y) > FLT_EPSILON ||
154  char_box != char_info.char_box || char_outbox != char_info.char_outbox || matrix != char_info.matrix)
155  return false;
156 
157  return true;
158  }
159 
167  bool operator != (const TextPageCharInfo& char_info) const{
168  if (font != char_info.font || flag != char_info.flag || fabs(font_size - char_info.font_size) > FLT_EPSILON ||
169  fabs(origin_x - char_info.origin_x) > FLT_EPSILON || fabs(origin_y - char_info.origin_y) > FLT_EPSILON ||
170  char_box != char_info.char_box || char_outbox != char_info.char_outbox || matrix != char_info.matrix)
171  return true;
172 
173  return false;
174  }
175 
193  void Set(const common::Font& font, TextCharFlag flag, float font_size, float origin_x, float origin_y,
194  const RectF& char_box, const RectF& char_outbox, const Matrix& matrix) {
195  this->font = font;
196  this->flag = flag;
197  this->font_size = font_size;
198  this->origin_x = origin_x;
199  this->origin_y = origin_y;
200  this->char_box = char_box;
201  this->char_outbox = char_outbox;
202  this->matrix = matrix;
203  }
204 
209 
217 
223  float font_size;
224 
228  float origin_x;
229 
233  float origin_y;
234 
239 
244 
249 };
250 
265 class TextPage FS_FINAL : public Base {
266  public:
272  typedef enum _TextParseFlags {
279  } TextParseFlags;
280 
286  typedef enum _TextOrderFlag {
291  } TextOrderFlag;
292 
293 
301  explicit TextPage(const PDFPage& page, int flags = foxit::pdf::TextPage::e_ParseTextNormal);
302 
304  ~TextPage();
310  TextPage(const TextPage& other);
318  TextPage& operator = (const TextPage& other);
319 
327  bool operator == (const TextPage& other) const;
335  bool operator != (const TextPage& other) const;
336 
344  bool IsEmpty() const;
345 
351  int GetCharCount() const;
352 
362  TextPageCharInfo GetCharInfo(int char_index);
363 
378  WString GetChars(int start = 0, int count = -1) const;
379 
392  int GetIndexAtPos(float x, float y, float tolerance) const;
393 
401  WString GetTextInRect(const RectF& rect) const;
402 
411  WString GetText(TextOrderFlag flag) const;
412 
426  common::Range GetWordAtPos(float x, float y, float tolerance) const;
427 
439  int GetTextRectCount(int start = 0, int count = -1);
440 
450  RectF GetTextRect(int rect_index) const;
451 
462  common::Rotation GetBaselineRotation(int rect_index);
463 
472 
480  common::Range GetCharRange(const RectF& rect);
481 
496 
497  // 强烈建议用户不要使用此方法;否则可能会发生未知情况。
498  explicit TextPage(FS_HANDLE handle = NULL);
499 };
500 
512 class TextSearch FS_FINAL : public Base {
513  public:
519  typedef enum _SearchFlags {
530  } SearchFlags;
531 
532 
548  explicit TextSearch(const PDFDoc& document, SearchCancelCallback* cancel = NULL, int flags = foxit::pdf::TextPage::e_ParseTextNormal);
549 
550  #ifndef _FX_NO_XFA_
551 
562  explicit TextSearch(const foxit::addon::xfa::XFADoc& xfa_document, foxit::pdf::SearchCancelCallback* cancel = NULL);
563 #endif // #ifndef _FX_NO_XFA_
564 
569  explicit TextSearch(const foxit::pdf::TextPage& text_page);
570 
579  explicit TextSearch(const foxit::pdf::annots::Annot& annot);
580 
582  ~TextSearch();
588  TextSearch(const TextSearch& other);
596  TextSearch& operator = (const TextSearch& other);
597 
605  bool operator == (const TextSearch& other) const;
613  bool operator != (const TextSearch& other) const;
614 
622  bool IsEmpty() const;
623 
634  bool SetPattern(const wchar_t* key_words, bool is_regex_search = false);
635 
650  bool SetStartPage(int page_index);
651 
666  bool SetEndPage(int page_index);
667 
687  bool SetStartCharacter(int char_index);
688 
699  bool SetSearchFlags(uint32 search_flags);
700 
707  bool FindNext();
708 
715  bool FindPrev();
716 
722  RectFArray GetMatchRects() const;
723 
732  int GetMatchPageIndex() const;
733 
740 
751 
762 
769  int GetMatchStartCharIndex() const;
770 
777  int GetMatchEndCharIndex() const;
778 
779  // 强烈建议用户不要使用此方法;否则可能会发生未知情况。
780  explicit TextSearch(FS_HANDLE handle = NULL);
781 };
782 
791 class TextLink FS_FINAL : public Base{
792  public:
794  ~TextLink();
800  TextLink(const TextLink& other);
808  TextLink& operator = (const TextLink& other);
809 
817  bool operator == (const TextLink& other) const;
825  bool operator != (const TextLink& other) const;
826 
834  bool IsEmpty() const;
835 
844  WString GetURI();
845 
851  int GetStartCharIndex();
852 
858  int GetEndCharIndex();
859 
866  // 强烈建议用户不要使用此方法;否则可能会发生未知情况。
867  explicit TextLink(FS_HANDLE handle = NULL);
868 
869 };
870 
875 class PageTextLinks FS_FINAL : public Base{
876  public:
882  explicit PageTextLinks(const TextPage& page);
888  PageTextLinks(const PageTextLinks& other);
896  PageTextLinks& operator = (const PageTextLinks& other);
904  bool operator == (const PageTextLinks& other) const ;
912  bool operator != (const PageTextLinks& other) const ;
913 
921  bool IsEmpty() const;
923  ~PageTextLinks();
924 
930  int GetTextLinkCount();
931 
940  TextLink GetTextLink(int index);
941 
942  // 强烈建议用户不要使用此方法;否则可能会发生未知情况。
943  explicit PageTextLinks(FS_HANDLE handle = NULL);
944 };
945 } // namespace pdf
946 } // namespace foxit
947 #endif // FS_SEARCH_H_
948 
int GetMatchStartCharIndex() const
基于当前匹配页面,获取当前匹配模式第一个字符的索引。
common::Range GetCharRange(const RectF &rect)
获取指定矩形区域内所有文本矩形的字符索引范围。
TextOrderFlag
获取PDF页面文本内容时使用的文本顺序标志枚举。
Definition: fs_search.h:286
bool IsEmpty() const
检查当前对象是否为空。
如果设置,搜索时匹配关键字的大小写。
Definition: fs_search.h:523
Definition: fs_common.h:1364
TextSearch(const PDFDoc &document, SearchCancelCallback *cancel=0, int flags=foxit::pdf::TextPage::e_ParseTextNormal)
对于PDF文档的构造函数。
Definition: fs_search.h:512
RectF char_box
页面空间中的字形边界框。
Definition: fs_search.h:238
CFX_Object Object
对象类型。
Definition: fs_basictypes.h:221
bool FindPrev()
搜索上一个匹配的模式。
TextCharFlag
PDF文本页面字符标志的枚举。
Definition: fs_search.h:59
字符标志:正常。
Definition: fs_search.h:63
TextPageCharInfo(const common::Font &font, TextCharFlag flag, float font_size, float origin_x, float origin_y, const RectF &char_box, const RectF &char_outbox, const Matrix &matrix)
带参数的构造函数。
Definition: fs_search.h:90
RectFArray GetTextRectArrayByRect(const RectF &rect)
获取指定矩形区域内所有文本矩形的数组。
common::Range GetWordAtPos(float x, float y, float tolerance) const
获取页面上指定位置处或附近单词的字符范围, 在PDF坐标系统中。
~TextSearch()
析构函数。
字符标志:连字符。
Definition: fs_search.h:69
bool SetStartPage(int page_index)
设置起始页面索引。
宽字符串类
Definition: fx_string.h:1457
common::Font font
字符的字体。
Definition: fs_search.h:208
int GetMatchEndCharIndex() const
基于当前匹配页面,获取当前匹配模式最后一个字符的索引。
字符标志:生成的。
Definition: fs_search.h:65
RectF char_outbox
页面空间中的印刷(显示和打印)边界框。
Definition: fs_search.h:243
Definition: fs_pdfdoc.h:771
bool operator !=(const TextPageCharInfo &char_info) const
不等于操作符。
Definition: fs_search.h:167
如果设置,搜索时匹配关键字的完整单词。
Definition: fs_search.h:525
bool operator==(const TextSearch &other) const
等于操作符。
TextPageCharInfo(const TextPageCharInfo &char_info)
用另一个字符信息对象的构造函数。
Definition: fs_search.h:114
bool SetStartCharacter(int char_index)
设置起始字符索引,搜索过程从该位置开始。
TextParseFlags
用于文本页面的解析标志枚举。
Definition: fs_search.h:272
字符标志:非Unicode。
Definition: fs_search.h:67
如果设置,搜索时连续匹配关键字。例如,"CC"在"CCC"中将被匹配两次。
Definition: fs_search.h:527
~TextPage()
析构函数。
int GetTextRectCount(int start=0, int count=-1)
计算由起始索引和数量指定范围内的文本矩形。
Definition: fs_xfa.h:905
bool operator !=(const TextSearch &other) const
不等于操作符。
RectF GetTextRect(int rect_index) const
通过索引获取文本矩形。
bool operator==(const TextPage &other) const
等于操作符。
TextSearch & operator=(const TextSearch &other)
赋值操作符。
float font_size
字符的字体大小。
Definition: fs_search.h:223
注释相关定义和类的头文件。
TextCharFlag flag
标志,指示文本页面字符标志的哪些属性是有意义的。
Definition: fs_search.h:216
virtual bool NeedToCancelNow()=0
用于检查是否取消搜索过程的回调函数。
WString GetText(TextOrderFlag flag) const
获取页面文本。
int GetCharCount() const
获取所有字符的数量。
TextPageCharInfo GetCharInfo(int char_index)
获取特定字符的字符信息。
FX_UINT32 uint32
无符号 32 位整数。
Definition: fs_basictypes.h:196
Definition: fs_pdfpage.h:421
void * FS_HANDLE
句柄类型。
Definition: fs_basictypes.h:214
通用定义和类的头文件。
int GetMatchPageIndex() const
获取当前匹配所属的页面索引。
如果设置,表示按显示顺序获取PDF页面的文本内容。
Definition: fs_search.h:290
通过根据字符在PDF页面中的位置规范化字符来解析PDF页面的文本内容。
Definition: fs_search.h:274
WString GetTextInRect(const RectF &rect) const
获取矩形内的文本,在PDF坐标系统中。
TextPageCharInfo()
构造函数。
Definition: fs_search.h:103
bool IsEmpty() const
检查当前对象是否为空。
Definition: fs_basictypes.h:449
字符标志:未知。
Definition: fs_search.h:61
XFA 相关定义和函数的头文件。
PDF页面相关定义和类的头文件。
bool FindNext()
搜索下一个匹配的模式。
bool SetPattern(const wchar_t *key_words, bool is_regex_search=false)
设置要搜索的关键词。
Definition: fs_annot.h:947
common::Rotation GetBaselineRotation(int rect_index)
获取指定矩形的文本趋势(作为旋转)。
int GetIndexAtPos(float x, float y, float tolerance) const
获取页面上指定位置处或附近的字符索引, 在PDF坐标系统中。
Definition: fs_common.h:1519
TextPage & operator=(const TextPage &other)
赋值操作符。
Rotation
旋转的枚举。
Definition: fs_common.h:57
Foxit命名空间。
Definition: fs_taggedpdf.h:27
int GetMatchSentenceStartIndex()
基于匹配句子,获取当前匹配模式第一个字符的索引。
TextPageCharInfo & operator=(const TextPageCharInfo &char_info)
赋值操作符。
Definition: fs_search.h:132
Definition: fs_search.h:52
float origin_y
原点位置的y坐标。
Definition: fs_search.h:233
WString GetTextUnderAnnot(annots::Annot &annot) const
获取与指定注释相交的页面文本。
Matrix matrix
字符的矩阵。
Definition: fs_search.h:248
WString GetChars(int start=0, int count=-1) const
获取由起始索引和数量指定范围内的所有字符。
bool operator !=(const TextPage &other) const
不等于操作符。
#define NULL
空指针值。
Definition: fx_system.h:792
无特殊搜索选项。
Definition: fs_search.h:521
如果设置,在搜索期间忽略全角字符并将所有字符视为标准ASCII或标准宽度字符。
Definition: fs_search.h:529
Definition: fx_coordinates.h:1076
WString GetMatchSentence()
获取包含当前匹配模式的句子。
void Set(const common::Font &font, TextCharFlag flag, float font_size, float origin_x, float origin_y, const RectF &char_box, const RectF &char_outbox, const Matrix &matrix)
设置值。
Definition: fs_search.h:193
int GetMatchSentenceEndIndex()
基于匹配句子,获取当前匹配模式最后一个字符的索引。
按流顺序解析PDF页面的文本内容。
Definition: fs_search.h:278
bool operator==(const TextPageCharInfo &char_info) const
等于操作符。
Definition: fs_search.h:151
SearchFlags
搜索标志的枚举。
Definition: fs_search.h:519
TextPage(const PDFPage &page, int flags=foxit::pdf::TextPage::e_ParseTextNormal)
从已解析的PDF页面构造函数。
Definition: fs_search.h:265
Definition: fs_search.h:39
如果设置,表示按流顺序获取PDF页面的文本内容。
Definition: fs_search.h:288
字符标志:组合词。
Definition: fs_search.h:71
bool SetEndPage(int page_index)
设置结束页面索引。
bool SetSearchFlags(uint32 search_flags)
设置搜索标志。
Definition: fx_coordinates.h:771
RectFArray GetMatchRects() const
获取当前匹配模式的矩形。
在换行时输出连字符来解析PDF页面的文本内容。
Definition: fs_search.h:276
float origin_x
原点位置的x坐标。
Definition: fs_search.h:228