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