• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_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/fxcrt/retain_ptr.h"
15 #include "core/fxcrt/span.h"
16 #include "core/fxcrt/widestring.h"
17 #include "core/fxge/dib/fx_dib.h"
18 #include "xfa/fde/cfde_data.h"
19 #include "xfa/fgas/layout/cfgas_break.h"
20 #include "xfa/fgas/layout/cfgas_char.h"
21 
22 class CFGAS_GEFont;
23 class CFGAS_TxtBreak;
24 class CFX_RenderDevice;
25 class TextCharPos;
26 
27 namespace pdfium {
28 
29 class CFDE_TextOut {
30  public:
31   static bool DrawString(CFX_RenderDevice* device,
32                          FX_ARGB color,
33                          const RetainPtr<CFGAS_GEFont>& pFont,
34                          span<TextCharPos> pCharPos,
35                          float fFontSize,
36                          const CFX_Matrix& matrix);
37 
38   CFDE_TextOut();
39   ~CFDE_TextOut();
40 
41   void SetFont(RetainPtr<CFGAS_GEFont> pFont);
42   void SetFontSize(float fFontSize);
SetTextColor(FX_ARGB color)43   void SetTextColor(FX_ARGB color) { m_TxtColor = color; }
44   void SetStyles(const FDE_TextStyle& dwStyles);
45   void SetAlignment(FDE_TextAlignment iAlignment);
46   void SetLineSpace(float fLineSpace);
SetMatrix(const CFX_Matrix & matrix)47   void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
48   void SetLineBreakTolerance(float fTolerance);
49 
50   void CalcLogicSize(WideStringView str, CFX_SizeF* pSize);
51   void CalcLogicSize(WideStringView str, CFX_RectF* pRect);
52   void DrawLogicText(CFX_RenderDevice* device,
53                      const WideString& str,
54                      const CFX_RectF& rect);
GetTotalLines()55   int32_t GetTotalLines() const { return m_iTotalLines; }
56 
57  private:
58   struct Piece {
59     Piece();
60     Piece(const Piece& that);
61     ~Piece();
62 
63     size_t start_char = 0;
64     size_t char_count = 0;
65     uint32_t char_styles = 0;
66     CFX_RectF bounds;
67   };
68 
69   class Line {
70    public:
71     Line();
72     Line(const Line& that);
73     ~Line();
74 
new_reload()75     bool new_reload() const { return new_reload_; }
set_new_reload(bool reload)76     void set_new_reload(bool reload) { new_reload_ = reload; }
77 
78     size_t AddPiece(size_t index, const Piece& piece);
79     size_t GetSize() const;
80     const Piece* GetPieceAtIndex(size_t index) const;
81     Piece* GetPieceAtIndex(size_t index);
82     void RemoveLast(size_t count);
83 
84    private:
85     bool new_reload_ = false;
86     std::deque<Piece> pieces_;
87   };
88 
89   bool RetrieveLineWidth(CFGAS_Char::BreakType dwBreakStatus,
90                          float* pStartPos,
91                          float* pWidth,
92                          float* pHeight);
93   void LoadText(const WideString& str, const CFX_RectF& rect);
94 
95   void Reload(const CFX_RectF& rect);
96   void ReloadLinePiece(Line* pLine, const CFX_RectF& rect);
97   bool RetrievePieces(CFGAS_Char::BreakType dwBreakStatus,
98                       bool bReload,
99                       const CFX_RectF& rect,
100                       size_t* pStartChar,
101                       int32_t* pPieceWidths);
102   void AppendPiece(const Piece& piece, bool bNeedReload, bool bEnd);
103   void DoAlignment(const CFX_RectF& rect);
104   size_t GetDisplayPos(const Piece* pPiece);
105 
106   std::unique_ptr<CFGAS_TxtBreak> const m_pTxtBreak;
107   RetainPtr<CFGAS_GEFont> m_pFont;
108   float m_fFontSize = 12.0f;
109   float m_fLineSpace = 12.0f;
110   float m_fLinePos = 0.0f;
111   float m_fTolerance = 0.0f;
112   FDE_TextAlignment m_iAlignment = FDE_TextAlignment::kTopLeft;
113   FDE_TextStyle m_Styles;
114   std::vector<int32_t> m_CharWidths;
115   FX_ARGB m_TxtColor = 0xFF000000;
116   Mask<CFGAS_Break::LayoutStyle> m_dwTxtBkStyles;
117   WideString m_wsText;
118   CFX_Matrix m_Matrix;
119   std::deque<Line> m_ttoLines;
120   size_t m_iCurLine = 0;
121   size_t m_iCurPiece = 0;
122   int32_t m_iTotalLines = 0;
123   std::vector<TextCharPos> m_CharPos;
124 };
125 
126 }  // namespace pdfium
127 
128 // TODO(crbug.com/42271761): Remove.
129 using pdfium::CFDE_TextOut;
130 
131 #endif  // XFA_FDE_CFDE_TEXTOUT_H_
132