• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
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_CFGAS_TXTBREAK_H_
8 #define XFA_FGAS_LAYOUT_CFGAS_TXTBREAK_H_
9 
10 #include <deque>
11 #include <vector>
12 
13 #include "core/fxcrt/fx_coordinates.h"
14 #include "core/fxcrt/retain_ptr.h"
15 #include "xfa/fgas/layout/cfgas_break.h"
16 #include "xfa/fgas/layout/cfgas_char.h"
17 
18 class CFGAS_GEFont;
19 class TextCharPos;
20 
21 #define FX_TXTCHARSTYLE_ArabicShadda 0x0020
22 #define FX_TXTCHARSTYLE_OddBidiLevel 0x0040
23 
24 enum CFX_TxtLineAlignment {
25   CFX_TxtLineAlignment_Left = 0,
26   CFX_TxtLineAlignment_Center = 1 << 0,
27   CFX_TxtLineAlignment_Right = 1 << 1,
28   CFX_TxtLineAlignment_Justified = 1 << 2
29 };
30 
CFX_BreakTypeNoneOrPiece(CFGAS_Char::BreakType type)31 inline bool CFX_BreakTypeNoneOrPiece(CFGAS_Char::BreakType type) {
32   return type == CFGAS_Char::BreakType::kNone ||
33          type == CFGAS_Char::BreakType::kPiece;
34 }
35 
36 class CFGAS_TxtBreak final : public CFGAS_Break {
37  public:
38   class Engine {
39    public:
40     virtual ~Engine();
41     virtual wchar_t GetChar(size_t idx) const = 0;
42     // May return negative for combining characters. Non-const so we can force
43     // a layout if needed.
44     virtual int32_t GetWidthOfChar(size_t idx) = 0;
45   };
46 
47   struct Run {
48     Run();
49     Run(const Run& other);
50     ~Run();
51 
52     CFGAS_TxtBreak::Engine* pEdtEngine = nullptr;
53     WideString wsStr;
54     int32_t* pWidths = nullptr;
55     // TODO(thestig): These 2 members probably should be size_t.
56     int32_t iStart = 0;
57     int32_t iLength = 0;
58     RetainPtr<CFGAS_GEFont> pFont;
59     float fFontSize = 12.0f;
60     Mask<LayoutStyle> dwStyles = LayoutStyle::kNone;
61     int32_t iHorizontalScale = 100;
62     int32_t iVerticalScale = 100;
63     uint32_t dwCharStyles = 0;
64     const CFX_RectF* pRect = nullptr;
65     bool bSkipSpace = true;
66   };
67 
68   CFGAS_TxtBreak();
69   ~CFGAS_TxtBreak() override;
70 
71   void SetLineWidth(float fLineWidth);
72   void SetAlignment(int32_t iAlignment);
73   void SetCombWidth(float fCombWidth);
74   CFGAS_Char::BreakType EndBreak(CFGAS_Char::BreakType dwStatus);
75 
76   size_t GetDisplayPos(const Run& run, TextCharPos* pCharPos) const;
77   std::vector<CFX_RectF> GetCharRects(const Run& run) const;
78   CFGAS_Char::BreakType AppendChar(wchar_t wch);
79 
80  private:
81   void AppendChar_Combination(CFGAS_Char* pCurChar);
82   void AppendChar_Tab(CFGAS_Char* pCurChar);
83   CFGAS_Char::BreakType AppendChar_Control(CFGAS_Char* pCurChar);
84   CFGAS_Char::BreakType AppendChar_Arabic(CFGAS_Char* pCurChar);
85   CFGAS_Char::BreakType AppendChar_Others(CFGAS_Char* pCurChar);
86 
87   void ResetContextCharStyles();
88   void EndBreakSplitLine(CFGAS_BreakLine* pNextLine, bool bAllChars);
89   std::deque<TPO> EndBreakBidiLine(CFGAS_Char::BreakType dwStatus);
90   void EndBreakAlignment(const std::deque<TPO>& tpos,
91                          bool bAllChars,
92                          CFGAS_Char::BreakType dwStatus);
93   int32_t GetBreakPos(std::vector<CFGAS_Char>* pChars,
94                       bool bAllChars,
95                       bool bOnlyBrk,
96                       int32_t* pEndPos);
97   void SplitTextLine(CFGAS_BreakLine* pCurLine,
98                      CFGAS_BreakLine* pNextLine,
99                      bool bAllChars);
100 
101   int32_t m_iAlignment = CFX_TxtLineAlignment_Left;
102   int32_t m_iCombWidth = 360000;
103 };
104 
105 #endif  // XFA_FGAS_LAYOUT_CFGAS_TXTBREAK_H_
106