Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fgas / include / fx_tbk.h
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #ifndef _FX_TEXTBREAK\r
8 #define _FX_TEXTBREAK\r
9 class IFX_Font;\r
10 class CFX_Char;\r
11 class IFX_TxtAccess;\r
12 class CFX_TxtChar;\r
13 class CFX_TxtPiece;\r
14 class IFX_TxtBreak;\r
15 #define FX_TXTBREAKPOLICY_None                          0x00\r
16 #define FX_TXTBREAKPOLICY_Pagination            0x01\r
17 #define FX_TXTBREAKPOLICY_SpaceBreak            0x02\r
18 #define FX_TXTBREAKPOLICY_NumberBreak           0x04\r
19 #define FX_TXTBREAK_None                                        0x00\r
20 #define FX_TXTBREAK_PieceBreak                          0x01\r
21 #define FX_TXTBREAK_LineBreak                           0x02\r
22 #define FX_TXTBREAK_ParagraphBreak                      0x03\r
23 #define FX_TXTBREAK_PageBreak                           0x04\r
24 #define FX_TXTBREAK_ControlChar                         0x10\r
25 #define FX_TXTBREAK_BreakChar                           0x20\r
26 #define FX_TXTBREAK_UnknownChar                         0x40\r
27 #define FX_TXTBREAK_RemoveChar                          0x80\r
28 #define FX_TXTLAYOUTSTYLE_MutipleFormat         0x0001\r
29 #define FX_TXTLAYOUTSTYLE_VerticalLayout        0x0002\r
30 #define FX_TXTLAYOUTSTYLE_VerticalChars         0x0004\r
31 #define FX_TXTLAYOUTSTYLE_ReverseLine           0x0008\r
32 #define FX_TXTLAYOUTSTYLE_ArabicContext         0x0010\r
33 #define FX_TXTLAYOUTSTYLE_ArabicShapes          0x0020\r
34 #define FX_TXTLAYOUTSTYLE_RTLReadingOrder       0x0040\r
35 #define FX_TXTLAYOUTSTYLE_ExpandTab                     0x0100\r
36 #define FX_TXTLAYOUTSTYLE_SingleLine            0x0200\r
37 #define FX_TXTLAYOUTSTYLE_CombText                      0x0400\r
38 #define FX_TXTCHARSTYLE_Alignment                       0x000F\r
39 #define FX_TXTCHARSTYLE_ArabicNumber            0x0010\r
40 #define FX_TXTCHARSTYLE_ArabicShadda            0x0020\r
41 #define FX_TXTCHARSTYLE_OddBidiLevel            0x0040\r
42 #define FX_TXTCHARSTYLE_RTLReadingOrder         0x0080\r
43 #define FX_TXTCHARSTYLE_ArabicContext           0x0300\r
44 #define FX_TXTCHARSTYLE_ArabicIndic                     0x0400\r
45 #define FX_TXTCHARSTYLE_ArabicComma                     0x0800\r
46 #define FX_TXTLINEALIGNMENT_Left                                0\r
47 #define FX_TXTLINEALIGNMENT_Center                              1\r
48 #define FX_TXTLINEALIGNMENT_Right                               2\r
49 #define FX_TXTLINEALIGNMENT_Justified                   (1 << 2)\r
50 #define FX_TXTLINEALIGNMENT_Distributed                 (2 << 2)\r
51 #define FX_TXTLINEALIGNMENT_JustifiedLeft               (FX_TXTLINEALIGNMENT_Left | FX_TXTLINEALIGNMENT_Justified)\r
52 #define FX_TXTLINEALIGNMENT_JustifiedCenter             (FX_TXTLINEALIGNMENT_Center | FX_TXTLINEALIGNMENT_Justified)\r
53 #define FX_TXTLINEALIGNMENT_JustifiedRight              (FX_TXTLINEALIGNMENT_Right | FX_TXTLINEALIGNMENT_Justified)\r
54 #define FX_TXTLINEALIGNMENT_DistributedLeft             (FX_TXTLINEALIGNMENT_Left | FX_TXTLINEALIGNMENT_Distributed)\r
55 #define FX_TXTLINEALIGNMENT_DistributedCenter   (FX_TXTLINEALIGNMENT_Center | FX_TXTLINEALIGNMENT_Distributed)\r
56 #define FX_TXTLINEALIGNMENT_DistributedRight    (FX_TXTLINEALIGNMENT_Right | FX_TXTLINEALIGNMENT_Distributed)\r
57 #define FX_TXTLINEALIGNMENT_LowerMask                   0x03\r
58 #define FX_TXTLINEALIGNMENT_HigherMask                  0x0C\r
59 #define FX_TXTBREAK_MinimumTabWidth                             160000\r
60 class IFX_TxtAccess\r
61 {\r
62 public:\r
63     virtual FX_WCHAR    GetChar(FX_LPVOID pIdentity, FX_INT32 index) const = 0;\r
64     virtual FX_INT32    GetWidth(FX_LPVOID pIdentity, FX_INT32 index) const = 0;\r
65 };\r
66 typedef struct _FX_TXTRUN {\r
67     _FX_TXTRUN()\r
68     {\r
69         pAccess                 = NULL;\r
70         pIdentity               = NULL;\r
71         pStr                    = NULL;\r
72         pWidths                 = NULL;\r
73         iLength                 = 0;\r
74         pFont                   = NULL;\r
75         fFontSize               = 12;\r
76         dwStyles                = 0;\r
77         iHorizontalScale = 100;\r
78         iVerticalScale  = 100;\r
79         iCharRotation   = 0;\r
80         dwCharStyles    = 0;\r
81         pRect                   = NULL;\r
82         wLineBreakChar  = L'\n';\r
83         bSkipSpace              = TRUE;\r
84     }\r
85     IFX_TxtAccess       *pAccess;\r
86     FX_LPVOID           pIdentity;\r
87     FX_LPCWSTR          pStr;\r
88     FX_INT32            *pWidths;\r
89     FX_INT32            iLength;\r
90     IFX_Font            *pFont;\r
91     FX_FLOAT            fFontSize;\r
92     FX_DWORD            dwStyles;\r
93     FX_INT32            iHorizontalScale;\r
94     FX_INT32            iVerticalScale;\r
95     FX_INT32            iCharRotation;\r
96     FX_DWORD            dwCharStyles;\r
97     FX_LPCRECTF         pRect;\r
98     FX_WCHAR            wLineBreakChar;\r
99     FX_BOOL                     bSkipSpace;\r
100 } FX_TXTRUN, * FX_LPTXTRUN;\r
101 typedef FX_TXTRUN const * FX_LPCTXTRUN;\r
102 class CFX_TxtPiece : public CFX_Target\r
103 {\r
104 public:\r
105     CFX_TxtPiece() : m_dwStatus(FX_TXTBREAK_PieceBreak)\r
106         , m_iStartPos(0)\r
107         , m_iWidth(-1)\r
108         , m_iStartChar(0)\r
109         , m_iChars(0)\r
110         , m_iBidiLevel(0)\r
111         , m_iBidiPos(0)\r
112         , m_iHorizontalScale(100)\r
113         , m_iVerticalScale(100)\r
114         , m_dwCharStyles(0)\r
115         , m_pChars(NULL)\r
116         , m_pUserData(NULL)\r
117     {\r
118     }\r
119     FX_INT32 GetEndPos() const\r
120     {\r
121         return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth;\r
122     }\r
123     FX_INT32 GetLength() const\r
124     {\r
125         return m_iChars;\r
126     }\r
127     FX_INT32 GetEndChar() const\r
128     {\r
129         return m_iStartChar + m_iChars;\r
130     }\r
131     CFX_TxtChar* GetCharPtr(FX_INT32 index) const\r
132     {\r
133         FXSYS_assert(index > -1 && index < m_iChars && m_pChars != NULL);\r
134         return m_pChars->GetDataPtr(m_iStartChar + index);\r
135     }\r
136     void GetString(FX_LPWSTR pText) const\r
137     {\r
138         FXSYS_assert(pText != NULL);\r
139         FX_INT32 iEndChar = m_iStartChar + m_iChars;\r
140         CFX_Char *pChar;\r
141         for (FX_INT32 i = m_iStartChar; i < iEndChar; i ++) {\r
142             pChar = m_pChars->GetDataPtr(i);\r
143             *pText ++ = (FX_WCHAR)pChar->m_wCharCode;\r
144         }\r
145     }\r
146 \r
147     void GetString(CFX_WideString &wsText) const\r
148     {\r
149         FX_LPWSTR pText = wsText.GetBuffer(m_iChars);\r
150         GetString(pText);\r
151         wsText.ReleaseBuffer(m_iChars);\r
152     }\r
153     void GetWidths(FX_INT32 *pWidths) const\r
154     {\r
155         FXSYS_assert(pWidths != NULL);\r
156         FX_INT32 iEndChar = m_iStartChar + m_iChars;\r
157         CFX_Char *pChar;\r
158         for (FX_INT32 i = m_iStartChar; i < iEndChar; i ++) {\r
159             pChar = m_pChars->GetDataPtr(i);\r
160             *pWidths ++ = pChar->m_iCharWidth;\r
161         }\r
162     }\r
163     FX_DWORD                    m_dwStatus;\r
164     FX_INT32                    m_iStartPos;\r
165     FX_INT32                    m_iWidth;\r
166     FX_INT32                    m_iStartChar;\r
167     FX_INT32                    m_iChars;\r
168     FX_INT32                    m_iBidiLevel;\r
169     FX_INT32                    m_iBidiPos;\r
170     FX_INT32                    m_iHorizontalScale;\r
171     FX_INT32                    m_iVerticalScale;\r
172     FX_DWORD                    m_dwCharStyles;\r
173     CFX_TxtCharArray    *m_pChars;\r
174     FX_LPVOID                   m_pUserData;\r
175 };\r
176 typedef CFX_BaseArrayTemplate<CFX_TxtPiece> CFX_TxtPieceArray;\r
177 class IFX_TxtBreak\r
178 {\r
179 public:\r
180     static IFX_TxtBreak*        Create(FX_DWORD dwPolicies);\r
181     virtual void                        Release() = 0;\r
182     virtual void                        SetLineWidth(FX_FLOAT fLineWidth) = 0;\r
183     virtual void                        SetLinePos(FX_FLOAT fLinePos) = 0;\r
184     virtual FX_DWORD            GetLayoutStyles() const = 0;\r
185     virtual void                        SetLayoutStyles(FX_DWORD dwLayoutStyles) = 0;\r
186     virtual void                        SetFont(IFX_Font *pFont) = 0;\r
187     virtual void                        SetFontSize(FX_FLOAT fFontSize) = 0;\r
188     virtual void                        SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) = 0;\r
189     virtual void                        SetDefaultChar(FX_WCHAR wch) = 0;\r
190     virtual void                        SetParagraphBreakChar(FX_WCHAR wch) = 0;\r
191     virtual void                        SetLineBreakTolerance(FX_FLOAT fTolerance) = 0;\r
192     virtual void                        SetHorizontalScale(FX_INT32 iScale) = 0;\r
193     virtual void                        SetVerticalScale(FX_INT32 iScale) = 0;\r
194     virtual void                        SetCharRotation(FX_INT32 iCharRotation) = 0;\r
195     virtual void                        SetCharSpace(FX_FLOAT fCharSpace) = 0;\r
196     virtual void                        SetAlignment(FX_INT32 iAlignment) = 0;\r
197     virtual FX_DWORD            GetContextCharStyles() const = 0;\r
198     virtual void                        SetContextCharStyles(FX_DWORD dwCharStyles) = 0;\r
199     virtual void                        SetCombWidth(FX_FLOAT fCombWidth) = 0;\r
200     virtual void                        SetUserData(FX_LPVOID pUserData) = 0;\r
201     virtual FX_DWORD                                    AppendChar(FX_WCHAR wch) = 0;\r
202     virtual FX_DWORD                                    EndBreak(FX_DWORD dwStatus = FX_TXTBREAK_PieceBreak) = 0;\r
203     virtual FX_INT32                                    CountBreakChars() const = 0;\r
204     virtual FX_INT32                                    CountBreakPieces() const = 0;\r
205     virtual const CFX_TxtPiece*                 GetBreakPiece(FX_INT32 index) const = 0;\r
206     virtual void                                                ClearBreakPieces() = 0;\r
207     virtual void                        Reset() = 0;\r
208     virtual FX_INT32            GetDisplayPos(FX_LPCTXTRUN pTxtRun, FXTEXT_CHARPOS *pCharPos, FX_BOOL bCharCode = FALSE, CFX_WideString *pWSForms = NULL, FX_AdjustCharDisplayPos pAdjustPos = NULL) const = 0;\r
209     virtual FX_INT32            GetCharRects(FX_LPCTXTRUN pTxtRun, CFX_RectFArray &rtArray, FX_BOOL bCharBBox = FALSE) const = 0;\r
210 };\r
211 #endif\r