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_FGAS_LAYOUT_CFX_RTFBREAK_H_ 8 #define XFA_FGAS_LAYOUT_CFX_RTFBREAK_H_ 9 10 #include <deque> 11 #include <vector> 12 13 #include "core/fxcrt/fx_coordinates.h" 14 #include "core/fxcrt/fx_unicode.h" 15 #include "core/fxcrt/retain_ptr.h" 16 #include "xfa/fgas/layout/cfx_break.h" 17 #include "xfa/fxfa/cxfa_textuserdata.h" 18 19 class CFGAS_GEFont; 20 class FXTEXT_CHARPOS; 21 22 enum class CFX_RTFLineAlignment { 23 Left = 0, 24 Center, 25 Right, 26 Justified, 27 Distributed 28 }; 29 30 struct FX_RTFTEXTOBJ { 31 FX_RTFTEXTOBJ(); 32 ~FX_RTFTEXTOBJ(); 33 34 WideString pStr; 35 std::vector<int32_t> pWidths; 36 RetainPtr<CFGAS_GEFont> pFont; 37 const CFX_RectF* pRect; 38 wchar_t wLineBreakChar; 39 float fFontSize; 40 int32_t iLength; 41 int32_t iBidiLevel; 42 int32_t iHorizontalScale; 43 int32_t iVerticalScale; 44 }; 45 46 class CFX_RTFBreak : public CFX_Break { 47 public: 48 explicit CFX_RTFBreak(uint32_t dwLayoutStyles); 49 ~CFX_RTFBreak() override; 50 51 void SetLineStartPos(float fLinePos); 52 SetAlignment(CFX_RTFLineAlignment align)53 void SetAlignment(CFX_RTFLineAlignment align) { m_iAlignment = align; } 54 void SetUserData(const RetainPtr<CXFA_TextUserData>& pUserData); 55 56 void AddPositionedTab(float fTabPos); 57 58 CFX_BreakType EndBreak(CFX_BreakType dwStatus); 59 60 int32_t GetDisplayPos(const FX_RTFTEXTOBJ* pText, 61 FXTEXT_CHARPOS* pCharPos, 62 bool bCharCode) const; 63 64 CFX_BreakType AppendChar(wchar_t wch); 65 GetCurrentLineForTesting()66 CFX_BreakLine* GetCurrentLineForTesting() const { return m_pCurLine; } 67 68 private: 69 void AppendChar_Combination(CFX_Char* pCurChar); 70 void AppendChar_Tab(CFX_Char* pCurChar); 71 CFX_BreakType AppendChar_Control(CFX_Char* pCurChar); 72 CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar); 73 CFX_BreakType AppendChar_Others(CFX_Char* pCurChar); 74 int32_t GetLastPositionedTab() const; 75 bool GetPositionedTab(int32_t* iTabPos) const; 76 77 int32_t GetBreakPos(std::vector<CFX_Char>& tca, 78 int32_t& iEndPos, 79 bool bAllChars, 80 bool bOnlyBrk); 81 void SplitTextLine(CFX_BreakLine* pCurLine, 82 CFX_BreakLine* pNextLine, 83 bool bAllChars); 84 bool EndBreak_SplitLine(CFX_BreakLine* pNextLine, 85 bool bAllChars, 86 CFX_BreakType dwStatus); 87 void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus); 88 void EndBreak_Alignment(const std::deque<FX_TPO>& tpos, 89 bool bAllChars, 90 CFX_BreakType dwStatus); 91 92 bool m_bPagination; 93 std::vector<int32_t> m_PositionedTabs; 94 CFX_RTFLineAlignment m_iAlignment; 95 RetainPtr<CXFA_TextUserData> m_pUserData; 96 }; 97 98 #endif // XFA_FGAS_LAYOUT_CFX_RTFBREAK_H_ 99