OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ | 7 #ifndef XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ |
8 #define XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ | 8 #define XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ |
9 | 9 |
10 #include "core/fxcrt/include/fx_ucd.h" | 10 #include "core/fxcrt/include/fx_ucd.h" |
11 #include "core/fxge/include/fx_ge.h" | 11 #include "core/fxge/include/fx_ge.h" |
12 #include "xfa/fgas/crt/fgas_memory.h" | 12 #include "xfa/fgas/crt/fgas_memory.h" |
13 #include "xfa/fgas/crt/fgas_utils.h" | 13 #include "xfa/fgas/crt/fgas_utils.h" |
14 #include "xfa/fgas/layout/fgas_textbreak.h" | 14 #include "xfa/fgas/layout/fgas_textbreak.h" |
15 #include "xfa/fgas/layout/fgas_unicode.h" | 15 #include "xfa/fgas/layout/fgas_unicode.h" |
16 | 16 |
| 17 class CFX_ArabicChar; |
17 class IFX_Unknown; | 18 class IFX_Unknown; |
18 class IFX_Font; | 19 class IFX_Font; |
19 | 20 |
20 #define FX_RTFBREAKPOLICY_None 0x00 | 21 #define FX_RTFBREAKPOLICY_None 0x00 |
21 #define FX_RTFBREAKPOLICY_SpaceBreak 0x01 | 22 #define FX_RTFBREAKPOLICY_SpaceBreak 0x01 |
22 #define FX_RTFBREAKPOLICY_NumberBreak 0x02 | 23 #define FX_RTFBREAKPOLICY_NumberBreak 0x02 |
23 #define FX_RTFBREAKPOLICY_InfixBreak 0x04 | 24 #define FX_RTFBREAKPOLICY_InfixBreak 0x04 |
24 #define FX_RTFBREAKPOLICY_TabBreak 0x08 | 25 #define FX_RTFBREAKPOLICY_TabBreak 0x08 |
25 #define FX_RTFBREAKPOLICY_OrphanPositionedTab 0x10 | 26 #define FX_RTFBREAKPOLICY_OrphanPositionedTab 0x10 |
26 #define FX_RTFBREAK_None 0x00 | 27 #define FX_RTFBREAK_None 0x00 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 int32_t m_iFontHeight; | 184 int32_t m_iFontHeight; |
184 int32_t m_iHorizontalScale; | 185 int32_t m_iHorizontalScale; |
185 int32_t m_iVerticalScale; | 186 int32_t m_iVerticalScale; |
186 uint32_t m_dwLayoutStyles; | 187 uint32_t m_dwLayoutStyles; |
187 uint32_t m_dwIdentity; | 188 uint32_t m_dwIdentity; |
188 CFX_RTFCharArray* m_pChars; | 189 CFX_RTFCharArray* m_pChars; |
189 IFX_Unknown* m_pUserData; | 190 IFX_Unknown* m_pUserData; |
190 }; | 191 }; |
191 typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray; | 192 typedef CFX_BaseArrayTemplate<CFX_RTFPiece> CFX_RTFPieceArray; |
192 | 193 |
193 class IFX_RTFBreak { | 194 class CFX_RTFLine { |
194 public: | 195 public: |
195 static IFX_RTFBreak* Create(uint32_t dwPolicies); | 196 CFX_RTFLine() |
196 virtual ~IFX_RTFBreak() {} | 197 : m_LinePieces(16), |
197 virtual void Release() = 0; | 198 m_iStart(0), |
198 virtual void SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd) = 0; | 199 m_iWidth(0), |
199 virtual void SetLineStartPos(FX_FLOAT fLinePos) = 0; | 200 m_iArabicChars(0), |
200 virtual uint32_t GetLayoutStyles() const = 0; | 201 m_iMBCSChars(0) {} |
201 virtual void SetLayoutStyles(uint32_t dwLayoutStyles) = 0; | 202 ~CFX_RTFLine() { RemoveAll(); } |
202 virtual void SetFont(IFX_Font* pFont) = 0; | 203 int32_t CountChars() const { return m_LineChars.GetSize(); } |
203 virtual void SetFontSize(FX_FLOAT fFontSize) = 0; | 204 CFX_RTFChar& GetChar(int32_t index) { |
204 virtual void SetTabWidth(FX_FLOAT fTabWidth) = 0; | 205 FXSYS_assert(index > -1 && index < m_LineChars.GetSize()); |
205 virtual void AddPositionedTab(FX_FLOAT fTabPos) = 0; | 206 return *m_LineChars.GetDataPtr(index); |
206 virtual void SetPositionedTabs(const CFX_FloatArray& tabs) = 0; | 207 } |
207 virtual void ClearPositionedTabs() = 0; | 208 CFX_RTFChar* GetCharPtr(int32_t index) { |
208 virtual void SetDefaultChar(FX_WCHAR wch) = 0; | 209 FXSYS_assert(index > -1 && index < m_LineChars.GetSize()); |
209 virtual void SetLineBreakChar(FX_WCHAR wch) = 0; | 210 return m_LineChars.GetDataPtr(index); |
210 virtual void SetLineBreakTolerance(FX_FLOAT fTolerance) = 0; | 211 } |
211 virtual void SetHorizontalScale(int32_t iScale) = 0; | 212 int32_t CountPieces() const { return m_LinePieces.GetSize(); } |
212 virtual void SetVerticalScale(int32_t iScale) = 0; | 213 CFX_RTFPiece& GetPiece(int32_t index) const { |
213 virtual void SetCharRotation(int32_t iCharRotation) = 0; | 214 FXSYS_assert(index > -1 && index < m_LinePieces.GetSize()); |
214 virtual void SetCharSpace(FX_FLOAT fCharSpace) = 0; | 215 return m_LinePieces.GetAt(index); |
215 virtual void SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace) = 0; | 216 } |
216 virtual void SetReadingOrder(FX_BOOL bRTL = FALSE) = 0; | 217 CFX_RTFPiece* GetPiecePtr(int32_t index) const { |
217 virtual void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left) = 0; | 218 FXSYS_assert(index > -1 && index < m_LinePieces.GetSize()); |
218 virtual void SetUserData(IFX_Unknown* pUserData) = 0; | 219 return m_LinePieces.GetPtrAt(index); |
219 virtual uint32_t AppendChar(FX_WCHAR wch) = 0; | 220 } |
220 virtual uint32_t EndBreak(uint32_t dwStatus = FX_RTFBREAK_PieceBreak) = 0; | 221 int32_t GetLineEnd() const { return m_iStart + m_iWidth; } |
221 virtual int32_t CountBreakPieces() const = 0; | 222 void RemoveAll(FX_BOOL bLeaveMemory = FALSE) { |
222 virtual const CFX_RTFPiece* GetBreakPiece(int32_t index) const = 0; | 223 CFX_RTFChar* pChar; |
223 virtual void GetLineRect(CFX_RectF& rect) const = 0; | 224 IFX_Unknown* pUnknown; |
224 virtual void ClearBreakPieces() = 0; | 225 int32_t iCount = m_LineChars.GetSize(); |
225 virtual void Reset() = 0; | 226 for (int32_t i = 0; i < iCount; i++) { |
226 virtual int32_t GetDisplayPos( | 227 pChar = m_LineChars.GetDataPtr(i); |
227 const FX_RTFTEXTOBJ* pText, | 228 if ((pUnknown = pChar->m_pUserData) != NULL) { |
228 FXTEXT_CHARPOS* pCharPos, | 229 pUnknown->Release(); |
229 FX_BOOL bCharCode = FALSE, | 230 } |
230 CFX_WideString* pWSForms = NULL, | 231 } |
231 FX_AdjustCharDisplayPos pAdjustPos = NULL) const = 0; | 232 m_LineChars.RemoveAll(); |
232 virtual int32_t GetCharRects(const FX_RTFTEXTOBJ* pText, | 233 m_LinePieces.RemoveAll(bLeaveMemory); |
233 CFX_RectFArray& rtArray, | 234 m_iWidth = 0; |
234 FX_BOOL bCharBBox = FALSE) const = 0; | 235 m_iArabicChars = 0; |
| 236 m_iMBCSChars = 0; |
| 237 } |
| 238 CFX_RTFCharArray m_LineChars; |
| 239 CFX_RTFPieceArray m_LinePieces; |
| 240 int32_t m_iStart; |
| 241 int32_t m_iWidth; |
| 242 int32_t m_iArabicChars; |
| 243 int32_t m_iMBCSChars; |
| 244 }; |
| 245 |
| 246 class CFX_RTFBreak { |
| 247 public: |
| 248 CFX_RTFBreak(uint32_t dwPolicies); |
| 249 ~CFX_RTFBreak(); |
| 250 void Release() { delete this; } |
| 251 void SetLineBoundary(FX_FLOAT fLineStart, FX_FLOAT fLineEnd); |
| 252 void SetLineStartPos(FX_FLOAT fLinePos); |
| 253 uint32_t GetLayoutStyles() const { return m_dwLayoutStyles; } |
| 254 void SetLayoutStyles(uint32_t dwLayoutStyles); |
| 255 void SetFont(IFX_Font* pFont); |
| 256 void SetFontSize(FX_FLOAT fFontSize); |
| 257 void SetTabWidth(FX_FLOAT fTabWidth); |
| 258 void AddPositionedTab(FX_FLOAT fTabPos); |
| 259 void SetPositionedTabs(const CFX_FloatArray& tabs); |
| 260 void ClearPositionedTabs(); |
| 261 void SetDefaultChar(FX_WCHAR wch); |
| 262 void SetLineBreakChar(FX_WCHAR wch); |
| 263 void SetLineBreakTolerance(FX_FLOAT fTolerance); |
| 264 void SetHorizontalScale(int32_t iScale); |
| 265 void SetVerticalScale(int32_t iScale); |
| 266 void SetCharRotation(int32_t iCharRotation); |
| 267 void SetCharSpace(FX_FLOAT fCharSpace); |
| 268 void SetWordSpace(FX_BOOL bDefault, FX_FLOAT fWordSpace); |
| 269 void SetReadingOrder(FX_BOOL bRTL = FALSE); |
| 270 void SetAlignment(int32_t iAlignment = FX_RTFLINEALIGNMENT_Left); |
| 271 void SetUserData(IFX_Unknown* pUserData); |
| 272 uint32_t AppendChar(FX_WCHAR wch); |
| 273 uint32_t EndBreak(uint32_t dwStatus = FX_RTFBREAK_PieceBreak); |
| 274 int32_t CountBreakPieces() const; |
| 275 const CFX_RTFPiece* GetBreakPiece(int32_t index) const; |
| 276 void GetLineRect(CFX_RectF& rect) const; |
| 277 void ClearBreakPieces(); |
| 278 void Reset(); |
| 279 int32_t GetDisplayPos(const FX_RTFTEXTOBJ* pText, |
| 280 FXTEXT_CHARPOS* pCharPos, |
| 281 FX_BOOL bCharCode = FALSE, |
| 282 CFX_WideString* pWSForms = NULL, |
| 283 FX_AdjustCharDisplayPos pAdjustPos = NULL) const; |
| 284 int32_t GetCharRects(const FX_RTFTEXTOBJ* pText, |
| 285 CFX_RectFArray& rtArray, |
| 286 FX_BOOL bCharBBox = FALSE) const; |
| 287 uint32_t AppendChar_CharCode(FX_WCHAR wch); |
| 288 uint32_t AppendChar_Combination(CFX_RTFChar* pCurChar, int32_t iRotation); |
| 289 uint32_t AppendChar_Tab(CFX_RTFChar* pCurChar, int32_t iRotation); |
| 290 uint32_t AppendChar_Control(CFX_RTFChar* pCurChar, int32_t iRotation); |
| 291 uint32_t AppendChar_Arabic(CFX_RTFChar* pCurChar, int32_t iRotation); |
| 292 uint32_t AppendChar_Others(CFX_RTFChar* pCurChar, int32_t iRotation); |
| 293 |
| 294 protected: |
| 295 uint32_t m_dwPolicies; |
| 296 CFX_ArabicChar* m_pArabicChar; |
| 297 int32_t m_iBoundaryStart; |
| 298 int32_t m_iBoundaryEnd; |
| 299 uint32_t m_dwLayoutStyles; |
| 300 FX_BOOL m_bPagination; |
| 301 FX_BOOL m_bVertical; |
| 302 FX_BOOL m_bSingleLine; |
| 303 FX_BOOL m_bCharCode; |
| 304 IFX_Font* m_pFont; |
| 305 int32_t m_iFontHeight; |
| 306 int32_t m_iFontSize; |
| 307 int32_t m_iTabWidth; |
| 308 CFX_Int32Array m_PositionedTabs; |
| 309 FX_BOOL m_bOrphanLine; |
| 310 FX_WCHAR m_wDefChar; |
| 311 int32_t m_iDefChar; |
| 312 FX_WCHAR m_wLineBreakChar; |
| 313 int32_t m_iHorizontalScale; |
| 314 int32_t m_iVerticalScale; |
| 315 int32_t m_iLineRotation; |
| 316 int32_t m_iCharRotation; |
| 317 int32_t m_iRotation; |
| 318 int32_t m_iCharSpace; |
| 319 FX_BOOL m_bWordSpace; |
| 320 int32_t m_iWordSpace; |
| 321 FX_BOOL m_bRTL; |
| 322 int32_t m_iAlignment; |
| 323 IFX_Unknown* m_pUserData; |
| 324 uint32_t m_dwCharType; |
| 325 uint32_t m_dwIdentity; |
| 326 CFX_RTFLine m_RTFLine1; |
| 327 CFX_RTFLine m_RTFLine2; |
| 328 CFX_RTFLine* m_pCurLine; |
| 329 int32_t m_iReady; |
| 330 int32_t m_iTolerance; |
| 331 int32_t GetLineRotation(uint32_t dwStyles) const; |
| 332 void SetBreakStatus(); |
| 333 CFX_RTFChar* GetLastChar(int32_t index) const; |
| 334 CFX_RTFLine* GetRTFLine(FX_BOOL bReady) const; |
| 335 CFX_RTFPieceArray* GetRTFPieces(FX_BOOL bReady) const; |
| 336 uint32_t GetUnifiedCharType(uint32_t dwType) const; |
| 337 int32_t GetLastPositionedTab() const; |
| 338 FX_BOOL GetPositionedTab(int32_t& iTabPos) const; |
| 339 int32_t GetBreakPos(CFX_RTFCharArray& tca, |
| 340 int32_t& iEndPos, |
| 341 FX_BOOL bAllChars = FALSE, |
| 342 FX_BOOL bOnlyBrk = FALSE); |
| 343 void SplitTextLine(CFX_RTFLine* pCurLine, |
| 344 CFX_RTFLine* pNextLine, |
| 345 FX_BOOL bAllChars = FALSE); |
| 346 FX_BOOL EndBreak_SplitLine(CFX_RTFLine* pNextLine, |
| 347 FX_BOOL bAllChars, |
| 348 uint32_t dwStatus); |
| 349 void EndBreak_BidiLine(CFX_TPOArray& tpos, uint32_t dwStatus); |
| 350 void EndBreak_Alignment(CFX_TPOArray& tpos, |
| 351 FX_BOOL bAllChars, |
| 352 uint32_t dwStatus); |
235 }; | 353 }; |
236 | 354 |
237 #endif // XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ | 355 #endif // XFA_FGAS_LAYOUT_FGAS_RTFBREAK_H_ |
OLD | NEW |