Home | History | Annotate | Download | only in tto
      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_TTO_FDE_TEXTOUT_H_
      8 #define XFA_FDE_TTO_FDE_TEXTOUT_H_
      9 
     10 #include <deque>
     11 #include <memory>
     12 #include <vector>
     13 
     14 #include "core/fxge/cfx_fxgedevice.h"
     15 #include "core/fxge/cfx_renderdevice.h"
     16 #include "core/fxge/fx_dib.h"
     17 #include "xfa/fde/fde_object.h"
     18 #include "xfa/fgas/crt/fgas_utils.h"
     19 #include "xfa/fgas/font/cfgas_fontmgr.h"
     20 
     21 #define FDE_TTOSTYLE_Underline 0x0001
     22 #define FDE_TTOSTYLE_Strikeout 0x0002
     23 #define FDE_TTOSTYLE_VerticalLayout 0x0004
     24 #define FDE_TTOSTYLE_SingleLine 0x0010
     25 #define FDE_TTOSTYLE_ExpandTab 0x0020
     26 #define FDE_TTOSTYLE_HotKey 0x0040
     27 #define FDE_TTOSTYLE_Ellipsis 0x0080
     28 #define FDE_TTOSTYLE_LineWrap 0x0100
     29 #define FDE_TTOSTYLE_ArabicShapes 0x0200
     30 #define FDE_TTOSTYLE_ArabicContext 0x0800
     31 #define FDE_TTOSTYLE_LastLineHeight 0x1000
     32 #define FDE_TTOALIGNMENT_TopLeft 0
     33 #define FDE_TTOALIGNMENT_TopCenter 1
     34 #define FDE_TTOALIGNMENT_TopRight 2
     35 #define FDE_TTOALIGNMENT_TopAuto 3
     36 #define FDE_TTOALIGNMENT_CenterLeft 4
     37 #define FDE_TTOALIGNMENT_Center 5
     38 #define FDE_TTOALIGNMENT_CenterRight 6
     39 #define FDE_TTOALIGNMENT_CenterAuto 7
     40 #define FDE_TTOALIGNMENT_BottomLeft 8
     41 #define FDE_TTOALIGNMENT_BottomCenter 9
     42 #define FDE_TTOALIGNMENT_BottomRight 10
     43 #define FDE_TTOALIGNMENT_BottomAuto 11
     44 
     45 class CFDE_RenderDevice;
     46 class CFX_RenderDevice;
     47 class CFX_TxtBreak;
     48 struct FX_TXTRUN;
     49 
     50 struct FDE_TTOPIECE {
     51   FDE_TTOPIECE();
     52   FDE_TTOPIECE(const FDE_TTOPIECE& that);
     53   ~FDE_TTOPIECE();
     54 
     55   int32_t iStartChar;
     56   int32_t iChars;
     57   uint32_t dwCharStyles;
     58   CFX_RectF rtPiece;
     59 };
     60 
     61 class CFDE_TTOLine {
     62  public:
     63   CFDE_TTOLine();
     64   CFDE_TTOLine(const CFDE_TTOLine& ttoLine);
     65   ~CFDE_TTOLine();
     66 
     67   bool GetNewReload() const { return m_bNewReload; }
     68   void SetNewReload(bool reload) { m_bNewReload = reload; }
     69   int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece);
     70   int32_t GetSize() const;
     71   FDE_TTOPIECE* GetPtrAt(int32_t index);
     72   void RemoveLast(int32_t iCount);
     73   void RemoveAll();
     74 
     75  private:
     76   bool m_bNewReload;
     77   std::deque<FDE_TTOPIECE> m_pieces;
     78 };
     79 
     80 class CFDE_TextOut {
     81  public:
     82   CFDE_TextOut();
     83   ~CFDE_TextOut();
     84 
     85   void SetFont(const CFX_RetainPtr<CFGAS_GEFont>& pFont);
     86   void SetFontSize(FX_FLOAT fFontSize);
     87   void SetTextColor(FX_ARGB color);
     88   void SetStyles(uint32_t dwStyles);
     89   void SetTabWidth(FX_FLOAT fTabWidth);
     90   void SetEllipsisString(const CFX_WideString& wsEllipsis);
     91   void SetParagraphBreakChar(FX_WCHAR wch);
     92   void SetAlignment(int32_t iAlignment);
     93   void SetLineSpace(FX_FLOAT fLineSpace);
     94   void SetDIBitmap(CFX_DIBitmap* pDIB);
     95   void SetRenderDevice(CFX_RenderDevice* pDevice);
     96   void SetClipRect(const CFX_Rect& rtClip);
     97   void SetClipRect(const CFX_RectF& rtClip);
     98   void SetMatrix(const CFX_Matrix& matrix);
     99   void SetLineBreakTolerance(FX_FLOAT fTolerance);
    100 
    101   void DrawText(const FX_WCHAR* pwsStr, int32_t iLength, int32_t x, int32_t y);
    102   void DrawText(const FX_WCHAR* pwsStr,
    103                 int32_t iLength,
    104                 FX_FLOAT x,
    105                 FX_FLOAT y);
    106   void DrawText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_Rect& rect);
    107   void DrawText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect);
    108 
    109   void SetLogicClipRect(const CFX_RectF& rtClip);
    110   void CalcLogicSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_SizeF& size);
    111   void CalcLogicSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect);
    112   void DrawLogicText(const FX_WCHAR* pwsStr,
    113                      int32_t iLength,
    114                      FX_FLOAT x,
    115                      FX_FLOAT y);
    116   void DrawLogicText(const FX_WCHAR* pwsStr,
    117                      int32_t iLength,
    118                      const CFX_RectF& rect);
    119   int32_t GetTotalLines();
    120 
    121  protected:
    122   void CalcTextSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect);
    123   bool RetrieveLineWidth(uint32_t dwBreakStatus,
    124                          FX_FLOAT& fStartPos,
    125                          FX_FLOAT& fWidth,
    126                          FX_FLOAT& fHeight);
    127   void SetLineWidth(CFX_RectF& rect);
    128   void DrawText(const FX_WCHAR* pwsStr,
    129                 int32_t iLength,
    130                 const CFX_RectF& rect,
    131                 const CFX_RectF& rtClip);
    132   void LoadText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect);
    133   void LoadEllipsis();
    134   void ExpandBuffer(int32_t iSize, int32_t iType);
    135   void RetrieveEllPieces(std::vector<int32_t>* pCharWidths);
    136 
    137   void Reload(const CFX_RectF& rect);
    138   void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect);
    139   bool RetriecePieces(uint32_t dwBreakStatus,
    140                       int32_t& iStartChar,
    141                       int32_t& iPieceWidths,
    142                       bool bReload,
    143                       const CFX_RectF& rect);
    144   void AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd);
    145   void ReplaceWidthEllipsis();
    146   void DoAlignment(const CFX_RectF& rect);
    147   void OnDraw(const CFX_RectF& rtClip);
    148   int32_t GetDisplayPos(FDE_TTOPIECE* pPiece);
    149   int32_t GetCharRects(const FDE_TTOPIECE* pPiece);
    150 
    151   FX_TXTRUN ToTextRun(const FDE_TTOPIECE* pPiece);
    152   void DrawLine(const FDE_TTOPIECE* pPiece, CFDE_Pen* pPen);
    153 
    154   std::unique_ptr<CFX_TxtBreak> m_pTxtBreak;
    155   CFX_RetainPtr<CFGAS_GEFont> m_pFont;
    156   FX_FLOAT m_fFontSize;
    157   FX_FLOAT m_fLineSpace;
    158   FX_FLOAT m_fLinePos;
    159   FX_FLOAT m_fTolerance;
    160   int32_t m_iAlignment;
    161   int32_t m_iTxtBkAlignment;
    162   std::vector<int32_t> m_CharWidths;
    163   std::vector<int32_t> m_EllCharWidths;
    164   FX_WCHAR m_wParagraphBkChar;
    165   FX_ARGB m_TxtColor;
    166   uint32_t m_dwStyles;
    167   uint32_t m_dwTxtBkStyles;
    168   CFX_WideString m_wsEllipsis;
    169   bool m_bElliChanged;
    170   int32_t m_iEllipsisWidth;
    171   CFX_WideString m_wsText;
    172   CFX_RectF m_rtClip;
    173   CFX_RectF m_rtLogicClip;
    174   CFX_Matrix m_Matrix;
    175   std::deque<CFDE_TTOLine> m_ttoLines;
    176   int32_t m_iCurLine;
    177   int32_t m_iCurPiece;
    178   int32_t m_iTotalLines;
    179   std::vector<FXTEXT_CHARPOS> m_CharPos;
    180   std::unique_ptr<CFDE_RenderDevice> m_pRenderDevice;
    181   CFX_ArrayTemplate<int32_t> m_hotKeys;
    182   std::vector<CFX_RectF> m_rectArray;
    183 };
    184 
    185 #endif  // XFA_FDE_TTO_FDE_TEXTOUT_H_
    186