summaryrefslogtreecommitdiff
path: root/core/fpdftext/cpdf_textpagefind.h
blob: dd7a31eba942f6e7b65db8b86cfbb211257bf8d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FPDFTEXT_CPDF_TEXTPAGEFIND_H_
#define CORE_FPDFTEXT_CPDF_TEXTPAGEFIND_H_

#include <vector>

#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
#include "third_party/base/optional.h"

class CPDF_TextPage;

class CPDF_TextPageFind {
 public:
  explicit CPDF_TextPageFind(const CPDF_TextPage* pTextPage);
  ~CPDF_TextPageFind();

  bool FindFirst(const WideString& findwhat,
                 int flags,
                 Optional<size_t> startPos);
  bool FindNext();
  bool FindPrev();
  int GetCurOrder() const;
  int GetMatchedCount() const;

 protected:
  void ExtractFindWhat(const WideString& findwhat);
  bool IsMatchWholeWord(const WideString& csPageText,
                        size_t startPos,
                        size_t endPos);
  bool ExtractSubString(WideString& rString,
                        const wchar_t* lpszFullString,
                        int iSubString,
                        wchar_t chSep);
  int GetCharIndex(int index) const;

 private:
  std::vector<uint16_t> m_CharIndex;
  UnownedPtr<const CPDF_TextPage> m_pTextPage;
  WideString m_strText;
  WideString m_findWhat;
  int m_flags;
  std::vector<WideString> m_csFindWhatArray;
  Optional<size_t> m_findNextStart;
  Optional<size_t> m_findPreStart;
  bool m_bMatchCase;
  bool m_bMatchWholeWord;
  int m_resStart;
  int m_resEnd;
  std::vector<CFX_FloatRect> m_resArray;
  bool m_IsFind;
};

#endif  // CORE_FPDFTEXT_CPDF_TEXTPAGEFIND_H_