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