All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextSearch.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5 #ifndef PDFTRON_H_CPPPDFTextSearch
6 #define PDFTRON_H_CPPPDFTextSearch
7 
8 #include <PDF/PDFDoc.h>
9 #include <Common/UString.h>
10 #include <PDF/Highlights.h>
11 #include <C/PDF/TRN_TextSearch.h>
12 
13 namespace pdftron {
14  namespace PDF {
15 
20 {
21 public:
22 
26  operator bool () { return IsFound(); }
27 
31  bool IsFound() const;
32 
36  bool IsDocEnd() const;
37 
41  bool IsPageEnd() const;
42 
46  int GetPageNumber() const;
47 
51  UString GetMatch() const;
52 
57  UString GetAmbientString() const;
58 
63  Highlights GetHighlights() const;
64 
65 
66 
67 // @cond PRIVATE_DOC
68 
69 #ifndef SWIGHIDDEN
70  SearchResult();
71  SearchResult(const SearchResult& b);
72  SearchResult(int, TRN_TextSearchResultCode rc, UString r, UString a, Highlights h);
73 #endif
74 // @endcond
75 
76 private:
77  int page_num;
78  TRN_TextSearchResultCode resCode;
79  UString result;
80  UString ambient;
81  Highlights hlts;
82 };
83 
84 
174 {
175 public:
176 
180  TextSearch();
181  ~TextSearch();
182 
186  typedef TRN_UInt32 Mode;
187 
192  {
193  //use regular expressions
195 
196  //match case-sensitively
198 
199  //match the entire word
201 
202  //search upward (from the end of the file and from the bottom of a page)
204 
205  //tells the search process to return when each page is finished; this is
206  //useful when a user needs Run() to return periodically so that certain
207  //things (e.g., UI) can be updated from time to time.
209 
210  //tells the search process to compute Highlight information.
212 
213  //tells the search process to compute the ambient string of the found pattern.
214  //This is useful if a user wants to examine or display what surrounds the
215  //found pattern.
217 
218  //refrain from replacing newlines with spaces
220  };
221 
236  bool Begin(PDFDoc& doc, const UString& pattern, Mode mode, int start_page = -1, int end_page = -1);
237 
247  SearchResult Run();
248 
257  bool SetPattern(const UString& pattern);
258 
263  Mode GetMode() const;
264 
278  void SetMode( Mode mode );
279 
284  void SetRightToLeftLanguage(bool flag);
285 
293  int GetCurrentPage() const;
294 
305  void SetOCGContext(OCG::Context* context);
306 
310  void Destroy();
311 
312 
313 // @cond PRIVATE_DOC
314 
315 private:
316  TRN_TextSearch mp_textsearch;
317  TextSearch(const TextSearch&);
318  TextSearch& operator= (const TextSearch&);
319 // @endcond
320 
321 };
322 
323 
324 #include <Impl/TextSearch.inl>
325 
326  }; // namespace PDF
327 }; // namespace pdftron
328 
329 #endif // PDFTRON_H_CPPPDFTextSearch
bool SetPattern(const UString &pattern)
void SetOCGContext(OCG::Context *context)
UString GetMatch() const
UString GetAmbientString() const
Highlights GetHighlights() const
int GetCurrentPage() const
void SetRightToLeftLanguage(bool flag)
bool Begin(PDFDoc &doc, const UString &pattern, Mode mode, int start_page=-1, int end_page=-1)
void SetMode(Mode mode)