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 
18 class CFGAS_GEFont;
19 class CFX_TextUserData;
20 class CFX_TextPiece;
21 class TextCharPos;
22 
23 enum class CFX_RTFLineAlignment {
24   Left = 0,
25   Center,
26   Right,
27   Justified,
28   Distributed
29 };
30 
31 class CFX_RTFBreak final : public CFX_Break {
32  public:
33   explicit CFX_RTFBreak(uint32_t dwLayoutStyles);
34   ~CFX_RTFBreak() override;
35 
36   void SetLineStartPos(float fLinePos);
37 
SetAlignment(CFX_RTFLineAlignment align)38   void SetAlignment(CFX_RTFLineAlignment align) { m_iAlignment = align; }
39   void SetUserData(const RetainPtr<CFX_TextUserData>& pUserData);
40 
41   void AddPositionedTab(float fTabPos);
42 
43   CFX_BreakType EndBreak(CFX_BreakType dwStatus);
44 
45   size_t GetDisplayPos(const CFX_TextPiece* pPiece,
46                        std::vector<TextCharPos>* pCharPos) const;
47 
48   CFX_BreakType AppendChar(wchar_t wch);
49 
50  private:
51   void AppendChar_Combination(CFX_Char* pCurChar);
52   void AppendChar_Tab(CFX_Char* pCurChar);
53   CFX_BreakType AppendChar_Control(CFX_Char* pCurChar);
54   CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar);
55   CFX_BreakType AppendChar_Others(CFX_Char* pCurChar);
56   bool GetPositionedTab(int32_t* iTabPos) const;
57 
58   int32_t GetBreakPos(std::vector<CFX_Char>& tca,
59                       bool bAllChars,
60                       bool bOnlyBrk,
61                       int32_t* pEndPos);
62   void SplitTextLine(CFX_BreakLine* pCurLine,
63                      CFX_BreakLine* pNextLine,
64                      bool bAllChars);
65   bool EndBreak_SplitLine(CFX_BreakLine* pNextLine,
66                           bool bAllChars,
67                           CFX_BreakType dwStatus);
68   void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus);
69   void EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
70                           bool bAllChars,
71                           CFX_BreakType dwStatus);
72 
73   bool m_bPagination;
74   std::vector<int32_t> m_PositionedTabs;
75   CFX_RTFLineAlignment m_iAlignment;
76   RetainPtr<CFX_TextUserData> m_pUserData;
77 };
78 
79 #endif  // XFA_FGAS_LAYOUT_CFX_RTFBREAK_H_
80