Loading...
Searching...
No Matches
TextSearch.h
Go to the documentation of this file.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2025 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
19 class SearchResult
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
173 class TextSearch
174{
175 public:
176
180 TextSearch();
181 ~TextSearch();
182
186 typedef TRN_UInt32 Mode;
187
191 enum TextSearchModes
192 {
193 //use regular expressions
194 e_reg_expression = 0x0001,
195
196 //match case-sensitively
197 e_case_sensitive = e_reg_expression << 1,
198
199 //match the entire word
200 e_whole_word = e_case_sensitive << 1,
201
202 //search upward (from the end of the file and from the bottom of a page)
203 e_search_up = e_whole_word << 1,
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.
208 e_page_stop = e_search_up << 1,
209
210 //tells the search process to compute Highlight information.
211 e_highlight = e_page_stop << 1,
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.
216 e_ambient_string = e_highlight << 1,
217
218 //refrain from replacing newlines with spaces
219 e_raw_text_search = e_ambient_string << 1,
220
221 //use Z-order as reading order for text
222 e_search_using_zorder = e_raw_text_search << 1
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
Highlights.h
PDFDoc.h
UString.h
pdftron::PDF::Highlights
Definition Highlights.h:71
pdftron::PDF::OCG::Context
Definition Context.h:42
pdftron::PDF::PDFDoc
Definition PDFDoc.h:72
pdftron::PDF::SearchResult
Definition TextSearch.h:20
pdftron::PDF::SearchResult::GetHighlights
Highlights GetHighlights() const
pdftron::PDF::SearchResult::IsDocEnd
bool IsDocEnd() const
pdftron::PDF::SearchResult::IsFound
bool IsFound() const
pdftron::PDF::SearchResult::GetPageNumber
int GetPageNumber() const
pdftron::PDF::SearchResult::IsPageEnd
bool IsPageEnd() const
pdftron::PDF::SearchResult::GetAmbientString
UString GetAmbientString() const
pdftron::PDF::SearchResult::GetMatch
UString GetMatch() const
pdftron::PDF::TextSearch::~TextSearch
~TextSearch()
pdftron::PDF::TextSearch::SetAmbientLettersBefore
void SetAmbientLettersBefore(int ambient_letters_before)
pdftron::PDF::TextSearch::Destroy
void Destroy()
pdftron::PDF::TextSearch::SetAmbientLettersAfter
void SetAmbientLettersAfter(int ambient_letters_after)
pdftron::PDF::TextSearch::TextSearch
TextSearch()
pdftron::PDF::TextSearch::Begin
bool Begin(PDFDoc &doc, const UString &pattern, Mode mode, int start_page=-1, int end_page=-1)
pdftron::PDF::TextSearch::SetRightToLeftLanguage
void SetRightToLeftLanguage(bool flag)
pdftron::PDF::TextSearch::SetMode
void SetMode(Mode mode)
pdftron::PDF::TextSearch::Run
SearchResult Run()
pdftron::PDF::TextSearch::SetPattern
bool SetPattern(const UString &pattern)
pdftron::PDF::TextSearch::SetOCGContext
void SetOCGContext(OCG::Context *context)
pdftron::PDF::TextSearch::SetAmbientWordsAfter
void SetAmbientWordsAfter(int ambient_words_after)
pdftron::PDF::TextSearch::SetAmbientWordsBefore
void SetAmbientWordsBefore(int ambient_words_before)
pdftron::PDF::TextSearch::Mode
TRN_UInt32 Mode
Definition TextSearch.h:186
pdftron::PDF::TextSearch::GetMode
Mode GetMode() const
pdftron::PDF::TextSearch::GetCurrentPage
int GetCurrentPage() const
pdftron::PDF::TextSearch::TextSearchModes
TextSearchModes
Definition TextSearch.h:192
pdftron::PDF::TextSearch::e_whole_word
@ e_whole_word
Definition TextSearch.h:200
pdftron::PDF::TextSearch::e_raw_text_search
@ e_raw_text_search
Definition TextSearch.h:219
pdftron::PDF::TextSearch::e_reg_expression
@ e_reg_expression
Definition TextSearch.h:194
pdftron::PDF::TextSearch::e_ambient_string
@ e_ambient_string
Definition TextSearch.h:216
pdftron::PDF::TextSearch::e_search_up
@ e_search_up
Definition TextSearch.h:203
pdftron::PDF::TextSearch::e_page_stop
@ e_page_stop
Definition TextSearch.h:208
pdftron::PDF::TextSearch::e_search_using_zorder
@ e_search_using_zorder
Definition TextSearch.h:222
pdftron::PDF::TextSearch::e_case_sensitive
@ e_case_sensitive
Definition TextSearch.h:197
pdftron::PDF::TextSearch::e_highlight
@ e_highlight
Definition TextSearch.h:211
pdftron::UString
Definition UString.h:28
pdftron::PDF
Definition Action.h:15
pdftron
Definition BasicTypes.h:10