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_FXFA_CXFA_TEXTLAYOUT_H_ 8 #define XFA_FXFA_CXFA_TEXTLAYOUT_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fxcrt/css/cfx_css.h" 14 #include "core/fxcrt/fx_coordinates.h" 15 #include "core/fxcrt/fx_string.h" 16 #include "xfa/fgas/layout/cfx_char.h" 17 #include "xfa/fxfa/cxfa_textparser.h" 18 19 class CFDE_RenderDevice; 20 class CFX_CSSComputedStyle; 21 class CFX_RTFBreak; 22 class CFX_RenderDevice; 23 class CFX_XMLNode; 24 class CFX_LinkUserData; 25 class CXFA_Node; 26 class CXFA_PieceLine; 27 class CXFA_TextPiece; 28 class CXFA_TextProvider; 29 class CXFA_TextTabstopsContext; 30 class TextCharPos; 31 struct CXFA_LoaderContext; 32 struct FX_RTFTEXTOBJ; 33 34 class CXFA_TextLayout { 35 public: 36 CXFA_TextLayout(CXFA_FFDoc* doc, CXFA_TextProvider* pTextProvider); 37 ~CXFA_TextLayout(); 38 39 float GetLayoutHeight(); 40 float StartLayout(float fWidth); 41 float DoLayout(float fTextHeight); 42 float DoSplitLayout(size_t szBlockIndex, 43 float fCalcHeight, 44 float fTextHeight); 45 float Layout(const CFX_SizeF& size); 46 47 CFX_SizeF CalcSize(const CFX_SizeF& minSize, const CFX_SizeF& maxSize); 48 void ItemBlocks(const CFX_RectF& rtText, size_t szBlockIndex); 49 bool DrawString(CFX_RenderDevice* pFxDevice, 50 const CFX_Matrix& mtDoc2Device, 51 const CFX_RectF& rtClip, 52 size_t szBlockIndex); IsLoaded()53 bool IsLoaded() const { return !m_pieceLines.empty(); } 54 void Unload(); 55 GetPieceLines()56 const std::vector<std::unique_ptr<CXFA_PieceLine>>* GetPieceLines() const { 57 return &m_pieceLines; 58 } 59 HasBlock()60 bool HasBlock() const { return m_bHasBlock; } ClearBlocks()61 void ClearBlocks() { m_Blocks.clear(); } ResetHasBlock()62 void ResetHasBlock() { m_bHasBlock = false; } 63 64 private: 65 struct BlockData { 66 size_t szIndex; 67 size_t szLength; 68 }; 69 70 void GetTextDataNode(); 71 CFX_XMLNode* GetXMLContainerNode(); 72 std::unique_ptr<CFX_RTFBreak> CreateBreak(bool bDefault); 73 void InitBreak(float fLineWidth); 74 void InitBreak(CFX_CSSComputedStyle* pStyle, 75 CFX_CSSDisplay eDisplay, 76 float fLineWidth, 77 const CFX_XMLNode* pXMLNode, 78 CFX_CSSComputedStyle* pParentStyle); 79 void Loader(float textWidth, float* pLinePos, bool bSavePieces); 80 void LoadText(CXFA_Node* pNode, 81 float textWidth, 82 float* pLinePos, 83 bool bSavePieces); 84 bool LoadRichText(const CFX_XMLNode* pXMLNode, 85 float textWidth, 86 float* pLinePos, 87 const RetainPtr<CFX_CSSComputedStyle>& pParentStyle, 88 bool bSavePieces, 89 RetainPtr<CFX_LinkUserData> pLinkData, 90 bool bEndBreak, 91 bool bIsOl, 92 int32_t iLiCount); 93 bool AppendChar(const WideString& wsText, 94 float* pLinePos, 95 float fSpaceAbove, 96 bool bSavePieces); 97 void AppendTextLine(CFX_BreakType dwStatus, 98 float* pLinePos, 99 bool bSavePieces, 100 bool bEndBreak); 101 void EndBreak(CFX_BreakType dwStatus, float* pLinePos, bool bDefault); 102 bool IsEnd(bool bSavePieces); 103 void UpdateAlign(float fHeight, float fBottom); 104 void RenderString(CFX_RenderDevice* pDevice, 105 CXFA_PieceLine* pPieceLine, 106 size_t szPiece, 107 std::vector<TextCharPos>* pCharPos, 108 const CFX_Matrix& mtDoc2Device); 109 void RenderPath(CFX_RenderDevice* pDevice, 110 CXFA_PieceLine* pPieceLine, 111 size_t szPiece, 112 std::vector<TextCharPos>* pCharPos, 113 const CFX_Matrix& mtDoc2Device); 114 size_t GetDisplayPos(const CXFA_TextPiece* pPiece, 115 std::vector<TextCharPos>* pCharPos); 116 void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine); 117 bool LayoutInternal(size_t szBlockIndex); 118 size_t CountBlocks() const; 119 size_t GetNextIndexFromLastBlockData() const; 120 void UpdateLoaderHeight(float fTextHeight); 121 122 bool m_bHasBlock = false; 123 bool m_bRichText = false; 124 bool m_bBlockContinue = true; 125 int32_t m_iLines = 0; 126 float m_fMaxWidth = 0; 127 std::vector<BlockData> m_Blocks; 128 UnownedPtr<CXFA_FFDoc> const m_pDoc; 129 CXFA_TextProvider* const m_pTextProvider; // Raw, owned by tree node. 130 CXFA_Node* m_pTextDataNode = nullptr; // Raw, owned by tree node. 131 std::unique_ptr<CFX_RTFBreak> m_pBreak; 132 std::unique_ptr<CXFA_LoaderContext> m_pLoader; 133 CXFA_TextParser m_textParser; 134 std::vector<std::unique_ptr<CXFA_PieceLine>> m_pieceLines; 135 std::unique_ptr<CXFA_TextTabstopsContext> m_pTabstopContext; 136 }; 137 138 #endif // XFA_FXFA_CXFA_TEXTLAYOUT_H_ 139