Home | History | Annotate | Download | only in fde
      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/fxcrt/cfx_char.h"
     15 #include "core/fxge/cfx_defaultrenderdevice.h"
     16 #include "core/fxge/cfx_renderdevice.h"
     17 #include "core/fxge/fx_dib.h"
     18 #include "xfa/fde/cfde_data.h"
     19 
     20 class CFDE_RenderDevice;
     21 class CFGAS_GEFont;
     22 class CFX_RenderDevice;
     23 class CFX_TxtBreak;
     24 
     25 class CFDE_TextOut {
     26  public:
     27   static bool DrawString(CFX_RenderDevice* device,
     28                          FX_ARGB color,
     29                          const RetainPtr<CFGAS_GEFont>& pFont,
     30                          FXTEXT_CHARPOS* pCharPos,
     31                          int32_t iCount,
     32                          float fFontSize,
     33                          const CFX_Matrix* pMatrix);
     34 
     35   CFDE_TextOut();
     36   ~CFDE_TextOut();
     37 
     38   void SetFont(const RetainPtr<CFGAS_GEFont>& pFont);
     39   void SetFontSize(float fFontSize);
     40   void SetTextColor(FX_ARGB color) { m_TxtColor = color; }
     41   void SetStyles(const FDE_TextStyle& dwStyles);
     42   void SetAlignment(FDE_TextAlignment iAlignment);
     43   void SetLineSpace(float fLineSpace);
     44   void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; }
     45   void SetLineBreakTolerance(float fTolerance);
     46 
     47   void CalcLogicSize(const WideString& str, CFX_SizeF& size);
     48   void CalcLogicSize(const WideString& str, CFX_RectF& rect);
     49   void DrawLogicText(CFX_RenderDevice* device,
     50                      const WideStringView& str,
     51                      const CFX_RectF& rect);
     52   int32_t GetTotalLines() const { return m_iTotalLines; }
     53 
     54  private:
     55   class CFDE_TTOLine {
     56    public:
     57     CFDE_TTOLine();
     58     CFDE_TTOLine(const CFDE_TTOLine& ttoLine);
     59     ~CFDE_TTOLine();
     60 
     61     bool GetNewReload() const { return m_bNewReload; }
     62     void SetNewReload(bool reload) { m_bNewReload = reload; }
     63     int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece);
     64     int32_t GetSize() const;
     65     FDE_TTOPIECE* GetPtrAt(int32_t index);
     66     void RemoveLast(int32_t iCount);
     67 
     68    private:
     69     bool m_bNewReload;
     70     std::deque<FDE_TTOPIECE> m_pieces;
     71   };
     72 
     73   bool RetrieveLineWidth(CFX_BreakType dwBreakStatus,
     74                          float& fStartPos,
     75                          float& fWidth,
     76                          float& fHeight);
     77   void LoadText(const WideString& str, const CFX_RectF& rect);
     78 
     79   void Reload(const CFX_RectF& rect);
     80   void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect);
     81   bool RetrievePieces(CFX_BreakType dwBreakStatus,
     82                       int32_t& iStartChar,
     83                       int32_t& iPieceWidths,
     84                       bool bReload,
     85                       const CFX_RectF& rect);
     86   void AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd);
     87   void DoAlignment(const CFX_RectF& rect);
     88   int32_t GetDisplayPos(FDE_TTOPIECE* pPiece);
     89 
     90   std::unique_ptr<CFX_TxtBreak> m_pTxtBreak;
     91   RetainPtr<CFGAS_GEFont> m_pFont;
     92   float m_fFontSize;
     93   float m_fLineSpace;
     94   float m_fLinePos;
     95   float m_fTolerance;
     96   FDE_TextAlignment m_iAlignment;
     97   FDE_TextStyle m_Styles;
     98   std::vector<int32_t> m_CharWidths;
     99   FX_ARGB m_TxtColor;
    100   uint32_t m_dwTxtBkStyles;
    101   WideString m_wsText;
    102   CFX_Matrix m_Matrix;
    103   std::deque<CFDE_TTOLine> m_ttoLines;
    104   int32_t m_iCurLine;
    105   int32_t m_iCurPiece;
    106   int32_t m_iTotalLines;
    107   std::vector<FXTEXT_CHARPOS> m_CharPos;
    108 };
    109 
    110 #endif  // XFA_FDE_CFDE_TEXTOUT_H_
    111