Kill CFX_Object.
[pdfium.git] / core / src / fpdftext / text_int.h
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4  
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef _PDF_TEXT_INT_H_
8 #define _PDF_TEXT_INT_H_
9 class CPDF_TextParseOptions 
10 {
11 public:
12     CPDF_TextParseOptions();
13     FX_BOOL                     m_bCheckObjectOrder;
14     FX_BOOL                     m_bCheckDirection;
15     int                         m_nCheckSameObject;
16 };
17 class CPDF_TextPage;
18 class CPDF_LinkExtract;
19 class CPDF_TextPageFind;
20 class CPDF_DocProgressiveSearch;
21 #define FPDFTEXT_CHAR_ERROR                     -1
22 #define FPDFTEXT_CHAR_NORMAL            0
23 #define FPDFTEXT_CHAR_GENERATED         1
24 #define FPDFTEXT_CHAR_UNUNICODE         2
25 #define FPDFTEXT_CHAR_HYPHEN            3
26 #define FPDFTEXT_CHAR_PIECE                     4
27 #define FPDFTEXT_MC_PASS                        0
28 #define FPDFTEXT_MC_DONE                        1
29 #define FPDFTEXT_MC_DELAY                       2
30 typedef struct _PAGECHAR_INFO {
31     int                                 m_CharCode;
32     FX_WCHAR                    m_Unicode;
33     FX_FLOAT                    m_OriginX;
34     FX_FLOAT                    m_OriginY;
35     FX_INT32                    m_Flag;
36     CFX_FloatRect               m_CharBox;
37     CPDF_TextObject*    m_pTextObj;
38     CFX_AffineMatrix    m_Matrix;
39     int                                 m_Index;
40 } PAGECHAR_INFO;
41 typedef CFX_SegmentedArray<PAGECHAR_INFO> PAGECHAR_InfoArray;
42 typedef struct {
43     int m_Start;
44     int m_nCount;
45 } FPDF_SEGMENT;
46 typedef CFX_ArrayTemplate<FPDF_SEGMENT> SEGMENT_Array;
47 typedef struct {
48     CPDF_TextObject*    m_pTextObj;
49     CFX_AffineMatrix    m_formMatrix;
50 } PDFTEXT_Obj;
51 typedef CFX_ArrayTemplate<PDFTEXT_Obj> LINEOBJ;
52 class CPDF_TextPage: public IPDF_TextPage
53 {
54 public:
55     CPDF_TextPage(const CPDF_Page* pPage, int flags = 0);
56     CPDF_TextPage(const CPDF_PageObjects* pPage, int flags = 0);
57     CPDF_TextPage(const CPDF_Page* pPage, CPDFText_ParseOptions ParserOptions);
58     virtual FX_BOOL                                     ParseTextPage();
59     virtual void                                        NormalizeObjects(FX_BOOL bNormalize);
60     virtual     FX_BOOL                                 IsParsered() const
61     {
62         return m_IsParsered;
63     }
64     virtual ~CPDF_TextPage() {};
65 public:
66     virtual int CharIndexFromTextIndex(int TextIndex)const ;
67     virtual int TextIndexFromCharIndex(int CharIndex)const;
68     virtual int                                         CountChars() const;
69     virtual     void                                    GetCharInfo(int index, FPDF_CHAR_INFO & info) const;
70     virtual void                                        GetRectArray(int start, int nCount, CFX_RectArray& rectArray) const;
71     virtual int                                         GetIndexAtPos(CPDF_Point point, FX_FLOAT xTorelance, FX_FLOAT yTorelance) const;
72     virtual int                                         GetIndexAtPos(FX_FLOAT x, FX_FLOAT y, FX_FLOAT xTorelance,
73             FX_FLOAT yTorelance) const;
74     virtual CFX_WideString                      GetTextByRect(const CFX_FloatRect& rect) const;
75     virtual void                                        GetRectsArrayByRect(const CFX_FloatRect& rect, CFX_RectArray& resRectArray) const;
76     virtual     int                                             GetOrderByDirection(int order, int direction) const;
77     virtual     CFX_WideString                  GetPageText(int start = 0, int nCount = -1) const;
78
79     virtual int                                         CountRects(int start, int nCount);
80     virtual     void                                    GetRect(int rectIndex, FX_FLOAT& left, FX_FLOAT& top
81                                             , FX_FLOAT& right, FX_FLOAT &bottom) const;
82     virtual FX_BOOL                                     GetBaselineRotate(int rectIndex, int& Rotate);
83     virtual FX_BOOL                                     GetBaselineRotate(const CFX_FloatRect& rect, int& Rotate);
84     virtual     int                                             CountBoundedSegments(FX_FLOAT left, FX_FLOAT top,
85             FX_FLOAT right, FX_FLOAT bottom, FX_BOOL bContains = FALSE);
86     virtual     void                                    GetBoundedSegment(int index, int& start, int& count) const;
87     virtual int                                         GetWordBreak(int index, int direction) const;
88 public:
89     const       PAGECHAR_InfoArray*             GetCharList() const
90     {
91         return &m_charList;
92     }
93     static      FX_BOOL                                 IsRectIntersect(const CFX_FloatRect& rect1, const CFX_FloatRect& rect2);
94     static      FX_BOOL                                 IsLetter(FX_WCHAR unicode);
95 private:
96     FX_BOOL                                                     IsHyphen(FX_WCHAR curChar);
97     FX_BOOL                                                     IsControlChar(PAGECHAR_INFO* pCharInfo);
98     FX_BOOL                                                     GetBaselineRotate(int start, int end, int& Rotate);
99     void                                                        ProcessObject();
100     void                                                        ProcessFormObject(CPDF_FormObject*      pFormObj, const CFX_AffineMatrix& formMatrix);
101     void                                                        ProcessTextObject(PDFTEXT_Obj pObj);
102     void                                                        ProcessTextObject(CPDF_TextObject*      pTextObj, const CFX_AffineMatrix& formMatrix, FX_POSITION ObjPos);
103     int                                                         ProcessInsertObject(const CPDF_TextObject* pObj, const CFX_AffineMatrix& formMatrix);
104     FX_BOOL                                                     GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info);
105     FX_BOOL                                                     IsSameAsPreTextObject(CPDF_TextObject* pTextObj, FX_POSITION ObjPos);
106     FX_BOOL                                                     IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject* pTextObj2);
107     int                                                         GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const;
108     void                                                        CloseTempLine();
109     void                                                        OnPiece(IFX_BidiChar* pBidi, CFX_WideString& str);
110     FX_INT32    PreMarkedContent(PDFTEXT_Obj pObj);
111     void                ProcessMarkedContent(PDFTEXT_Obj pObj);
112     void                CheckMarkedContentObject(FX_INT32& start, FX_INT32& nCount) const;
113     void                FindPreviousTextObject(void);
114     void                AddCharInfoByLRDirection(CFX_WideString& str, int i);
115     void                AddCharInfoByRLDirection(CFX_WideString& str, int i);
116     FX_INT32    GetTextObjectWritingMode(const CPDF_TextObject* pTextObj);
117     FX_INT32    FindTextlineFlowDirection();
118     void SwapTempTextBuf(FX_INT32 iCharListStartAppend,
119                          FX_INT32 iBufStartAppend);
120     FX_BOOL IsRightToLeft(const CPDF_TextObject* pTextObj,
121                           const CPDF_Font* pFont,
122                           int nItems) const;
123 protected:
124     CPDFText_ParseOptions                       m_ParseOptions;
125     CFX_WordArray                                       m_CharIndex;
126     const CPDF_PageObjects*                     m_pPage;
127     PAGECHAR_InfoArray                          m_charList;
128     CFX_WideTextBuf                                     m_TextBuf;
129     PAGECHAR_InfoArray                          m_TempCharList;
130     CFX_WideTextBuf                                     m_TempTextBuf;
131     int                                                         m_parserflag;
132     CPDF_TextObject*                            m_pPreTextObj;
133     CFX_AffineMatrix                            m_perMatrix;
134     FX_BOOL                                                     m_IsParsered;
135     CFX_AffineMatrix                            m_DisplayMatrix;
136
137     SEGMENT_Array                                       m_Segment;
138     CFX_RectArray                                       m_SelRects;
139     LINEOBJ                                                     m_LineObj;
140     FX_BOOL                                                     m_TextlineDir;
141     CFX_FloatRect                                       m_CurlineRect;
142 };
143 class CPDF_TextPageFind: public IPDF_TextPageFind
144 {
145 public:
146     CPDF_TextPageFind(const IPDF_TextPage* pTextPage);
147     virtual                                                     ~CPDF_TextPageFind() {};
148 public:
149     virtual     FX_BOOL                                 FindFirst(const CFX_WideString& findwhat, int flags, int startPos = 0);
150     virtual     FX_BOOL                                 FindNext();
151     virtual     FX_BOOL                                 FindPrev();
152
153     virtual void                                        GetRectArray(CFX_RectArray& rects) const;
154     virtual int                                         GetCurOrder() const;
155     virtual int                                         GetMatchedCount()const;
156 protected:
157     void                                                        ExtractFindWhat(const CFX_WideString& findwhat);
158     FX_BOOL                                                     IsMatchWholeWord(const CFX_WideString& csPageText, int startPos, int endPos);
159     FX_BOOL                                                     ExtractSubString(CFX_WideString& rString, FX_LPCWSTR lpszFullString,
160             int iSubString, FX_WCHAR chSep);
161     CFX_WideString                                      MakeReverse(const CFX_WideString& str);
162     int                                                         ReverseFind(const CFX_WideString& csPageText, const CFX_WideString& csWord, int nStartPos, int& WordLength);
163     int                                                         GetCharIndex(int index) const;
164 private:
165     CFX_WordArray                                       m_CharIndex;
166     const IPDF_TextPage*                        m_pTextPage;
167     CFX_WideString                                      m_strText;
168     CFX_WideString                                      m_findWhat;
169     int                                                         m_flags;
170     CFX_WideStringArray                         m_csFindWhatArray;
171     int                                                         m_findNextStart;
172     int                                                         m_findPreStart;
173     FX_BOOL                                                     m_bMatchCase;
174     FX_BOOL                                                     m_bMatchWholeWord;
175     int                                                         m_resStart;
176     int                                                         m_resEnd;
177     CFX_RectArray                                       m_resArray;
178     FX_BOOL                                                     m_IsFind;
179 };
180 class CPDF_LinkExt
181 {
182 public:
183     CPDF_LinkExt() {};
184     int                                                         m_Start;
185     int                                                         m_Count;
186     CFX_WideString                                      m_strUrl;
187     virtual                                                     ~CPDF_LinkExt() {};
188 };
189 typedef CFX_ArrayTemplate<CPDF_LinkExt*> LINK_InfoArray;
190 class CPDF_LinkExtract: public IPDF_LinkExtract
191 {
192 public:
193     CPDF_LinkExtract();
194     virtual                                                     ~CPDF_LinkExtract();
195     virtual FX_BOOL                                     ExtractLinks(const IPDF_TextPage* pTextPage);
196     virtual     FX_BOOL                                 IsExtract() const
197     {
198         return m_IsParserd;
199     }
200 public:
201     virtual int                                         CountLinks() const;
202     virtual     CFX_WideString                  GetURL(int index) const;
203     virtual     void                                    GetBoundedSegment(int index, int& start, int& count) const;
204     virtual     void                                    GetRects(int index, CFX_RectArray& rects)const;
205 protected:
206     void                                                        parserLink();
207     void                                                        DeleteLinkList();
208     FX_BOOL                                                     CheckWebLink(CFX_WideString& strBeCheck);
209     FX_BOOL                                                     CheckMailLink(CFX_WideString& str);
210     FX_BOOL                                                     AppendToLinkList(int start, int count, const CFX_WideString& strUrl);
211 private:
212     LINK_InfoArray                                      m_LinkList;
213     const CPDF_TextPage*                        m_pTextPage;
214     CFX_WideString                                      m_strPageText;
215     FX_BOOL                                                     m_IsParserd;
216 };
217 FX_STRSIZE FX_Unicode_GetNormalization(FX_WCHAR wch, FX_LPWSTR pDst);
218 void NormalizeString(CFX_WideString& str);
219 void NormalizeCompositeChar(FX_WCHAR wChar, CFX_WideString& sDest);
220 #endif