• 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_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_rtfbreak.h"
17 #include "xfa/fxfa/cxfa_textparser.h"
18 
19 class CFDE_RenderDevice;
20 class CFX_CSSComputedStyle;
21 class CFX_RenderDevice;
22 class CFX_RTFBreak;
23 class CFX_XMLNode;
24 class CXFA_LinkUserData;
25 class CXFA_LoaderContext;
26 class CXFA_Node;
27 class CXFA_PieceLine;
28 class CXFA_TextPiece;
29 class CXFA_TextProvider;
30 class CXFA_TextTabstopsContext;
31 
32 class CXFA_TextLayout {
33  public:
34   explicit CXFA_TextLayout(CXFA_FFDoc* doc, CXFA_TextProvider* pTextProvider);
35   ~CXFA_TextLayout();
36 
37   float GetLayoutHeight();
38   float StartLayout(float fWidth);
39   float DoLayout(int32_t iBlockIndex,
40                  float fCalcHeight,
41                  float fContentAreaHeight,
42                  float fTextHeight);
43   float Layout(const CFX_SizeF& size);
44 
45   CFX_SizeF CalcSize(const CFX_SizeF& minSize, const CFX_SizeF& maxSize);
46   void ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex);
47   bool DrawString(CFX_RenderDevice* pFxDevice,
48                   const CFX_Matrix& tmDoc2Device,
49                   const CFX_RectF& rtClip,
50                   int32_t iBlock);
IsLoaded()51   bool IsLoaded() const { return !m_pieceLines.empty(); }
52   void Unload();
GetPieceLines()53   const std::vector<std::unique_ptr<CXFA_PieceLine>>* GetPieceLines() const {
54     return &m_pieceLines;
55   }
56 
57   bool m_bHasBlock;
58   std::vector<int32_t> m_Blocks;
59 
60  private:
61   void GetTextDataNode();
62   CFX_XMLNode* GetXMLContainerNode();
63   std::unique_ptr<CFX_RTFBreak> CreateBreak(bool bDefault);
64   void InitBreak(float fLineWidth);
65   void InitBreak(CFX_CSSComputedStyle* pStyle,
66                  CFX_CSSDisplay eDisplay,
67                  float fLineWidth,
68                  CFX_XMLNode* pXMLNode,
69                  CFX_CSSComputedStyle* pParentStyle);
70   bool Loader(float textWidth, float& fLinePos, bool bSavePieces);
71   void LoadText(CXFA_Node* pNode,
72                 float textWidth,
73                 float& fLinePos,
74                 bool bSavePieces);
75   bool LoadRichText(CFX_XMLNode* pXMLNode,
76                     float textWidth,
77                     float& fLinePos,
78                     const RetainPtr<CFX_CSSComputedStyle>& pParentStyle,
79                     bool bSavePieces,
80                     RetainPtr<CXFA_LinkUserData> pLinkData,
81                     bool bEndBreak = true,
82                     bool bIsOl = false,
83                     int32_t iLiCount = 0);
84   bool AppendChar(const WideString& wsText,
85                   float& fLinePos,
86                   float fSpaceAbove,
87                   bool bSavePieces);
88   void AppendTextLine(CFX_BreakType dwStatus,
89                       float& fLinePos,
90                       bool bSavePieces,
91                       bool bEndBreak = false);
92   void EndBreak(CFX_BreakType dwStatus, float& fLinePos, bool bDefault);
93   bool IsEnd(bool bSavePieces);
94   void ProcessText(WideString& wsText);
95   void UpdateAlign(float fHeight, float fBottom);
96   void RenderString(CFX_RenderDevice* pDevice,
97                     CXFA_PieceLine* pPieceLine,
98                     int32_t iPiece,
99                     FXTEXT_CHARPOS* pCharPos,
100                     const CFX_Matrix& tmDoc2Device);
101   void RenderPath(CFX_RenderDevice* pDevice,
102                   CXFA_PieceLine* pPieceLine,
103                   int32_t iPiece,
104                   FXTEXT_CHARPOS* pCharPos,
105                   const CFX_Matrix& tmDoc2Device);
106   int32_t GetDisplayPos(const CXFA_TextPiece* pPiece,
107                         FXTEXT_CHARPOS* pCharPos,
108                         bool bCharCode = false);
109   bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr);
110   void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine);
111   bool Layout(int32_t iBlock);
112   int32_t CountBlocks() const;
113 
114   CXFA_FFDoc* m_pDoc;
115   CXFA_TextProvider* m_pTextProvider;
116   CXFA_Node* m_pTextDataNode;
117   bool m_bRichText;
118   std::unique_ptr<CFX_RTFBreak> m_pBreak;
119   std::unique_ptr<CXFA_LoaderContext> m_pLoader;
120   int32_t m_iLines;
121   float m_fMaxWidth;
122   CXFA_TextParser m_textParser;
123   std::vector<std::unique_ptr<CXFA_PieceLine>> m_pieceLines;
124   std::unique_ptr<CXFA_TextTabstopsContext> m_pTabstopContext;
125   bool m_bBlockContinue;
126 };
127 
128 #endif  // XFA_FXFA_CXFA_TEXTLAYOUT_H_
129