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-2024 by Apryse Software 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  //use Z-order as reading order for text
223  };
224 
239  bool Begin(PDFDoc& doc, const UString& pattern, Mode mode, int start_page = -1, int end_page = -1);
240 
250  SearchResult Run();
251 
260  bool SetPattern(const UString& pattern);
261 
266  Mode GetMode() const;
267 
281  void SetMode( Mode mode );
282 
287  void SetRightToLeftLanguage(bool flag);
288 
296  int GetCurrentPage() const;
297 
308  void SetOCGContext(OCG::Context* context);
309 
313  void Destroy();
314 
315 
316 /* {{codegen: TextSearch}} */
317 
323  void SetAmbientLettersBefore(int ambient_letters_before);
324 
330  void SetAmbientLettersAfter(int ambient_letters_after);
331 
337  void SetAmbientWordsBefore(int ambient_words_before);
338 
344  void SetAmbientWordsAfter(int ambient_words_after);
345 /* {{codegen: TextSearch}} */
346 
347 // @cond PRIVATE_DOC
348 
349  #ifndef SWIGHIDDEN
350  TRN_TextSearch mp_textsearch;
351  #endif /* SWIGHIDDEN */
352 private:
353  TextSearch(const TextSearch&);
354  TextSearch& operator= (const TextSearch&);
355 // @endcond
356 
357 };
358 
359 
360 #include <Impl/TextSearch.inl>
361 
362  }; // namespace PDF
363 }; // namespace pdftron
364 
365 #endif // PDFTRON_H_CPPPDFTextSearch
bool SetPattern(const UString &pattern)
void SetOCGContext(OCG::Context *context)
void SetAmbientLettersAfter(int ambient_letters_after)
UString GetMatch() const
void SetAmbientLettersBefore(int ambient_letters_before)
void SetAmbientWordsAfter(int ambient_words_after)
UString GetAmbientString() const
Highlights GetHighlights() const
int GetCurrentPage() const
void SetAmbientWordsBefore(int ambient_words_before)
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)