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