• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TXTBREAK_H_
8 #define XFA_FGAS_LAYOUT_CFX_TXTBREAK_H_
9 
10 #include <deque>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fxcrt/cfx_char.h"
15 #include "core/fxge/cfx_renderdevice.h"
16 #include "third_party/base/stl_util.h"
17 #include "xfa/fgas/layout/cfx_break.h"
18 
19 class CFDE_TextEditEngine;
20 class CFGAS_GEFont;
21 struct FDE_TEXTEDITPIECE;
22 
23 #define FX_TXTCHARSTYLE_ArabicShadda 0x0020
24 #define FX_TXTCHARSTYLE_OddBidiLevel 0x0040
25 
26 enum CFX_TxtLineAlignment {
27   CFX_TxtLineAlignment_Left = 0,
28   CFX_TxtLineAlignment_Center = 1 << 0,
29   CFX_TxtLineAlignment_Right = 1 << 1,
30   CFX_TxtLineAlignment_Justified = 1 << 2
31 };
32 
CFX_BreakTypeNoneOrPiece(CFX_BreakType type)33 inline bool CFX_BreakTypeNoneOrPiece(CFX_BreakType type) {
34   return type == CFX_BreakType::None || type == CFX_BreakType::Piece;
35 }
36 
37 struct FX_TXTRUN {
38   FX_TXTRUN();
39   FX_TXTRUN(const FX_TXTRUN& other);
40   ~FX_TXTRUN();
41 
42   CFDE_TextEditEngine* pEdtEngine;
43   const FDE_TEXTEDITPIECE* pIdentity;
44   WideString wsStr;
45   int32_t* pWidths;
46   int32_t iLength;
47   RetainPtr<CFGAS_GEFont> pFont;
48   float fFontSize;
49   uint32_t dwStyles;
50   int32_t iHorizontalScale;
51   int32_t iVerticalScale;
52   uint32_t dwCharStyles;
53   const CFX_RectF* pRect;
54   bool bSkipSpace;
55 };
56 
57 class CFX_TxtBreak : public CFX_Break {
58  public:
59   CFX_TxtBreak();
60   ~CFX_TxtBreak() override;
61 
62   void SetLineWidth(float fLineWidth);
63   void SetAlignment(int32_t iAlignment);
64   void SetCombWidth(float fCombWidth);
65   CFX_BreakType EndBreak(CFX_BreakType dwStatus);
66 
67   int32_t GetDisplayPos(const FX_TXTRUN* pTxtRun,
68                         FXTEXT_CHARPOS* pCharPos) const;
69   std::vector<CFX_RectF> GetCharRects(const FX_TXTRUN* pTxtRun,
70                                       bool bCharBBox = false) const;
71   CFX_BreakType AppendChar(wchar_t wch);
72 
73  private:
74   void AppendChar_Combination(CFX_Char* pCurChar);
75   void AppendChar_Tab(CFX_Char* pCurChar);
76   CFX_BreakType AppendChar_Control(CFX_Char* pCurChar);
77   CFX_BreakType AppendChar_Arabic(CFX_Char* pCurChar);
78   CFX_BreakType AppendChar_Others(CFX_Char* pCurChar);
79 
80   void ResetContextCharStyles();
81   bool EndBreak_SplitLine(CFX_BreakLine* pNextLine, bool bAllChars);
82   void EndBreak_BidiLine(std::deque<FX_TPO>* tpos, CFX_BreakType dwStatus);
83   void EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
84                           bool bAllChars,
85                           CFX_BreakType dwStatus);
86   int32_t GetBreakPos(std::vector<CFX_Char>& ca,
87                       int32_t& iEndPos,
88                       bool bAllChars = false,
89                       bool bOnlyBrk = false);
90   void SplitTextLine(CFX_BreakLine* pCurLine,
91                      CFX_BreakLine* pNextLine,
92                      bool bAllChars = false);
93 
94   int32_t m_iAlignment;
95   int32_t m_iCombWidth;
96 };
97 
98 #endif  // XFA_FGAS_LAYOUT_CFX_TXTBREAK_H_
99