• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _FDE_TXTEDTPAGE_H
8 #define _FDE_TXTEDTPAGE_H
9 class CFDE_TxtEdtEngine;
10 class IFX_CharIter;
11 class CFDE_TxtEdtPage;
12 class CFDE_TxtEdtLineExt;
13 class CFDE_TxtEdtTextSet;
14 class CFDE_TxtEdtParag;
15 enum FDE_TXTEDT_CHARTYPE {
16   FDE_TXTEDT_CHARTYPE_Unknown = 0,
17   FDE_TXTEDT_CHARTYPE_Tab,
18   FDE_TXTEDT_CHARTYPE_Space,
19   FDE_TXTEDT_CHARTYPE_Punctuation,
20   FDE_TXTEDT_CHARTYPE_LineBreak,
21   FDE_TXTEDT_CHARTYPE_Number,
22   FDE_TXTEDT_CHARTYPE_Char,
23   FDE_TXTEDT_CHARTYPE_CJK,
24 };
FDE_GetEditSelCharType(FX_WCHAR wChar)25 inline FDE_TXTEDT_CHARTYPE FDE_GetEditSelCharType(FX_WCHAR wChar) {
26   if (wChar == 0x9) {
27     return FDE_TXTEDT_CHARTYPE_Tab;
28   } else if (wChar == 0x20 || wChar == 0xA0) {
29     return FDE_TXTEDT_CHARTYPE_Space;
30   } else if (wChar == 0x9 || wChar == 0x20 || wChar == 0xA0 ||
31              (wChar >= L'!' && wChar <= L'/') ||
32              (wChar >= L':' && wChar <= L'@') ||
33              (wChar >= L'[' && wChar <= L'^') ||
34              (wChar >= L'{' && wChar <= L'~') || wChar == 0x60) {
35     return FDE_TXTEDT_CHARTYPE_Punctuation;
36   } else if (wChar == 0x0a || wChar == 0x0d) {
37     return FDE_TXTEDT_CHARTYPE_LineBreak;
38   } else if (wChar >= '0' && wChar <= '9') {
39     return FDE_TXTEDT_CHARTYPE_Number;
40   } else if ((wChar >= 0x2e80 && wChar <= 0x2eff) ||
41              (wChar >= 0x3000 && wChar <= 0x303f) ||
42              (wChar >= 0x31c0 && wChar <= 0x31ef) ||
43              (wChar >= 0x3200 && wChar <= 0x32ff) ||
44              (wChar >= 0x3300 && wChar <= 0x33ff) ||
45              (wChar >= 0x3400 && wChar <= 0x4dbf) ||
46              (wChar >= 0x4e00 && wChar <= 0x9fff) ||
47              (wChar >= 0xf900 && wChar <= 0xfaff) ||
48              (wChar >= 0xfe30 && wChar <= 0xfe4f)) {
49     return FDE_TXTEDT_CHARTYPE_CJK;
50   } else {
51     return FDE_TXTEDT_CHARTYPE_Char;
52   }
53 }
54 typedef struct _FDE_TXTEDTPIECE {
55   int32_t nStart;
56   int32_t nCount;
57   int32_t nBidiLevel;
58   CFX_RectF rtPiece;
59   FX_DWORD dwCharStyles;
60 } FDE_TEXTEDITPIECE, *FDE_LPTEXTEDITPIECE;
61 typedef CFX_MassArrayTemplate<FDE_TEXTEDITPIECE> CFDE_TXTEDTPieceMassArray;
62 class CFDE_TxtEdtTextSet : public IFDE_TextSet {
63  public:
64   CFDE_TxtEdtTextSet(CFDE_TxtEdtPage* pPage);
65   ~CFDE_TxtEdtTextSet();
66 
67   virtual FDE_VISUALOBJTYPE GetType();
68   virtual FX_BOOL GetBBox(FDE_HVISUALOBJ hVisualObj, CFX_RectF& bbox);
69   virtual FX_BOOL GetMatrix(FDE_HVISUALOBJ hVisualObj, CFX_Matrix& matrix);
70   virtual FX_BOOL GetRect(FDE_HVISUALOBJ hVisualObj, CFX_RectF& rt);
71   virtual FX_BOOL GetClip(FDE_HVISUALOBJ hVisualObj, CFX_RectF& rt);
72   virtual int32_t GetString(FDE_HVISUALOBJ hText, CFX_WideString& wsText);
73   virtual IFX_Font* GetFont(FDE_HVISUALOBJ hText);
74   virtual FX_FLOAT GetFontSize(FDE_HVISUALOBJ hText);
75   virtual FX_ARGB GetFontColor(FDE_HVISUALOBJ hText);
76   virtual int32_t GetDisplayPos(FDE_HVISUALOBJ hText,
77                                 FXTEXT_CHARPOS* pCharPos,
78                                 FX_BOOL bCharCode = FALSE,
79                                 CFX_WideString* pWSForms = NULL);
80   virtual int32_t GetCharRects(FDE_HVISUALOBJ hText, CFX_RectFArray& rtArray);
81   virtual int32_t GetCharRects_Impl(FDE_HVISUALOBJ hText,
82                                     CFX_RectFArray& rtArray,
83                                     FX_BOOL bBBox = FALSE);
84 
85  private:
86   CFDE_TxtEdtPage* m_pPage;
87 };
88 class CFDE_TxtEdtPage : public IFDE_TxtEdtPage {
89  public:
90   CFDE_TxtEdtPage(IFDE_TxtEdtEngine* pEngine, int32_t nLineIndex);
91 
92   virtual void Release();
93   virtual IFDE_TxtEdtEngine* GetEngine() const;
94 
95   virtual FDE_VISUALOBJTYPE GetType();
96   virtual FX_BOOL GetBBox(FDE_HVISUALOBJ hVisualObj, CFX_RectF& bbox);
97   virtual FX_BOOL GetMatrix(FDE_HVISUALOBJ hVisualObj, CFX_Matrix& matrix);
98   virtual FX_BOOL GetRect(FDE_HVISUALOBJ hVisualObj, CFX_RectF& rt);
99   virtual FX_BOOL GetClip(FDE_HVISUALOBJ hVisualObj, CFX_RectF& rt);
100   virtual int32_t GetCharRect(int32_t nIndex,
101                               CFX_RectF& rect,
102                               FX_BOOL bBBox = FALSE) const;
103   virtual int32_t GetCharIndex(const CFX_PointF& fPoint, FX_BOOL& bBefore);
104   virtual int32_t SelectWord(const CFX_PointF& fPoint, int32_t& nCount);
105   virtual int32_t GetCharStart() const;
106   virtual int32_t GetCharCount() const;
107   virtual void CalcRangeRectArray(int32_t nStart,
108                                   int32_t nCount,
109                                   CFX_RectFArray& RectFArr) const;
110   virtual int32_t GetDisplayPos(const CFX_RectF& rtClip,
111                                 FXTEXT_CHARPOS*& pCharPos,
112                                 FX_LPRECTF pBBox) const;
113 
114   virtual FX_BOOL IsLoaded(FX_LPCRECTF pClipBox = NULL);
115   virtual int32_t LoadPage(FX_LPCRECTF pClipBox = NULL,
116                            IFX_Pause* pPause = NULL);
117   virtual void UnloadPage(FX_LPCRECTF pClipBox = NULL);
118 
119   virtual const CFX_RectF& GetContentsBox();
120   virtual FX_POSITION GetFirstPosition(FDE_HVISUALOBJ hCanvas);
121   virtual FDE_HVISUALOBJ GetNext(FDE_HVISUALOBJ hCanvas,
122                                  FX_POSITION& pos,
123                                  IFDE_VisualSet*& pVisualSet);
124   virtual FDE_HVISUALOBJ GetParentCanvas(FDE_HVISUALOBJ hCanvas,
125                                          IFDE_VisualSet*& pVisualSet);
126   virtual FX_WCHAR GetChar(void* pIdentity, int32_t index) const;
127   virtual int32_t GetWidth(void* pIdentity, int32_t index) const;
128 
129  protected:
130   virtual ~CFDE_TxtEdtPage();
131 
132  private:
133   void NormalizePt2Rect(CFX_PointF& ptF,
134                         const CFX_RectF& rtF,
135                         FX_FLOAT fTolerance) const;
136   IFX_CharIter* m_pIter;
137   CFDE_TxtEdtTextSet* m_pTextSet;
138   CFDE_TxtEdtEngine* m_pEditEngine;
139   CFDE_TXTEDTPieceMassArray m_PieceMassArr;
140   CFDE_TxtEdtParag* m_pBgnParag;
141   CFDE_TxtEdtParag* m_pEndParag;
142 
143   int32_t m_nRefCount;
144   int32_t m_nPageStart;
145   int32_t m_nCharCount;
146   int32_t m_nPageIndex;
147   FX_BOOL m_bLoaded;
148   CFX_RectF m_rtPage;
149   CFX_RectF m_rtPageMargin;
150   CFX_RectF m_rtPageContents;
151   CFX_RectF m_rtPageCanvas;
152   int32_t* m_pCharWidth;
153 };
154 #endif
155