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 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 20 | class CFDE_RenderDevice; |
npm | 9ada2d8 | 2016-08-10 07:51:38 -0700 | [diff] [blame] | 21 | class CFX_RenderDevice; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 22 | class CFX_TxtBreak; |
| 23 | |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 24 | enum class FDE_TextAlignment : uint8_t { |
| 25 | kTopLeft = 0, |
| 26 | kCenterLeft, |
| 27 | kCenter, |
| 28 | kCenterRight |
| 29 | }; |
| 30 | |
| 31 | struct FDE_TextStyle { |
| 32 | FDE_TextStyle() |
| 33 | : single_line_(false), line_wrap_(false), last_line_height_(false) {} |
| 34 | ~FDE_TextStyle() {} |
| 35 | |
| 36 | void Reset() { |
| 37 | single_line_ = false; |
| 38 | line_wrap_ = false; |
| 39 | last_line_height_ = false; |
| 40 | } |
| 41 | |
| 42 | bool single_line_; |
| 43 | bool line_wrap_; |
| 44 | bool last_line_height_; |
| 45 | }; |
| 46 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 47 | struct FDE_TTOPIECE { |
Tom Sepez | 76da884 | 2017-02-06 15:10:48 -0800 | [diff] [blame] | 48 | FDE_TTOPIECE(); |
Tom Sepez | c3f74e9 | 2017-03-02 11:32:19 -0800 | [diff] [blame] | 49 | FDE_TTOPIECE(const FDE_TTOPIECE& that); |
Tom Sepez | 76da884 | 2017-02-06 15:10:48 -0800 | [diff] [blame] | 50 | ~FDE_TTOPIECE(); |
| 51 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 52 | int32_t iStartChar; |
| 53 | int32_t iChars; |
| 54 | uint32_t dwCharStyles; |
| 55 | CFX_RectF rtPiece; |
| 56 | }; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 57 | |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame] | 58 | class CFDE_TTOLine { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 59 | public: |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 60 | CFDE_TTOLine(); |
| 61 | CFDE_TTOLine(const CFDE_TTOLine& ttoLine); |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame] | 62 | ~CFDE_TTOLine(); |
weili | eec3a36 | 2016-06-18 06:25:37 -0700 | [diff] [blame] | 63 | |
Tom Sepez | c3f74e9 | 2017-03-02 11:32:19 -0800 | [diff] [blame] | 64 | bool GetNewReload() const { return m_bNewReload; } |
| 65 | void SetNewReload(bool reload) { m_bNewReload = reload; } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 66 | int32_t AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece); |
| 67 | int32_t GetSize() const; |
| 68 | FDE_TTOPIECE* GetPtrAt(int32_t index); |
| 69 | void RemoveLast(int32_t iCount); |
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: |
Dan Sinclair | 73b492a | 2017-08-14 17:23:25 -0400 | [diff] [blame] | 78 | static bool DrawString(CFX_RenderDevice* device, |
| 79 | FX_ARGB color, |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 80 | const RetainPtr<CFGAS_GEFont>& pFont, |
Dan Sinclair | 8c6dc95 | 2017-08-21 09:50:55 -0400 | [diff] [blame] | 81 | FXTEXT_CHARPOS* pCharPos, |
Dan Sinclair | 73b492a | 2017-08-14 17:23:25 -0400 | [diff] [blame] | 82 | int32_t iCount, |
| 83 | float fFontSize, |
| 84 | const CFX_Matrix* pMatrix); |
| 85 | |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 86 | CFDE_TextOut(); |
Dan Sinclair | 0cb9b8c | 2017-01-10 16:38:10 -0500 | [diff] [blame] | 87 | ~CFDE_TextOut(); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 88 | |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 89 | void SetFont(const RetainPtr<CFGAS_GEFont>& pFont); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 90 | void SetFontSize(float fFontSize); |
Dan Sinclair | 54a8390 | 2017-08-14 11:08:39 -0400 | [diff] [blame] | 91 | void SetTextColor(FX_ARGB color) { m_TxtColor = color; } |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 92 | void SetStyles(const FDE_TextStyle& dwStyles); |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 93 | void SetAlignment(FDE_TextAlignment iAlignment); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 94 | void SetLineSpace(float fLineSpace); |
Dan Sinclair | 54a8390 | 2017-08-14 11:08:39 -0400 | [diff] [blame] | 95 | void SetMatrix(const CFX_Matrix& matrix) { m_Matrix = matrix; } |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 96 | void SetLineBreakTolerance(float fTolerance); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 97 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 98 | void CalcLogicSize(const WideString& str, CFX_SizeF& size); |
| 99 | void CalcLogicSize(const WideString& str, CFX_RectF& rect); |
Dan Sinclair | 73b492a | 2017-08-14 17:23:25 -0400 | [diff] [blame] | 100 | void DrawLogicText(CFX_RenderDevice* device, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 101 | const WideStringView& str, |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 102 | const CFX_RectF& rect); |
Dan Sinclair | 54a8390 | 2017-08-14 11:08:39 -0400 | [diff] [blame] | 103 | int32_t GetTotalLines() const { return m_iTotalLines; } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 104 | |
Dan Sinclair | bccf573 | 2017-03-30 14:10:32 -0400 | [diff] [blame] | 105 | private: |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 106 | bool RetrieveLineWidth(CFX_BreakType dwBreakStatus, |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 107 | float& fStartPos, |
| 108 | float& fWidth, |
| 109 | float& fHeight); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 110 | void LoadText(const WideString& str, const CFX_RectF& rect); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 111 | |
| 112 | void Reload(const CFX_RectF& rect); |
| 113 | void ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect); |
Dan Sinclair | c36fe07 | 2017-03-09 16:58:12 -0500 | [diff] [blame] | 114 | bool RetrievePieces(CFX_BreakType dwBreakStatus, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 115 | int32_t& iStartChar, |
| 116 | int32_t& iPieceWidths, |
| 117 | bool bReload, |
| 118 | const CFX_RectF& rect); |
| 119 | void AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 120 | void DoAlignment(const CFX_RectF& rect); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 121 | int32_t GetDisplayPos(FDE_TTOPIECE* pPiece); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 122 | |
weili | cddf825 | 2016-08-04 15:43:59 -0700 | [diff] [blame] | 123 | std::unique_ptr<CFX_TxtBreak> m_pTxtBreak; |
Dan Sinclair | 0b95042 | 2017-09-21 15:49:49 -0400 | [diff] [blame] | 124 | RetainPtr<CFGAS_GEFont> m_pFont; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 125 | float m_fFontSize; |
| 126 | float m_fLineSpace; |
| 127 | float m_fLinePos; |
| 128 | float m_fTolerance; |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 129 | FDE_TextAlignment m_iAlignment; |
| 130 | FDE_TextStyle m_Styles; |
weili | cddf825 | 2016-08-04 15:43:59 -0700 | [diff] [blame] | 131 | std::vector<int32_t> m_CharWidths; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 132 | FX_ARGB m_TxtColor; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 133 | uint32_t m_dwTxtBkStyles; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 134 | WideString m_wsText; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 135 | CFX_Matrix m_Matrix; |
Tom Sepez | c3f74e9 | 2017-03-02 11:32:19 -0800 | [diff] [blame] | 136 | std::deque<CFDE_TTOLine> m_ttoLines; |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 137 | int32_t m_iCurLine; |
| 138 | int32_t m_iCurPiece; |
| 139 | int32_t m_iTotalLines; |
weili | cddf825 | 2016-08-04 15:43:59 -0700 | [diff] [blame] | 140 | std::vector<FXTEXT_CHARPOS> m_CharPos; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 141 | }; |
| 142 | |
Dan Sinclair | bccf573 | 2017-03-30 14:10:32 -0400 | [diff] [blame] | 143 | #endif // XFA_FDE_CFDE_TEXTOUT_H_ |