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 _FDE_TEXTOUT_IMP 8 #define _FDE_TEXTOUT_IMP 9 struct FDE_TTOPIECE { 10 public: 11 int32_t iStartChar; 12 int32_t iChars; 13 FX_DWORD dwCharStyles; 14 CFX_RectF rtPiece; 15 }; 16 typedef FDE_TTOPIECE* FDE_LPTTOPIECE; 17 typedef CFX_MassArrayTemplate<FDE_TTOPIECE> CFDE_TTOPieceArray; 18 class CFDE_TTOLine : public CFX_Target { 19 public: 20 CFDE_TTOLine(); 21 CFDE_TTOLine(const CFDE_TTOLine& ttoLine); 22 ~CFDE_TTOLine(); 23 int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece); 24 int32_t GetSize() const; 25 FDE_LPTTOPIECE GetPtrAt(int32_t index); 26 void RemoveLast(int32_t iCount); 27 void RemoveAll(FX_BOOL bLeaveMemory); 28 FX_BOOL m_bNewReload; 29 CFDE_TTOPieceArray m_pieces; 30 31 protected: 32 int32_t m_iPieceCount; 33 }; 34 typedef CFX_ObjectMassArrayTemplate<CFDE_TTOLine> CFDE_TTOLineArray; 35 class CFDE_TextOut : public IFDE_TextOut, public CFX_Target { 36 public: 37 CFDE_TextOut(); 38 ~CFDE_TextOut(); 39 virtual void Release() { delete this; } 40 virtual void SetFont(IFX_Font* pFont); 41 virtual void SetFontSize(FX_FLOAT fFontSize); 42 virtual void SetTextColor(FX_ARGB color); 43 virtual void SetStyles(FX_DWORD dwStyles); 44 virtual void SetTabWidth(FX_FLOAT fTabWidth); 45 virtual void SetEllipsisString(const CFX_WideString& wsEllipsis); 46 virtual void SetParagraphBreakChar(FX_WCHAR wch); 47 virtual void SetAlignment(int32_t iAlignment); 48 virtual void SetLineSpace(FX_FLOAT fLineSpace); 49 virtual void SetDIBitmap(CFX_DIBitmap* pDIB); 50 virtual void SetRenderDevice(CFX_RenderDevice* pDevice); 51 virtual void SetClipRect(const CFX_Rect& rtClip); 52 virtual void SetClipRect(const CFX_RectF& rtClip); 53 virtual void SetMatrix(const CFX_Matrix& matrix); 54 virtual void SetLineBreakTolerance(FX_FLOAT fTolerance); 55 virtual void CalcSize(const FX_WCHAR* pwsStr, 56 int32_t iLength, 57 CFX_Size& size); 58 virtual void CalcSize(const FX_WCHAR* pwsStr, 59 int32_t iLength, 60 CFX_SizeF& size); 61 virtual void CalcSize(const FX_WCHAR* pwsStr, 62 int32_t iLength, 63 CFX_Rect& rect); 64 virtual void CalcSize(const FX_WCHAR* pwsStr, 65 int32_t iLength, 66 CFX_RectF& rect); 67 68 virtual void DrawText(const FX_WCHAR* pwsStr, 69 int32_t iLength, 70 int32_t x, 71 int32_t y); 72 virtual void DrawText(const FX_WCHAR* pwsStr, 73 int32_t iLength, 74 FX_FLOAT x, 75 FX_FLOAT y); 76 virtual void DrawText(const FX_WCHAR* pwsStr, 77 int32_t iLength, 78 const CFX_Rect& rect); 79 virtual void DrawText(const FX_WCHAR* pwsStr, 80 int32_t iLength, 81 const CFX_RectF& rect); 82 83 virtual void SetLogicClipRect(const CFX_RectF& rtClip); 84 virtual void CalcLogicSize(const FX_WCHAR* pwsStr, 85 int32_t iLength, 86 CFX_SizeF& size); 87 virtual void CalcLogicSize(const FX_WCHAR* pwsStr, 88 int32_t iLength, 89 CFX_RectF& rect); 90 virtual void DrawLogicText(const FX_WCHAR* pwsStr, 91 int32_t iLength, 92 FX_FLOAT x, 93 FX_FLOAT y); 94 virtual void DrawLogicText(const FX_WCHAR* pwsStr, 95 int32_t iLength, 96 const CFX_RectF& rect); 97 virtual int32_t GetTotalLines(); 98 99 protected: 100 void CalcTextSize(const FX_WCHAR* pwsStr, int32_t iLength, CFX_RectF& rect); 101 FX_BOOL RetrieveLineWidth(FX_DWORD dwBreakStatus, 102 FX_FLOAT& fStartPos, 103 FX_FLOAT& fWidth, 104 FX_FLOAT& fHeight); 105 void SetLineWidth(CFX_RectF& rect); 106 void DrawText(const FX_WCHAR* pwsStr, 107 int32_t iLength, 108 const CFX_RectF& rect, 109 const CFX_RectF& rtClip); 110 void LoadText(const FX_WCHAR* pwsStr, int32_t iLength, const CFX_RectF& rect); 111 void LoadEllipsis(); 112 void ExpandBuffer(int32_t iSize, int32_t iType); 113 void RetrieveEllPieces(int32_t*& pCharWidths); 114 115 void Reload(const CFX_RectF& rect); 116 void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect); 117 FX_BOOL RetriecePieces(FX_DWORD dwBreakStatus, 118 int32_t& iStartChar, 119 int32_t& iPieceWidths, 120 FX_BOOL bReload, 121 const CFX_RectF& rect); 122 void AppendPiece(const FDE_TTOPIECE& ttoPiece, 123 FX_BOOL bNeedReload, 124 FX_BOOL bEnd); 125 void ReplaceWidthEllipsis(); 126 void DoAlignment(const CFX_RectF& rect); 127 void OnDraw(const CFX_RectF& rtClip); 128 int32_t GetDisplayPos(FDE_LPTTOPIECE pPiece); 129 int32_t GetCharRects(FDE_LPTTOPIECE pPiece); 130 131 void ToTextRun(const FDE_LPTTOPIECE pPiece, FX_TXTRUN& tr); 132 void DrawLine(const FDE_LPTTOPIECE pPiece, IFDE_Pen*& pPen); 133 134 IFX_TxtBreak* m_pTxtBreak; 135 IFX_Font* m_pFont; 136 FX_FLOAT m_fFontSize; 137 FX_FLOAT m_fLineSpace; 138 FX_FLOAT m_fLinePos; 139 FX_FLOAT m_fTolerance; 140 int32_t m_iAlignment; 141 int32_t m_iTxtBkAlignment; 142 int32_t* m_pCharWidths; 143 int32_t m_iChars; 144 int32_t* m_pEllCharWidths; 145 int32_t m_iEllChars; 146 FX_WCHAR m_wParagraphBkChar; 147 FX_ARGB m_TxtColor; 148 FX_DWORD m_dwStyles; 149 FX_DWORD m_dwTxtBkStyles; 150 CFX_WideString m_wsEllipsis; 151 FX_BOOL m_bElliChanged; 152 int32_t m_iEllipsisWidth; 153 CFX_WideString m_wsText; 154 CFX_RectF m_rtClip; 155 CFX_RectF m_rtLogicClip; 156 CFX_Matrix m_Matrix; 157 CFDE_TTOLineArray m_ttoLines; 158 int32_t m_iCurLine; 159 int32_t m_iCurPiece; 160 int32_t m_iTotalLines; 161 FXTEXT_CHARPOS* m_pCharPos; 162 int32_t m_iCharPosSize; 163 IFDE_RenderDevice* m_pRenderDevice; 164 CFX_Int32Array m_hotKeys; 165 CFX_RectFArray m_rectArray; 166 }; 167 #endif 168