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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
// Copyright 2014 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_SRC_FPDFTEXT_TEXT_INT_H_
#define CORE_SRC_FPDFTEXT_TEXT_INT_H_
#include <deque>
#include <vector>
#include "core/include/fpdftext/fpdf_text.h"
#include "core/include/fxcrt/fx_basic.h"
class CFX_BidiChar;
class CPDF_DocProgressiveSearch;
class CPDF_FormObject;
class CPDF_LinkExtract;
class CPDF_TextPageFind;
#define FPDFTEXT_CHAR_ERROR -1
#define FPDFTEXT_CHAR_NORMAL 0
#define FPDFTEXT_CHAR_GENERATED 1
#define FPDFTEXT_CHAR_UNUNICODE 2
#define FPDFTEXT_CHAR_HYPHEN 3
#define FPDFTEXT_CHAR_PIECE 4
#define FPDFTEXT_MC_PASS 0
#define FPDFTEXT_MC_DONE 1
#define FPDFTEXT_MC_DELAY 2
struct PAGECHAR_INFO {
int m_CharCode;
FX_WCHAR m_Unicode;
FX_FLOAT m_OriginX;
FX_FLOAT m_OriginY;
int32_t m_Flag;
CFX_FloatRect m_CharBox;
CPDF_TextObject* m_pTextObj;
CFX_Matrix m_Matrix;
int m_Index;
};
struct FPDF_SEGMENT {
int m_Start;
int m_nCount;
};
struct PDFTEXT_Obj {
CPDF_TextObject* m_pTextObj;
CFX_Matrix m_formMatrix;
};
class CPDF_TextPage : public IPDF_TextPage {
public:
CPDF_TextPage(const CPDF_Page* pPage, int flags);
~CPDF_TextPage() override {}
// IPDF_TextPage:
FX_BOOL ParseTextPage() override;
bool IsParsed() const override { return m_bIsParsed; }
int CharIndexFromTextIndex(int TextIndex) const override;
int TextIndexFromCharIndex(int CharIndex) const override;
int CountChars() const override;
void GetCharInfo(int index, FPDF_CHAR_INFO* info) const override;
void GetRectArray(int start,
int nCount,
CFX_RectArray& rectArray) const override;
int GetIndexAtPos(CPDF_Point point,
FX_FLOAT xTolerance,
FX_FLOAT yTolerance) const override;
int GetIndexAtPos(FX_FLOAT x,
FX_FLOAT y,
FX_FLOAT xTolerance,
FX_FLOAT yTolerance) const override;
CFX_WideString GetTextByRect(const CFX_FloatRect& rect) const override;
void GetRectsArrayByRect(const CFX_FloatRect& rect,
CFX_RectArray& resRectArray) const override;
CFX_WideString GetPageText(int start = 0, int nCount = -1) const override;
int CountRects(int start, int nCount) override;
void GetRect(int rectIndex,
FX_FLOAT& left,
FX_FLOAT& top,
FX_FLOAT& right,
FX_FLOAT& bottom) const override;
FX_BOOL GetBaselineRotate(int rectIndex, int& Rotate) override;
FX_BOOL GetBaselineRotate(const CFX_FloatRect& rect, int& Rotate) override;
int CountBoundedSegments(FX_FLOAT left,
FX_FLOAT top,
FX_FLOAT right,
FX_FLOAT bottom,
FX_BOOL bContains = FALSE) override;
void GetBoundedSegment(int index, int& start, int& count) const override;
int GetWordBreak(int index, int direction) const override;
static FX_BOOL IsRectIntersect(const CFX_FloatRect& rect1,
const CFX_FloatRect& rect2);
static FX_BOOL IsLetter(FX_WCHAR unicode);
private:
FX_BOOL IsHyphen(FX_WCHAR curChar);
bool IsControlChar(const PAGECHAR_INFO& charInfo);
FX_BOOL GetBaselineRotate(int start, int end, int& Rotate);
void ProcessObject();
void ProcessFormObject(CPDF_FormObject* pFormObj,
const CFX_Matrix& formMatrix);
void ProcessTextObject(PDFTEXT_Obj pObj);
void ProcessTextObject(CPDF_TextObject* pTextObj,
const CFX_Matrix& formMatrix,
FX_POSITION ObjPos);
int ProcessInsertObject(const CPDF_TextObject* pObj,
const CFX_Matrix& formMatrix);
FX_BOOL GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info);
FX_BOOL IsSameAsPreTextObject(CPDF_TextObject* pTextObj, FX_POSITION ObjPos);
FX_BOOL IsSameTextObject(CPDF_TextObject* pTextObj1,
CPDF_TextObject* pTextObj2);
int GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const;
void CloseTempLine();
void OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str);
int32_t PreMarkedContent(PDFTEXT_Obj pObj);
void ProcessMarkedContent(PDFTEXT_Obj pObj);
void CheckMarkedContentObject(int32_t& start, int32_t& nCount) const;
void FindPreviousTextObject(void);
void AddCharInfoByLRDirection(FX_WCHAR wChar, PAGECHAR_INFO info);
void AddCharInfoByRLDirection(FX_WCHAR wChar, PAGECHAR_INFO info);
int32_t GetTextObjectWritingMode(const CPDF_TextObject* pTextObj);
int32_t FindTextlineFlowDirection();
void SwapTempTextBuf(int32_t iCharListStartAppend, int32_t iBufStartAppend);
FX_BOOL IsRightToLeft(const CPDF_TextObject* pTextObj,
const CPDF_Font* pFont,
int nItems) const;
std::vector<FX_WORD> m_CharIndex;
const CPDF_PageObjectList* const m_pPage;
std::deque<PAGECHAR_INFO> m_CharList;
std::deque<PAGECHAR_INFO> m_TempCharList;
CFX_WideTextBuf m_TextBuf;
CFX_WideTextBuf m_TempTextBuf;
const int m_parserflag;
CPDF_TextObject* m_pPreTextObj;
CFX_Matrix m_perMatrix;
bool m_bIsParsed;
CFX_Matrix m_DisplayMatrix;
CFX_ArrayTemplate<FPDF_SEGMENT> m_Segments;
CFX_RectArray m_SelRects;
CFX_ArrayTemplate<PDFTEXT_Obj> m_LineObj;
int32_t m_TextlineDir;
CFX_FloatRect m_CurlineRect;
};
class CPDF_TextPageFind : public IPDF_TextPageFind {
public:
explicit CPDF_TextPageFind(const IPDF_TextPage* pTextPage);
~CPDF_TextPageFind() override {}
// IPDF_TextPageFind
FX_BOOL FindFirst(const CFX_WideString& findwhat,
int flags,
int startPos = 0) override;
FX_BOOL FindNext() override;
FX_BOOL FindPrev() override;
void GetRectArray(CFX_RectArray& rects) const override;
int GetCurOrder() const override;
int GetMatchedCount() const override;
protected:
void ExtractFindWhat(const CFX_WideString& findwhat);
FX_BOOL IsMatchWholeWord(const CFX_WideString& csPageText,
int startPos,
int endPos);
FX_BOOL ExtractSubString(CFX_WideString& rString,
const FX_WCHAR* lpszFullString,
int iSubString,
FX_WCHAR chSep);
CFX_WideString MakeReverse(const CFX_WideString& str);
int ReverseFind(const CFX_WideString& csPageText,
const CFX_WideString& csWord,
int nStartPos,
int& WordLength);
int GetCharIndex(int index) const;
private:
std::vector<FX_WORD> m_CharIndex;
const IPDF_TextPage* m_pTextPage;
CFX_WideString m_strText;
CFX_WideString m_findWhat;
int m_flags;
CFX_WideStringArray m_csFindWhatArray;
int m_findNextStart;
int m_findPreStart;
FX_BOOL m_bMatchCase;
FX_BOOL m_bMatchWholeWord;
int m_resStart;
int m_resEnd;
CFX_RectArray m_resArray;
FX_BOOL m_IsFind;
};
class CPDF_LinkExt {
public:
CPDF_LinkExt() {}
int m_Start;
int m_Count;
CFX_WideString m_strUrl;
virtual ~CPDF_LinkExt() {}
};
typedef CFX_ArrayTemplate<CPDF_LinkExt*> LINK_InfoArray;
class CPDF_LinkExtract : public IPDF_LinkExtract {
public:
CPDF_LinkExtract();
~CPDF_LinkExtract() override;
// IPDF_LinkExtract
FX_BOOL ExtractLinks(const IPDF_TextPage* pTextPage) override;
int CountLinks() const override;
CFX_WideString GetURL(int index) const override;
void GetBoundedSegment(int index, int& start, int& count) const override;
void GetRects(int index, CFX_RectArray& rects) const override;
FX_BOOL IsExtract() const { return m_bIsParsed; }
protected:
void ParseLink();
void DeleteLinkList();
FX_BOOL CheckWebLink(CFX_WideString& strBeCheck);
bool CheckMailLink(CFX_WideString& str);
void AppendToLinkList(int start, int count, const CFX_WideString& strUrl);
private:
LINK_InfoArray m_LinkList;
const CPDF_TextPage* m_pTextPage;
CFX_WideString m_strPageText;
bool m_bIsParsed;
};
FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst);
#endif // CORE_SRC_FPDFTEXT_TEXT_INT_H_
|