• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_BREAK_H_
8 #define XFA_FGAS_LAYOUT_CFX_BREAK_H_
9 
10 #include <stdint.h>
11 
12 #include "core/fxcrt/retain_ptr.h"
13 #include "core/fxcrt/unowned_ptr.h"
14 #include "xfa/fgas/layout/cfx_breakline.h"
15 
16 class CFGAS_GEFont;
17 
18 struct FX_TPO {
19   bool operator<(const FX_TPO& that) const { return pos < that.pos; }
20 
21   int32_t index;
22   int32_t pos;
23 };
24 
25 enum FX_LAYOUTSTYLE {
26   FX_LAYOUTSTYLE_None = 0,
27   FX_LAYOUTSTYLE_Pagination = 0x01,
28   FX_LAYOUTSTYLE_ExpandTab = 0x10,
29   FX_LAYOUTSTYLE_SingleLine = 0x200,
30   FX_LAYOUTSTYLE_CombText = 0x400
31 };
32 
33 class CFX_Break {
34  public:
35   virtual ~CFX_Break();
36 
37   void Reset();
38 
39   void SetLayoutStyles(uint32_t dwLayoutStyles);
GetLayoutStyles()40   uint32_t GetLayoutStyles() const { return m_dwLayoutStyles; }
41 
42   void SetFont(const RetainPtr<CFGAS_GEFont>& pFont);
43   void SetFontSize(float fFontSize);
44   void SetTabWidth(float fTabWidth);
GetTabWidth()45   int32_t GetTabWidth() const { return m_iTabWidth; }
46 
47   void SetHorizontalScale(int32_t iScale);
48   void SetVerticalScale(int32_t iScale);
49   void SetLineBreakTolerance(float fTolerance);
50   void SetLineBoundary(float fLineStart, float fLineEnd);
51 
52   void SetCharSpace(float fCharSpace);
53   void SetParagraphBreakChar(wchar_t wch);
54 
55   int32_t CountBreakPieces() const;
56   const CFX_BreakPiece* GetBreakPieceUnstable(int32_t index) const;
57   void ClearBreakPieces();
58 
59   CFX_Char* GetLastChar(int32_t index, bool bOmitChar, bool bRichText) const;
GetCurrentLineForTesting()60   const CFX_BreakLine* GetCurrentLineForTesting() const {
61     return m_pCurLine.Get();
62   }
63 
64  protected:
65   static const int kMinimumTabWidth;
66   static const float kConversionFactor;
67 
68   explicit CFX_Break(uint32_t dwLayoutStyles);
69 
70   void SetBreakStatus();
HasLine()71   bool HasLine() const { return m_iReadyLineIndex >= 0; }
72   bool IsGreaterThanLineWidth(int32_t width) const;
73   FX_CHARTYPE GetUnifiedCharType(FX_CHARTYPE dwType) const;
74 
75   FX_CHARTYPE m_eCharType = FX_CHARTYPE::kUnknown;
76   bool m_bSingleLine = false;
77   bool m_bCombText = false;
78   uint32_t m_dwIdentity = 0;
79   uint32_t m_dwLayoutStyles = 0;
80   int32_t m_iLineStart = 0;
81   int32_t m_iLineWidth = 2000000;
82   wchar_t m_wParagraphBreakChar = L'\n';
83   int32_t m_iFontSize = 240;
84   int32_t m_iTabWidth = 720000;
85   int32_t m_iHorizontalScale = 100;
86   int32_t m_iVerticalScale = 100;
87   int32_t m_iTolerance = 0;
88   int32_t m_iCharSpace = 0;
89   RetainPtr<CFGAS_GEFont> m_pFont;
90   UnownedPtr<CFX_BreakLine> m_pCurLine;
91   int8_t m_iReadyLineIndex = -1;
92   CFX_BreakLine m_Lines[2];
93 };
94 
95 #endif  // XFA_FGAS_LAYOUT_CFX_BREAK_H_
96