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