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