OLD | NEW |
| (Empty) |
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 XFA_SRC_FGAS_LAYOUT_FGAS_RTFBREAK_H_ | |
8 #define XFA_SRC_FGAS_LAYOUT_FGAS_RTFBREAK_H_ | |
9 | |
10 #include "core/include/fxcrt/fx_ucd.h" | |
11 #include "core/include/fxge/fx_ge.h" | |
12 #include "xfa/src/fgas/crt/fgas_memory.h" | |
13 #include "xfa/src/fgas/crt/fgas_utils.h" | |
14 #include "xfa/src/fgas/layout/fgas_textbreak.h" | |
15 #include "xfa/src/fgas/layout/fgas_unicode.h" | |
16 | |
17 class IFX_Unknown; | |
18 class IFX_Font; | |
19 | |
20 #define FX_RTFBREAKPOLICY_None 0x00 | |
21 #define FX_RTFBREAKPOLICY_SpaceBreak 0x01 | |
22 #define FX_RTFBREAKPOLICY_NumberBreak 0x02 | |
23 #define FX_RTFBREAKPOLICY_InfixBreak 0x04 | |
24 #define FX_RTFBREAKPOLICY_TabBreak 0x08 | |
25 #define FX_RTFBREAKPOLICY_OrphanPositionedTab 0x10 | |
26 #define FX_RTFBREAK_None 0x00 | |
27 #define FX_RTFBREAK_PieceBreak 0x01 | |
28 #define FX_RTFBREAK_LineBreak 0x02 | |
29 #define FX_RTFBREAK_ParagraphBreak 0x03 | |
30 #define FX_RTFBREAK_PageBreak 0x04 | |
31 #define FX_RTFLAYOUTSTYLE_Pagination 0x01 | |
32 #define FX_RTFLAYOUTSTYLE_VerticalLayout 0x02 | |
33 #define FX_RTFLAYOUTSTYLE_VerticalChars 0x04 | |
34 #define FX_RTFLAYOUTSTYLE_LineDirection 0x08 | |
35 #define FX_RTFLAYOUTSTYLE_ExpandTab 0x10 | |
36 #define FX_RTFLAYOUTSTYLE_ArabicNumber 0x20 | |
37 #define FX_RTFLAYOUTSTYLE_SingleLine 0x40 | |
38 #define FX_RTFLAYOUTSTYLE_MBCSCode 0x80 | |
39 #define FX_RTFCHARSTYLE_Alignment 0x000F | |
40 #define FX_RTFCHARSTYLE_ArabicNumber 0x0010 | |
41 #define FX_RTFCHARSTYLE_ArabicShadda 0x0020 | |
42 #define FX_RTFCHARSTYLE_OddBidiLevel 0x0040 | |
43 #define FX_RTFCHARSTYLE_RTLReadingOrder 0x0080 | |
44 #define FX_RTFCHARSTYLE_ArabicContext 0x0300 | |
45 #define FX_RTFCHARSTYLE_ArabicIndic 0x0400 | |
46 #define FX_RTFCHARSTYLE_ArabicComma 0x0800 | |
47 #define FX_RTFLINEALIGNMENT_Left 0 | |
48 #define FX_RTFLINEALIGNMENT_Center 1 | |
49 #define FX_RTFLINEALIGNMENT_Right 2 | |
50 #define FX_RTFLINEALIGNMENT_Justified (1 << 2) | |
51 #define FX_RTFLINEALIGNMENT_Distributed (2 << 2) | |
52 #define FX_RTFLINEALIGNMENT_JustifiedLeft \ | |
53 (FX_RTFLINEALIGNMENT_Left | FX_RTFLINEALIGNMENT_Justified) | |
54 #define FX_RTFLINEALIGNMENT_JustifiedCenter \ | |
55 (FX_RTFLINEALIGNMENT_Center | FX_RTFLINEALIGNMENT_Justified) | |
56 #define FX_RTFLINEALIGNMENT_JustifiedRight \ | |
57 (FX_RTFLINEALIGNMENT_Right | FX_RTFLINEALIGNMENT_Justified) | |
58 #define FX_RTFLINEALIGNMENT_DistributedLeft \ | |
59 (FX_RTFLINEALIGNMENT_Left | FX_RTFLINEALIGNMENT_Distributed) | |
60 #define FX_RTFLINEALIGNMENT_DistributedCenter \ | |
61 (FX_RTFLINEALIGNMENT_Center | FX_RTFLINEALIGNMENT_Distributed) | |
62 #define FX_RTFLINEALIGNMENT_DistributedRight \ | |
63 (FX_RTFLINEALIGNMENT_Right | FX_RTFLINEALIGNMENT_Distributed) | |
64 #define FX_RTFLINEALIGNMENT_LowerMask 0x03 | |
65 #define FX_RTFLINEALIGNMENT_HigherMask 0x0C | |
66 | |
67 struct FX_RTFTEXTOBJ { | |
68 FX_RTFTEXTOBJ() { | |
69 pStr = NULL; | |
70 pWidths = NULL; | |
71 iLength = 0; | |
72 pFont = NULL; | |
73 fFontSize = 12.0f; | |
74 dwLayoutStyles = 0; | |
75 iCharRotation = 0; | |
76 iBidiLevel = 0; | |
77 pRect = NULL; | |
78 wLineBreakChar = L'\n'; | |
79 iHorizontalScale = 100; | |
80 iVerticalScale = 100; | |
81 } | |
82 | |
83 const FX_WCHAR* pStr; | |
84 int32_t* pWidths; | |
85 int32_t iLength; | |
86 IFX_Font* pFont; | |
87 FX_FLOAT fFontSize; | |
88 FX_DWORD dwLayoutStyles; | |
89 int32_t iCharRotation; | |
90 int32_t iBidiLevel; | |
91 const CFX_RectF* pRect; | |
92 FX_WCHAR wLineBreakChar; | |
93 int32_t iHorizontalScale; | |
94 int32_t iVerticalScale; | |
95 }; | |
96 | |
97 class CFX_RTFPiece : public CFX_Target { | |
98 public: | |
99 CFX_RTFPiece() | |
100 : m_dwStatus(FX_RTFBREAK_PieceBreak), | |
101 m_iStartPos(0), | |
102 m_iWidth(-1), | |
103 m_iStartChar(0), | |
104 m_iChars(0), | |
105 m_iBidiLevel(0), | |
106 m_iBidiPos(0), | |
107 m_iFontSize(0), | |
108 m_iFontHeight(0), | |
109 m_iHorizontalScale(100), | |
110 m_iVerticalScale(100), | |
111 m_dwLayoutStyles(0), | |
112 m_dwIdentity(0), | |
113 m_pChars(NULL), | |
114 m_pUserData(NULL) {} | |
115 ~CFX_RTFPiece() { Reset(); } | |
116 void AppendChar(const CFX_RTFChar& tc) { | |
117 FXSYS_assert(m_pChars != NULL); | |
118 m_pChars->Add(tc); | |
119 if (m_iWidth < 0) { | |
120 m_iWidth = tc.m_iCharWidth; | |
121 } else { | |
122 m_iWidth += tc.m_iCharWidth; | |
123 } | |
124 m_iChars++; | |
125 } | |
126 int32_t GetEndPos() const { | |
127 return m_iWidth < 0 ? m_iStartPos : m_iStartPos + m_iWidth; | |
128 } | |
129 int32_t GetLength() const { return m_iChars; } | |
130 int32_t GetEndChar() const { return m_iStartChar + m_iChars; } | |
131 CFX_RTFChar& GetChar(int32_t index) { | |
132 FXSYS_assert(index > -1 && index < m_iChars && m_pChars != NULL); | |
133 return *m_pChars->GetDataPtr(m_iStartChar + index); | |
134 } | |
135 CFX_RTFChar* GetCharPtr(int32_t index) const { | |
136 FXSYS_assert(index > -1 && index < m_iChars && m_pChars != NULL); | |
137 return m_pChars->GetDataPtr(m_iStartChar + index); | |
138 } | |
139 void GetString(FX_WCHAR* pText) const { | |
140 FXSYS_assert(pText != NULL); | |
141 int32_t iEndChar = m_iStartChar + m_iChars; | |
142 CFX_RTFChar* pChar; | |
143 for (int32_t i = m_iStartChar; i < iEndChar; i++) { | |
144 pChar = m_pChars->GetDataPtr(i); | |
145 *pText++ = (FX_WCHAR)pChar->m_wCharCode; | |
146 } | |
147 } | |
148 void GetString(CFX_WideString& wsText) const { | |
149 FX_WCHAR* pText = wsText.GetBuffer(m_iChars); | |
150 GetString(pText); | |
151 wsText.ReleaseBuffer(m_iChars); | |
152 } | |
153 void GetWidths(int32_t* pWidths) const { | |
154 FXSYS_assert(pWidths != NULL); | |
155 int32_t iEndChar = m_iStartChar + m_iChars; | |
156 CFX_RTFChar* pChar; | |
157 for (int32_t i = m_iStartChar; i < iEndChar; i++) { | |
158 pChar = m_pChars->GetDataPtr(i); | |
159 *pWidths++ = pChar->m_iCharWidth; | |
160 } | |
161 } | |
162 void Reset() { | |
163 m_dwStatus = FX_RTFBREAK_PieceBreak; | |
164 if (m_iWidth > -1) { | |
165 m_iStartPos += m_iWidth; | |
166 } | |
167 m_iWidth = -1; | |
168 m_iStartChar += m_iChars; | |
169 m_iChars = 0; | |
170 m_iBidiLevel = 0; | |
171 m_iBidiPos = 0; | |
172 m_iHorizontalScale = 100; | |
173 m_iVerticalScale = 100; | |
174 } | |
175 FX_DWORD m_dwStatus; | |
176 int32_t m_iStartPos; | |
177 int32_t m_iWidth; | |
178 int32_t m_iStartChar; | |
179 int32_t m_iChars; | |
180 int32_t m_iBidiLevel; | |
181 int32_t m_iBidiPos; | |
182 int32_t m_iFontSize; | |
183 int32_t m_iFontHeight; | |
184 int32_t m_iHorizontalScale; | |
185 int32_t m_iVerticalScale; | |
186 FX_DWORD m_dwLayoutStyles; | |
187 FX_DWORD m_dwIdentity; | |
188 CFX_RTFCharArray* m_pChars; | |
189 IFX_Unknown* m_pUserData; | |
190 }; | |
191 typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray; | |
192 | |
193 class IFX_RTFBreak { | |
194 public: | |
195 static IFX_RTFBreak* Create(FX_DWORD dwPolicies); | |
196 virtual ~IFX_RTFBreak() {} | |
197 virtual void Release() = 0; | |
198 virtual void SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) = 0; | |
199 virtual void SetLineStartPos(FX_FLOAT fLinePos) = 0; | |
200 virtual FX_DWORD GetLayoutStyles() const = 0; | |
201 virtual void SetLayoutStyles(FX_DWORD dwLayoutStyles) = 0; | |
202 virtual void SetFont(IFX_Font* pFont) = 0; | |
203 virtual void SetFontSize(FX_FLOAT fFontSize) = 0; | |
204 virtual void SetTabWidth(FX_FLOAT fTabWidth) = 0; | |
205 virtual void AddPositionedTab(FX_FLOAT fTabPos) = 0; | |
206 virtual void SetPositionedTabs(const CFX_FloatArray& tabs) = 0; | |
207 virtual void ClearPositionedTabs() = 0; | |
208 virtual void SetDefaultChar(FX_WCHAR wch) = 0; | |
209 virtual void SetLineBreakChar(FX_WCHAR wch) = 0; | |
210 virtual void SetLineBreakTolerance(FX_FLOAT fTolerance) = 0; | |
211 virtual void SetHorizontalScale(int32_t iScale) = 0; | |
212 virtual void SetVerticalScale(int32_t iScale) = 0; | |
213 virtual void SetCharRotation(int32_t iCharRotation) = 0; | |
214 virtual void SetCharSpace(FX_FLOAT fCharSpace) = 0; | |
215 virtual void SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace) = 0; | |
216 virtual void SetReadingOrder(FX_BOOL bRTL = FALSE) = 0; | |
217 virtual void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left) = 0; | |
218 virtual void SetUserData(IFX_Unknown* pUserData) = 0; | |
219 virtual FX_DWORD AppendChar(FX_WCHAR wch) = 0; | |
220 virtual FX_DWORD EndBreak(FX_DWORD dwStatus = FX_RTFBREAK_PieceBreak) = 0; | |
221 virtual int32_t CountBreakPieces() const = 0; | |
222 virtual const CFX_RTFPiece* GetBreakPiece(int32_t index) const = 0; | |
223 virtual void GetLineRect(CFX_RectF& rect) const = 0; | |
224 virtual void ClearBreakPieces() = 0; | |
225 virtual void Reset() = 0; | |
226 virtual int32_t GetDisplayPos( | |
227 const FX_RTFTEXTOBJ* pText, | |
228 FXTEXT_CHARPOS* pCharPos, | |
229 FX_BOOL bCharCode = FALSE, | |
230 CFX_WideString* pWSForms = NULL, | |
231 FX_AdjustCharDisplayPos pAdjustPos = NULL) const = 0; | |
232 virtual int32_t GetCharRects(const FX_RTFTEXTOBJ* pText, | |
233 CFX_RectFArray& rtArray, | |
234 FX_BOOL bCharBBox = FALSE) const = 0; | |
235 }; | |
236 | |
237 #endif // XFA_SRC_FGAS_LAYOUT_FGAS_RTFBREAK_H_ | |
OLD | NEW |