• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_FDE_CFDE_TEXTOUT_H_
8 #define XFA_FDE_CFDE_TEXTOUT_H_
9 
10 #include <deque>
11 #include <memory>
12 #include <vector>
13 
14 #include "core/fxge/fx_dib.h"
15 #include "third_party/base/span.h"
16 #include "xfa/fde/cfde_data.h"
17 #include "xfa/fgas/layout/cfx_char.h"
18 
19 class CFDE_RenderDevice;
20 class CFGAS_GEFont;
21 class CFX_RenderDevice;
22 class CFX_TxtBreak;
23 class TextCharPos;
24 
25 struct FDE_TTOPIECE {
26   FDE_TTOPIECE();
27   FDE_TTOPIECE(const FDE_TTOPIECE& that);
28   ~FDE_TTOPIECE();
29 
30   int32_t iStartChar;
31   int32_t iChars;
32   uint32_t dwCharStyles;
33   CFX_RectF rtPiece;
34 };
35 
36 class CFDE_TextOut {
37  public:
38   static bool DrawString(CFX_RenderDevice* device,
39                          FX_ARGB color,
40                          const RetainPtr<CFGAS_GEFont>& pFont,
41                          pdfium::span<TextCharPos> pCharPos,
42                          float fFontSize,
43                          const CFX_Matrix& matrix);
44 
45   CFDE_TextOut();
46   ~CFDE_TextOut();
47 
48   void SetFont(const RetainPtr<CFGAS_GEFont>& pFont);
49   void SetFontSize(float fFontSize);
SetTextColor(FX_ARGB color)50   void SetTextColor(FX_ARGB color) { m_TxtColor = color; }
51   void SetStyles(const FDE_TextStyle& dwStyles);
52   void SetAlignment(FDE_TextAlignment iAlignment);
53   void SetLineSpace(float fLineSpace);
SetMatrix(const CFX_Matrix & matrix)54   void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
55   void SetLineBreakTolerance(float fTolerance);
56 
57   void CalcLogicSize(WideStringView str, CFX_SizeF* pSize);
58   void CalcLogicSize(WideStringView str, CFX_RectF* pRect);
59   void DrawLogicText(CFX_RenderDevice* device,
60                      WideStringView str,
61                      const CFX_RectF& rect);
GetTotalLines()62   int32_t GetTotalLines() const { return m_iTotalLines; }
63 
64  private:
65   class CFDE_TTOLine {
66    public:
67     CFDE_TTOLine();
68     CFDE_TTOLine(const CFDE_TTOLine& ttoLine);
69     ~CFDE_TTOLine();
70 
GetNewReload()71     bool GetNewReload() const { return m_bNewReload; }
SetNewReload(bool reload)72     void SetNewReload(bool reload) { m_bNewReload = reload; }
73     int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece);
74     int32_t GetSize() const;
75     FDE_TTOPIECE* GetPtrAt(int32_t index);
76     void RemoveLast(int32_t iCount);
77 
78    private:
79     bool m_bNewReload;
80     std::deque<FDE_TTOPIECE> m_pieces;
81   };
82 
83   bool RetrieveLineWidth(CFX_BreakType dwBreakStatus,
84                          float* pStartPos,
85                          float* pWidth,
86                          float* pHeight);
87   void LoadText(const WideString& str, const CFX_RectF& rect);
88 
89   void Reload(const CFX_RectF& rect);
90   void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect);
91   bool RetrievePieces(CFX_BreakType dwBreakStatus,
92                       bool bReload,
93                       const CFX_RectF& rect,
94                       int32_t* pStartChar,
95                       int32_t* pPieceWidths);
96   void AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd);
97   void DoAlignment(const CFX_RectF& rect);
98   size_t GetDisplayPos(FDE_TTOPIECE* pPiece);
99 
100   std::unique_ptr<CFX_TxtBreak> const m_pTxtBreak;
101   RetainPtr<CFGAS_GEFont> m_pFont;
102   float m_fFontSize = 12.0f;
103   float m_fLineSpace = 12.0f;
104   float m_fLinePos = 0.0f;
105   float m_fTolerance = 0.0f;
106   FDE_TextAlignment m_iAlignment = FDE_TextAlignment::kTopLeft;
107   FDE_TextStyle m_Styles;
108   std::vector<int32_t> m_CharWidths;
109   FX_ARGB m_TxtColor = 0xFF000000;
110   uint32_t m_dwTxtBkStyles = 0;
111   WideString m_wsText;
112   CFX_Matrix m_Matrix;
113   std::deque<CFDE_TTOLine> m_ttoLines;
114   int32_t m_iCurLine = 0;
115   int32_t m_iCurPiece = 0;
116   int32_t m_iTotalLines = 0;
117   std::vector<TextCharPos> m_CharPos;
118 };
119 
120 #endif  // XFA_FDE_CFDE_TEXTOUT_H_
121