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