OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fde/tto/fde_textout.h" | 7 #include "xfa/fde/tto/fde_textout.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fxcrt/include/fx_coordinates.h" | 11 #include "core/fxcrt/include/fx_coordinates.h" |
12 #include "core/fxcrt/include/fx_system.h" | 12 #include "core/fxcrt/include/fx_system.h" |
13 #include "xfa/fde/cfde_path.h" | 13 #include "xfa/fde/cfde_path.h" |
14 #include "xfa/fde/fde_gedevice.h" | 14 #include "xfa/fde/fde_gedevice.h" |
15 #include "xfa/fde/fde_object.h" | 15 #include "xfa/fde/fde_object.h" |
16 #include "xfa/fgas/crt/fgas_memory.h" | 16 #include "xfa/fgas/crt/fgas_memory.h" |
17 #include "xfa/fgas/crt/fgas_utils.h" | 17 #include "xfa/fgas/crt/fgas_utils.h" |
18 #include "xfa/fgas/layout/fgas_textbreak.h" | 18 #include "xfa/fgas/layout/fgas_textbreak.h" |
19 | 19 |
20 CFDE_TextOut::CFDE_TextOut() | 20 CFDE_TextOut::CFDE_TextOut() |
21 : m_pFont(nullptr), | 21 : m_pTxtBreak(new CFX_TxtBreak(FX_TXTBREAKPOLICY_None)), |
22 m_pFont(nullptr), | |
22 m_fFontSize(12.0f), | 23 m_fFontSize(12.0f), |
23 m_fLineSpace(m_fFontSize), | 24 m_fLineSpace(m_fFontSize), |
24 m_fLinePos(0.0f), | 25 m_fLinePos(0.0f), |
25 m_fTolerance(0.0f), | 26 m_fTolerance(0.0f), |
26 m_iAlignment(0), | 27 m_iAlignment(0), |
27 m_iTxtBkAlignment(0), | 28 m_iTxtBkAlignment(0), |
28 m_pCharWidths(nullptr), | |
29 m_iChars(0), | |
30 m_pEllCharWidths(nullptr), | |
31 m_iEllChars(0), | |
32 m_wParagraphBkChar(L'\n'), | 29 m_wParagraphBkChar(L'\n'), |
33 m_TxtColor(0xFF000000), | 30 m_TxtColor(0xFF000000), |
34 m_dwStyles(0), | 31 m_dwStyles(0), |
35 m_dwTxtBkStyles(0), | 32 m_dwTxtBkStyles(0), |
36 m_bElliChanged(FALSE), | 33 m_bElliChanged(FALSE), |
37 m_iEllipsisWidth(0), | 34 m_iEllipsisWidth(0), |
38 m_ttoLines(5), | 35 m_ttoLines(5), |
39 m_iCurLine(0), | 36 m_iCurLine(0), |
40 m_iCurPiece(0), | 37 m_iCurPiece(0), |
41 m_iTotalLines(0), | 38 m_iTotalLines(0) { |
42 m_pCharPos(nullptr), | |
43 m_iCharPosSize(0) { | |
44 m_pTxtBreak = new CFX_TxtBreak(FX_TXTBREAKPOLICY_None); | |
45 m_Matrix.SetIdentity(); | 39 m_Matrix.SetIdentity(); |
46 m_rtClip.Reset(); | 40 m_rtClip.Reset(); |
47 m_rtLogicClip.Reset(); | 41 m_rtLogicClip.Reset(); |
48 } | 42 } |
43 | |
49 CFDE_TextOut::~CFDE_TextOut() { | 44 CFDE_TextOut::~CFDE_TextOut() { |
50 delete m_pTxtBreak; | |
51 FX_Free(m_pCharWidths); | |
52 FX_Free(m_pEllCharWidths); | |
53 FX_Free(m_pCharPos); | |
54 m_ttoLines.RemoveAll(FALSE); | 45 m_ttoLines.RemoveAll(FALSE); |
55 } | 46 } |
47 | |
56 void CFDE_TextOut::SetFont(CFGAS_GEFont* pFont) { | 48 void CFDE_TextOut::SetFont(CFGAS_GEFont* pFont) { |
57 ASSERT(pFont); | 49 ASSERT(pFont); |
58 m_pFont = pFont; | 50 m_pFont = pFont; |
59 m_pTxtBreak->SetFont(pFont); | 51 m_pTxtBreak->SetFont(pFont); |
60 } | 52 } |
53 | |
61 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { | 54 void CFDE_TextOut::SetFontSize(FX_FLOAT fFontSize) { |
62 ASSERT(fFontSize > 0); | 55 ASSERT(fFontSize > 0); |
63 m_fFontSize = fFontSize; | 56 m_fFontSize = fFontSize; |
64 m_pTxtBreak->SetFontSize(fFontSize); | 57 m_pTxtBreak->SetFontSize(fFontSize); |
65 } | 58 } |
59 | |
66 void CFDE_TextOut::SetTextColor(FX_ARGB color) { | 60 void CFDE_TextOut::SetTextColor(FX_ARGB color) { |
67 m_TxtColor = color; | 61 m_TxtColor = color; |
68 } | 62 } |
63 | |
69 void CFDE_TextOut::SetStyles(uint32_t dwStyles) { | 64 void CFDE_TextOut::SetStyles(uint32_t dwStyles) { |
70 m_dwStyles = dwStyles; | 65 m_dwStyles = dwStyles; |
71 m_dwTxtBkStyles = 0; | 66 m_dwTxtBkStyles = 0; |
72 if (dwStyles & FDE_TTOSTYLE_SingleLine) { | 67 if (dwStyles & FDE_TTOSTYLE_SingleLine) { |
73 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_SingleLine; | 68 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_SingleLine; |
74 } | 69 } |
75 if (dwStyles & FDE_TTOSTYLE_ExpandTab) { | 70 if (dwStyles & FDE_TTOSTYLE_ExpandTab) { |
76 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ExpandTab; | 71 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ExpandTab; |
77 } | 72 } |
78 if (dwStyles & FDE_TTOSTYLE_ArabicShapes) { | 73 if (dwStyles & FDE_TTOSTYLE_ArabicShapes) { |
79 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicShapes; | 74 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicShapes; |
80 } | 75 } |
81 if (dwStyles & FDE_TTOSTYLE_RTL) { | 76 if (dwStyles & FDE_TTOSTYLE_RTL) { |
82 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_RTLReadingOrder; | 77 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_RTLReadingOrder; |
83 } | 78 } |
84 if (dwStyles & FDE_TTOSTYLE_ArabicContext) { | 79 if (dwStyles & FDE_TTOSTYLE_ArabicContext) { |
85 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicContext; | 80 m_dwTxtBkStyles |= FX_TXTLAYOUTSTYLE_ArabicContext; |
86 } | 81 } |
87 if (dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 82 if (dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
88 m_dwTxtBkStyles |= | 83 m_dwTxtBkStyles |= |
89 (FX_TXTLAYOUTSTYLE_VerticalChars | FX_TXTLAYOUTSTYLE_VerticalLayout); | 84 (FX_TXTLAYOUTSTYLE_VerticalChars | FX_TXTLAYOUTSTYLE_VerticalLayout); |
90 } | 85 } |
91 m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); | 86 m_pTxtBreak->SetLayoutStyles(m_dwTxtBkStyles); |
92 } | 87 } |
88 | |
93 void CFDE_TextOut::SetTabWidth(FX_FLOAT fTabWidth) { | 89 void CFDE_TextOut::SetTabWidth(FX_FLOAT fTabWidth) { |
94 ASSERT(fTabWidth > 1.0f); | 90 ASSERT(fTabWidth > 1.0f); |
95 m_pTxtBreak->SetTabWidth(fTabWidth, FALSE); | 91 m_pTxtBreak->SetTabWidth(fTabWidth, FALSE); |
96 } | 92 } |
93 | |
97 void CFDE_TextOut::SetEllipsisString(const CFX_WideString& wsEllipsis) { | 94 void CFDE_TextOut::SetEllipsisString(const CFX_WideString& wsEllipsis) { |
98 m_bElliChanged = TRUE; | 95 m_bElliChanged = TRUE; |
99 m_wsEllipsis = wsEllipsis; | 96 m_wsEllipsis = wsEllipsis; |
100 } | 97 } |
98 | |
101 void CFDE_TextOut::SetParagraphBreakChar(FX_WCHAR wch) { | 99 void CFDE_TextOut::SetParagraphBreakChar(FX_WCHAR wch) { |
102 m_wParagraphBkChar = wch; | 100 m_wParagraphBkChar = wch; |
103 m_pTxtBreak->SetParagraphBreakChar(wch); | 101 m_pTxtBreak->SetParagraphBreakChar(wch); |
104 } | 102 } |
103 | |
105 void CFDE_TextOut::SetAlignment(int32_t iAlignment) { | 104 void CFDE_TextOut::SetAlignment(int32_t iAlignment) { |
106 m_iAlignment = iAlignment; | 105 m_iAlignment = iAlignment; |
107 switch (m_iAlignment) { | 106 switch (m_iAlignment) { |
108 case FDE_TTOALIGNMENT_TopCenter: | 107 case FDE_TTOALIGNMENT_TopCenter: |
109 case FDE_TTOALIGNMENT_Center: | 108 case FDE_TTOALIGNMENT_Center: |
110 case FDE_TTOALIGNMENT_BottomCenter: | 109 case FDE_TTOALIGNMENT_BottomCenter: |
111 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Center; | 110 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Center; |
112 break; | 111 break; |
113 case FDE_TTOALIGNMENT_TopRight: | 112 case FDE_TTOALIGNMENT_TopRight: |
114 case FDE_TTOALIGNMENT_CenterRight: | 113 case FDE_TTOALIGNMENT_CenterRight: |
115 case FDE_TTOALIGNMENT_BottomRight: | 114 case FDE_TTOALIGNMENT_BottomRight: |
116 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Right; | 115 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Right; |
117 break; | 116 break; |
118 default: | 117 default: |
119 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Left; | 118 m_iTxtBkAlignment = FX_TXTLINEALIGNMENT_Left; |
120 break; | 119 break; |
121 } | 120 } |
122 m_pTxtBreak->SetAlignment(m_iTxtBkAlignment); | 121 m_pTxtBreak->SetAlignment(m_iTxtBkAlignment); |
123 } | 122 } |
123 | |
124 void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { | 124 void CFDE_TextOut::SetLineSpace(FX_FLOAT fLineSpace) { |
125 ASSERT(fLineSpace > 1.0f); | 125 ASSERT(fLineSpace > 1.0f); |
126 m_fLineSpace = fLineSpace; | 126 m_fLineSpace = fLineSpace; |
127 } | 127 } |
128 | 128 |
129 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { | 129 void CFDE_TextOut::SetDIBitmap(CFX_DIBitmap* pDIB) { |
130 ASSERT(pDIB); | 130 ASSERT(pDIB); |
131 | 131 |
132 m_pRenderDevice.reset(); | 132 m_pRenderDevice.reset(); |
133 CFX_FxgeDevice* device = new CFX_FxgeDevice; | 133 CFX_FxgeDevice* device = new CFX_FxgeDevice; |
134 device->Attach(pDIB, false, nullptr, false); | 134 device->Attach(pDIB, false, nullptr, false); |
135 m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE)); | 135 m_pRenderDevice.reset(new CFDE_RenderDevice(device, FALSE)); |
136 } | 136 } |
137 | 137 |
138 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { | 138 void CFDE_TextOut::SetRenderDevice(CFX_RenderDevice* pDevice) { |
139 ASSERT(pDevice); | 139 ASSERT(pDevice); |
140 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE)); | 140 m_pRenderDevice.reset(new CFDE_RenderDevice(pDevice, FALSE)); |
141 } | 141 } |
142 | 142 |
143 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { | 143 void CFDE_TextOut::SetClipRect(const CFX_Rect& rtClip) { |
144 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, | 144 m_rtClip.Set((FX_FLOAT)rtClip.left, (FX_FLOAT)rtClip.top, |
145 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); | 145 (FX_FLOAT)rtClip.Width(), (FX_FLOAT)rtClip.Height()); |
146 } | 146 } |
147 | |
147 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { | 148 void CFDE_TextOut::SetClipRect(const CFX_RectF& rtClip) { |
148 m_rtClip = rtClip; | 149 m_rtClip = rtClip; |
149 } | 150 } |
151 | |
150 void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) { | 152 void CFDE_TextOut::SetLogicClipRect(const CFX_RectF& rtClip) { |
151 m_rtLogicClip = rtClip; | 153 m_rtLogicClip = rtClip; |
152 } | 154 } |
155 | |
153 void CFDE_TextOut::SetMatrix(const CFX_Matrix& matrix) { | 156 void CFDE_TextOut::SetMatrix(const CFX_Matrix& matrix) { |
154 m_Matrix = matrix; | 157 m_Matrix = matrix; |
155 } | 158 } |
159 | |
156 void CFDE_TextOut::SetLineBreakTolerance(FX_FLOAT fTolerance) { | 160 void CFDE_TextOut::SetLineBreakTolerance(FX_FLOAT fTolerance) { |
157 m_fTolerance = fTolerance; | 161 m_fTolerance = fTolerance; |
158 m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); | 162 m_pTxtBreak->SetLineBreakTolerance(m_fTolerance); |
159 } | 163 } |
164 | |
160 int32_t CFDE_TextOut::GetTotalLines() { | 165 int32_t CFDE_TextOut::GetTotalLines() { |
161 return m_iTotalLines; | 166 return m_iTotalLines; |
162 } | 167 } |
168 | |
163 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 169 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
164 int32_t iLength, | 170 int32_t iLength, |
165 CFX_Size& size) { | 171 CFX_Size& size) { |
166 CFX_RectF rtText; | 172 CFX_RectF rtText; |
167 rtText.Set(0.0f, 0.0f, (FX_FLOAT)size.x, (FX_FLOAT)size.y); | 173 rtText.Set(0.0f, 0.0f, (FX_FLOAT)size.x, (FX_FLOAT)size.y); |
168 CalcSize(pwsStr, iLength, rtText); | 174 CalcSize(pwsStr, iLength, rtText); |
169 size.x = (int32_t)rtText.Width(); | 175 size.x = (int32_t)rtText.Width(); |
170 size.y = (int32_t)rtText.Height(); | 176 size.y = (int32_t)rtText.Height(); |
171 } | 177 } |
178 | |
172 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 179 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
173 int32_t iLength, | 180 int32_t iLength, |
174 CFX_SizeF& size) { | 181 CFX_SizeF& size) { |
175 CFX_RectF rtText; | 182 CFX_RectF rtText; |
176 rtText.Set(0.0f, 0.0f, size.x, size.y); | 183 rtText.Set(0.0f, 0.0f, size.x, size.y); |
177 CalcSize(pwsStr, iLength, rtText); | 184 CalcSize(pwsStr, iLength, rtText); |
178 size.x = rtText.Width(); | 185 size.x = rtText.Width(); |
179 size.y = rtText.Height(); | 186 size.y = rtText.Height(); |
180 } | 187 } |
188 | |
181 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 189 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
182 int32_t iLength, | 190 int32_t iLength, |
183 CFX_Rect& rect) { | 191 CFX_Rect& rect) { |
184 CFX_RectF rtText; | 192 CFX_RectF rtText; |
185 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.Width(), | 193 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.Width(), |
186 (FX_FLOAT)rect.Height()); | 194 (FX_FLOAT)rect.Height()); |
187 CalcSize(pwsStr, iLength, rtText); | 195 CalcSize(pwsStr, iLength, rtText); |
188 rect.Set((int32_t)rtText.left, (int32_t)rtText.top, (int32_t)rtText.Width(), | 196 rect.Set((int32_t)rtText.left, (int32_t)rtText.top, (int32_t)rtText.Width(), |
189 (int32_t)rtText.Height()); | 197 (int32_t)rtText.Height()); |
190 } | 198 } |
199 | |
191 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, | 200 void CFDE_TextOut::CalcSize(const FX_WCHAR* pwsStr, |
192 int32_t iLength, | 201 int32_t iLength, |
193 CFX_RectF& rect) { | 202 CFX_RectF& rect) { |
194 if (!pwsStr || iLength < 1) { | 203 if (!pwsStr || iLength < 1) { |
195 rect.width = 0.0f; | 204 rect.width = 0.0f; |
196 rect.height = 0.0f; | 205 rect.height = 0.0f; |
197 } else { | 206 } else { |
198 CFX_Matrix rm; | 207 CFX_Matrix rm; |
199 rm.SetReverse(m_Matrix); | 208 rm.SetReverse(m_Matrix); |
200 rm.TransformRect(rect); | 209 rm.TransformRect(rect); |
201 CalcTextSize(pwsStr, iLength, rect); | 210 CalcTextSize(pwsStr, iLength, rect); |
202 m_Matrix.TransformRect(rect); | 211 m_Matrix.TransformRect(rect); |
203 } | 212 } |
204 } | 213 } |
214 | |
205 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, | 215 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, |
206 int32_t iLength, | 216 int32_t iLength, |
207 CFX_SizeF& size) { | 217 CFX_SizeF& size) { |
208 CFX_RectF rtText; | 218 CFX_RectF rtText; |
209 rtText.Set(0.0f, 0.0f, size.x, size.y); | 219 rtText.Set(0.0f, 0.0f, size.x, size.y); |
210 CalcLogicSize(pwsStr, iLength, rtText); | 220 CalcLogicSize(pwsStr, iLength, rtText); |
211 size.x = rtText.Width(); | 221 size.x = rtText.Width(); |
212 size.y = rtText.Height(); | 222 size.y = rtText.Height(); |
213 } | 223 } |
224 | |
214 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, | 225 void CFDE_TextOut::CalcLogicSize(const FX_WCHAR* pwsStr, |
215 int32_t iLength, | 226 int32_t iLength, |
216 CFX_RectF& rect) { | 227 CFX_RectF& rect) { |
217 if (!pwsStr || iLength < 1) { | 228 if (!pwsStr || iLength < 1) { |
218 rect.width = 0.0f; | 229 rect.width = 0.0f; |
219 rect.height = 0.0f; | 230 rect.height = 0.0f; |
220 } else { | 231 } else { |
221 CalcTextSize(pwsStr, iLength, rect); | 232 CalcTextSize(pwsStr, iLength, rect); |
222 } | 233 } |
223 } | 234 } |
235 | |
224 void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, | 236 void CFDE_TextOut::CalcTextSize(const FX_WCHAR* pwsStr, |
225 int32_t iLength, | 237 int32_t iLength, |
226 CFX_RectF& rect) { | 238 CFX_RectF& rect) { |
227 ASSERT(m_pFont && m_fFontSize >= 1.0f); | 239 ASSERT(m_pFont && m_fFontSize >= 1.0f); |
228 SetLineWidth(rect); | 240 SetLineWidth(rect); |
229 m_iTotalLines = 0; | 241 m_iTotalLines = 0; |
230 const FX_WCHAR* pStr = pwsStr; | 242 const FX_WCHAR* pStr = pwsStr; |
231 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 243 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
232 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 244 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
233 FX_FLOAT fWidth = 0.0f; | 245 FX_FLOAT fWidth = 0.0f; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 } else { | 288 } else { |
277 rect.left += fStartPos; | 289 rect.left += fStartPos; |
278 rect.top += fInc; | 290 rect.top += fInc; |
279 rect.width = std::min(fWidth, rect.Width()); | 291 rect.width = std::min(fWidth, rect.Width()); |
280 rect.height = fHeight; | 292 rect.height = fHeight; |
281 if (m_dwStyles & FDE_TTOSTYLE_LastLineHeight) { | 293 if (m_dwStyles & FDE_TTOSTYLE_LastLineHeight) { |
282 rect.height -= m_fLineSpace - m_fFontSize; | 294 rect.height -= m_fLineSpace - m_fFontSize; |
283 } | 295 } |
284 } | 296 } |
285 } | 297 } |
298 | |
286 void CFDE_TextOut::SetLineWidth(CFX_RectF& rect) { | 299 void CFDE_TextOut::SetLineWidth(CFX_RectF& rect) { |
287 if ((m_dwStyles & FDE_TTOSTYLE_SingleLine) == 0) { | 300 if ((m_dwStyles & FDE_TTOSTYLE_SingleLine) == 0) { |
288 FX_FLOAT fLineWidth = 0.0f; | 301 FX_FLOAT fLineWidth = 0.0f; |
289 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 302 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
290 if (rect.Height() < 1.0f) { | 303 if (rect.Height() < 1.0f) { |
291 rect.height = m_fFontSize * 1000.0f; | 304 rect.height = m_fFontSize * 1000.0f; |
292 } | 305 } |
293 fLineWidth = rect.Height(); | 306 fLineWidth = rect.Height(); |
294 } else { | 307 } else { |
295 if (rect.Width() < 1.0f) { | 308 if (rect.Width() < 1.0f) { |
296 rect.width = m_fFontSize * 1000.0f; | 309 rect.width = m_fFontSize * 1000.0f; |
297 } | 310 } |
298 fLineWidth = rect.Width(); | 311 fLineWidth = rect.Width(); |
299 } | 312 } |
300 m_pTxtBreak->SetLineWidth(fLineWidth); | 313 m_pTxtBreak->SetLineWidth(fLineWidth); |
301 } | 314 } |
302 } | 315 } |
316 | |
303 FX_BOOL CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, | 317 FX_BOOL CFDE_TextOut::RetrieveLineWidth(uint32_t dwBreakStatus, |
304 FX_FLOAT& fStartPos, | 318 FX_FLOAT& fStartPos, |
305 FX_FLOAT& fWidth, | 319 FX_FLOAT& fWidth, |
306 FX_FLOAT& fHeight) { | 320 FX_FLOAT& fHeight) { |
307 if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { | 321 if (dwBreakStatus <= FX_TXTBREAK_PieceBreak) { |
308 return FALSE; | 322 return FALSE; |
309 } | 323 } |
310 FX_FLOAT fLineStep = | 324 FX_FLOAT fLineStep = |
311 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 325 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
312 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 326 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
(...skipping 10 matching lines...) Expand all Loading... | |
323 } | 337 } |
324 if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { | 338 if (!bLineWrap && dwBreakStatus == FX_TXTBREAK_LineBreak) { |
325 fWidth += fLineWidth; | 339 fWidth += fLineWidth; |
326 } else { | 340 } else { |
327 fWidth = std::max(fWidth, fLineWidth); | 341 fWidth = std::max(fWidth, fLineWidth); |
328 fHeight += fLineStep; | 342 fHeight += fLineStep; |
329 } | 343 } |
330 m_iTotalLines++; | 344 m_iTotalLines++; |
331 return TRUE; | 345 return TRUE; |
332 } | 346 } |
347 | |
333 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 348 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
334 int32_t iLength, | 349 int32_t iLength, |
335 int32_t x, | 350 int32_t x, |
336 int32_t y) { | 351 int32_t y) { |
337 CFX_RectF rtText; | 352 CFX_RectF rtText; |
338 rtText.Set((FX_FLOAT)x, (FX_FLOAT)y, m_fFontSize * 1000.0f, | 353 rtText.Set((FX_FLOAT)x, (FX_FLOAT)y, m_fFontSize * 1000.0f, |
339 m_fFontSize * 1000.0f); | 354 m_fFontSize * 1000.0f); |
340 DrawText(pwsStr, iLength, rtText); | 355 DrawText(pwsStr, iLength, rtText); |
341 } | 356 } |
357 | |
342 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 358 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
343 int32_t iLength, | 359 int32_t iLength, |
344 FX_FLOAT x, | 360 FX_FLOAT x, |
345 FX_FLOAT y) { | 361 FX_FLOAT y) { |
346 CFX_RectF rtText; | 362 CFX_RectF rtText; |
347 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); | 363 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); |
348 DrawText(pwsStr, iLength, rtText); | 364 DrawText(pwsStr, iLength, rtText); |
349 } | 365 } |
366 | |
350 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 367 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
351 int32_t iLength, | 368 int32_t iLength, |
352 const CFX_Rect& rect) { | 369 const CFX_Rect& rect) { |
353 CFX_RectF rtText; | 370 CFX_RectF rtText; |
354 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.width, | 371 rtText.Set((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, (FX_FLOAT)rect.width, |
355 (FX_FLOAT)rect.height); | 372 (FX_FLOAT)rect.height); |
356 DrawText(pwsStr, iLength, rtText); | 373 DrawText(pwsStr, iLength, rtText); |
357 } | 374 } |
375 | |
358 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 376 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
359 int32_t iLength, | 377 int32_t iLength, |
360 const CFX_RectF& rect) { | 378 const CFX_RectF& rect) { |
361 CFX_RectF rtText; | 379 CFX_RectF rtText; |
362 rtText.Set(rect.left, rect.top, rect.width, rect.height); | 380 rtText.Set(rect.left, rect.top, rect.width, rect.height); |
363 CFX_Matrix rm; | 381 CFX_Matrix rm; |
364 rm.SetReverse(m_Matrix); | 382 rm.SetReverse(m_Matrix); |
365 rm.TransformRect(rtText); | 383 rm.TransformRect(rtText); |
366 DrawText(pwsStr, iLength, rtText, m_rtClip); | 384 DrawText(pwsStr, iLength, rtText, m_rtClip); |
367 } | 385 } |
386 | |
368 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, | 387 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, |
369 int32_t iLength, | 388 int32_t iLength, |
370 FX_FLOAT x, | 389 FX_FLOAT x, |
371 FX_FLOAT y) { | 390 FX_FLOAT y) { |
372 CFX_RectF rtText; | 391 CFX_RectF rtText; |
373 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); | 392 rtText.Set(x, y, m_fFontSize * 1000.0f, m_fFontSize * 1000.0f); |
374 DrawLogicText(pwsStr, iLength, rtText); | 393 DrawLogicText(pwsStr, iLength, rtText); |
375 } | 394 } |
395 | |
376 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, | 396 void CFDE_TextOut::DrawLogicText(const FX_WCHAR* pwsStr, |
377 int32_t iLength, | 397 int32_t iLength, |
378 const CFX_RectF& rect) { | 398 const CFX_RectF& rect) { |
379 CFX_RectF rtClip; | 399 CFX_RectF rtClip; |
380 rtClip.Set(m_rtLogicClip.left, m_rtLogicClip.top, m_rtLogicClip.width, | 400 rtClip.Set(m_rtLogicClip.left, m_rtLogicClip.top, m_rtLogicClip.width, |
381 m_rtLogicClip.height); | 401 m_rtLogicClip.height); |
382 m_Matrix.TransformRect(rtClip); | 402 m_Matrix.TransformRect(rtClip); |
383 DrawText(pwsStr, iLength, rect, rtClip); | 403 DrawText(pwsStr, iLength, rect, rtClip); |
384 } | 404 } |
405 | |
385 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, | 406 void CFDE_TextOut::DrawText(const FX_WCHAR* pwsStr, |
386 int32_t iLength, | 407 int32_t iLength, |
387 const CFX_RectF& rect, | 408 const CFX_RectF& rect, |
388 const CFX_RectF& rtClip) { | 409 const CFX_RectF& rtClip) { |
389 ASSERT(m_pFont && m_fFontSize >= 1.0f); | 410 ASSERT(m_pFont && m_fFontSize >= 1.0f); |
390 if (!pwsStr || iLength < 1) | 411 if (!pwsStr || iLength < 1) |
391 return; | 412 return; |
392 | 413 |
393 if (rect.width < m_fFontSize || rect.height < m_fFontSize) { | 414 if (rect.width < m_fFontSize || rect.height < m_fFontSize) { |
394 return; | 415 return; |
395 } | 416 } |
396 FX_FLOAT fLineWidth = rect.width; | 417 FX_FLOAT fLineWidth = rect.width; |
397 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { | 418 if (m_dwStyles & FDE_TTOSTYLE_VerticalLayout) { |
398 fLineWidth = rect.height; | 419 fLineWidth = rect.height; |
399 } | 420 } |
400 m_pTxtBreak->SetLineWidth(fLineWidth); | 421 m_pTxtBreak->SetLineWidth(fLineWidth); |
401 m_ttoLines.RemoveAll(TRUE); | 422 m_ttoLines.RemoveAll(TRUE); |
402 m_wsText.clear(); | 423 m_wsText.clear(); |
403 LoadText(pwsStr, iLength, rect); | 424 LoadText(pwsStr, iLength, rect); |
404 if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { | 425 if (m_dwStyles & FDE_TTOSTYLE_Ellipsis) { |
405 ReplaceWidthEllipsis(); | 426 ReplaceWidthEllipsis(); |
406 } | 427 } |
407 Reload(rect); | 428 Reload(rect); |
408 DoAlignment(rect); | 429 DoAlignment(rect); |
409 OnDraw(rtClip); | 430 OnDraw(rtClip); |
410 } | 431 } |
432 | |
411 void CFDE_TextOut::ExpandBuffer(int32_t iSize, int32_t iType) { | 433 void CFDE_TextOut::ExpandBuffer(int32_t iSize, int32_t iType) { |
412 switch (iType) { | 434 switch (iType) { |
413 case 0: | 435 case 0: |
414 if (!m_pCharWidths) { | 436 if (m_CharWidths.size() < static_cast<size_t>(iSize)) |
Lei Zhang
2016/08/04 18:09:16
We should make sure iType isn't negative, or chang
Wei Li
2016/08/04 21:42:25
This was stemmed from signed FX_STRSIZE type probl
| |
415 m_pCharWidths = FX_Alloc(int32_t, iSize); | 437 m_CharWidths.resize(iSize, 0); |
416 m_iChars = iSize; | |
417 } else if (m_iChars < iSize) { | |
418 m_pCharWidths = FX_Realloc(int32_t, m_pCharWidths, iSize); | |
419 m_iChars = iSize; | |
420 } | |
421 FXSYS_memset(m_pCharWidths, 0, iSize * sizeof(int32_t)); | |
422 break; | 438 break; |
423 case 1: | 439 case 1: |
424 if (!m_pEllCharWidths) { | 440 if (m_EllCharWidths.size() < static_cast<size_t>(iSize)) |
425 m_pEllCharWidths = FX_Alloc(int32_t, iSize); | 441 m_EllCharWidths.resize(iSize, 0); |
426 m_iEllChars = iSize; | |
427 } else if (m_iEllChars < iSize) { | |
428 m_pEllCharWidths = FX_Realloc(int32_t, m_pEllCharWidths, iSize); | |
429 m_iEllChars = iSize; | |
430 } | |
431 FXSYS_memset(m_pEllCharWidths, 0, iSize * sizeof(int32_t)); | |
432 break; | 442 break; |
433 case 2: | 443 case 2: |
434 if (!m_pCharPos) { | 444 if (m_CharPos.size() < static_cast<size_t>(iSize)) |
435 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iSize); | 445 m_CharPos.resize(iSize, FXTEXT_CHARPOS()); |
436 m_iCharPosSize = iSize; | |
437 } else if (m_iCharPosSize < iSize) { | |
438 m_pCharPos = FX_Realloc(FXTEXT_CHARPOS, m_pCharPos, iSize); | |
439 m_iCharPosSize = iSize; | |
440 } | |
441 break; | 446 break; |
442 } | 447 } |
443 } | 448 } |
449 | |
444 void CFDE_TextOut::LoadEllipsis() { | 450 void CFDE_TextOut::LoadEllipsis() { |
445 if (!m_bElliChanged) { | 451 if (!m_bElliChanged) { |
446 return; | 452 return; |
447 } | 453 } |
448 m_bElliChanged = FALSE; | 454 m_bElliChanged = FALSE; |
449 m_iEllipsisWidth = 0; | 455 m_iEllipsisWidth = 0; |
450 int32_t iLength = m_wsEllipsis.GetLength(); | 456 int32_t iLength = m_wsEllipsis.GetLength(); |
451 if (iLength < 1) { | 457 if (iLength < 1) { |
452 return; | 458 return; |
453 } | 459 } |
454 ExpandBuffer(iLength, 1); | 460 ExpandBuffer(iLength, 1); |
455 const FX_WCHAR* pStr = m_wsEllipsis.c_str(); | 461 const FX_WCHAR* pStr = m_wsEllipsis.c_str(); |
456 int32_t* pCharWidths = m_pEllCharWidths; | |
457 uint32_t dwBreakStatus; | 462 uint32_t dwBreakStatus; |
458 FX_WCHAR wch; | 463 FX_WCHAR wch; |
459 while (iLength-- > 0) { | 464 while (iLength-- > 0) { |
460 wch = *pStr++; | 465 wch = *pStr++; |
461 dwBreakStatus = m_pTxtBreak->AppendChar(wch); | 466 dwBreakStatus = m_pTxtBreak->AppendChar(wch); |
462 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 467 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) |
463 RetrieveEllPieces(pCharWidths); | 468 RetrieveEllPieces(&m_EllCharWidths); |
464 } | |
465 } | 469 } |
466 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 470 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
467 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 471 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) |
468 RetrieveEllPieces(pCharWidths); | 472 RetrieveEllPieces(&m_EllCharWidths); |
469 } | |
470 m_pTxtBreak->Reset(); | 473 m_pTxtBreak->Reset(); |
471 } | 474 } |
472 void CFDE_TextOut::RetrieveEllPieces(int32_t*& pCharWidths) { | 475 |
476 void CFDE_TextOut::RetrieveEllPieces(std::vector<int32_t>* pCharWidths) { | |
473 int32_t iCount = m_pTxtBreak->CountBreakPieces(); | 477 int32_t iCount = m_pTxtBreak->CountBreakPieces(); |
474 CFX_Char* pTC; | 478 int32_t iCharIndex = 0; |
475 for (int32_t i = 0; i < iCount; i++) { | 479 for (int32_t i = 0; i < iCount; i++) { |
476 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); | 480 const CFX_TxtPiece* pPiece = m_pTxtBreak->GetBreakPiece(i); |
477 int32_t iPieceChars = pPiece->GetLength(); | 481 int32_t iPieceChars = pPiece->GetLength(); |
478 for (int32_t j = 0; j < iPieceChars; j++) { | 482 for (int32_t j = 0; j < iPieceChars; j++) { |
479 pTC = pPiece->GetCharPtr(j); | 483 CFX_Char* pTC = pPiece->GetCharPtr(j); |
480 if (pTC->m_iCharWidth <= 0) { | 484 (*pCharWidths)[iCharIndex] = |
481 *pCharWidths = 0; | 485 pTC->m_iCharWidth <= 0 ? 0 : pTC->m_iCharWidth; |
Lei Zhang
2016/08/04 18:09:16
std::max(pTC->m_iCharWidth, 0);
Wei Li
2016/08/04 21:42:25
Done.
| |
482 } else { | 486 m_iEllipsisWidth += (*pCharWidths)[iCharIndex]; |
483 *pCharWidths = pTC->m_iCharWidth; | 487 iCharIndex++; |
484 } | |
485 m_iEllipsisWidth += *pCharWidths; | |
486 pCharWidths++; | |
487 } | 488 } |
488 } | 489 } |
489 m_pTxtBreak->ClearBreakPieces(); | 490 m_pTxtBreak->ClearBreakPieces(); |
490 } | 491 } |
492 | |
491 void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, | 493 void CFDE_TextOut::LoadText(const FX_WCHAR* pwsStr, |
492 int32_t iLength, | 494 int32_t iLength, |
493 const CFX_RectF& rect) { | 495 const CFX_RectF& rect) { |
494 FX_WCHAR* pStr = m_wsText.GetBuffer(iLength); | 496 FX_WCHAR* pStr = m_wsText.GetBuffer(iLength); |
495 int32_t iTxtLength = iLength; | 497 int32_t iTxtLength = iLength; |
496 ExpandBuffer(iTxtLength, 0); | 498 ExpandBuffer(iTxtLength, 0); |
497 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); | 499 FX_BOOL bHotKey = !!(m_dwStyles & FDE_TTOSTYLE_HotKey); |
498 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 500 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
499 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 501 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
500 FX_FLOAT fLineStep = | 502 FX_FLOAT fLineStep = |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 } | 546 } |
545 } | 547 } |
546 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 548 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
547 if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { | 549 if (dwBreakStatus > FX_TXTBREAK_PieceBreak && !bRet) { |
548 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, FALSE, rect); | 550 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, FALSE, rect); |
549 } | 551 } |
550 m_pTxtBreak->ClearBreakPieces(); | 552 m_pTxtBreak->ClearBreakPieces(); |
551 m_pTxtBreak->Reset(); | 553 m_pTxtBreak->Reset(); |
552 m_wsText.ReleaseBuffer(iLength); | 554 m_wsText.ReleaseBuffer(iLength); |
553 } | 555 } |
556 | |
554 FX_BOOL CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, | 557 FX_BOOL CFDE_TextOut::RetriecePieces(uint32_t dwBreakStatus, |
555 int32_t& iStartChar, | 558 int32_t& iStartChar, |
556 int32_t& iPieceWidths, | 559 int32_t& iPieceWidths, |
557 FX_BOOL bReload, | 560 FX_BOOL bReload, |
558 const CFX_RectF& rect) { | 561 const CFX_RectF& rect) { |
559 FX_BOOL bSingleLine = !!(m_dwStyles & FDE_TTOSTYLE_SingleLine); | 562 FX_BOOL bSingleLine = !!(m_dwStyles & FDE_TTOSTYLE_SingleLine); |
560 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); | 563 FX_BOOL bLineWrap = !!(m_dwStyles & FDE_TTOSTYLE_LineWrap); |
561 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 564 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
562 FX_FLOAT fLineStep = | 565 FX_FLOAT fLineStep = |
563 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; | 566 (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize; |
(...skipping 14 matching lines...) Expand all Loading... | |
578 for (; j < iPieceChars; j++) { | 581 for (; j < iPieceChars; j++) { |
579 pTC = pPiece->GetCharPtr(j); | 582 pTC = pPiece->GetCharPtr(j); |
580 int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; | 583 int32_t iCurCharWidth = pTC->m_iCharWidth > 0 ? pTC->m_iCharWidth : 0; |
581 if (bSingleLine || !bLineWrap) { | 584 if (bSingleLine || !bLineWrap) { |
582 if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { | 585 if (iLineWidth - iPieceWidths - iWidth < iCurCharWidth) { |
583 bNeedReload = TRUE; | 586 bNeedReload = TRUE; |
584 break; | 587 break; |
585 } | 588 } |
586 } | 589 } |
587 iWidth += iCurCharWidth; | 590 iWidth += iCurCharWidth; |
588 m_pCharWidths[iChar++] = iCurCharWidth; | 591 m_CharWidths[iChar++] = iCurCharWidth; |
589 } | 592 } |
590 if (j == 0 && !bReload) { | 593 if (j == 0 && !bReload) { |
591 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); | 594 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); |
592 pLine->m_bNewReload = TRUE; | 595 pLine->m_bNewReload = TRUE; |
593 } else if (j > 0) { | 596 } else if (j > 0) { |
594 CFX_RectF rtPiece; | 597 CFX_RectF rtPiece; |
595 if (bVertical) { | 598 if (bVertical) { |
596 rtPiece.left = m_fLinePos; | 599 rtPiece.left = m_fLinePos; |
597 rtPiece.top = rect.top + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; | 600 rtPiece.top = rect.top + (FX_FLOAT)pPiece->m_iStartPos / 20000.0f; |
598 rtPiece.width = fLineStep; | 601 rtPiece.width = fLineStep; |
(...skipping 15 matching lines...) Expand all Loading... | |
614 AppendPiece(ttoPiece, bNeedReload, (bReload && i == iCount - 1)); | 617 AppendPiece(ttoPiece, bNeedReload, (bReload && i == iCount - 1)); |
615 } | 618 } |
616 iStartChar += iPieceChars; | 619 iStartChar += iPieceChars; |
617 iPieceWidths += iWidth; | 620 iPieceWidths += iWidth; |
618 } | 621 } |
619 m_pTxtBreak->ClearBreakPieces(); | 622 m_pTxtBreak->ClearBreakPieces(); |
620 FX_BOOL bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || | 623 FX_BOOL bRet = bSingleLine || bLineWrap || (!bLineWrap && bNeedReload) || |
621 dwBreakStatus == FX_TXTBREAK_ParagraphBreak; | 624 dwBreakStatus == FX_TXTBREAK_ParagraphBreak; |
622 return bRet; | 625 return bRet; |
623 } | 626 } |
627 | |
624 void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, | 628 void CFDE_TextOut::AppendPiece(const FDE_TTOPIECE& ttoPiece, |
625 FX_BOOL bNeedReload, | 629 FX_BOOL bNeedReload, |
626 FX_BOOL bEnd) { | 630 FX_BOOL bEnd) { |
627 if (m_iCurLine >= m_ttoLines.GetSize()) { | 631 if (m_iCurLine >= m_ttoLines.GetSize()) { |
628 CFDE_TTOLine ttoLine; | 632 CFDE_TTOLine ttoLine; |
629 ttoLine.m_bNewReload = bNeedReload; | 633 ttoLine.m_bNewReload = bNeedReload; |
630 m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); | 634 m_iCurPiece = ttoLine.AddPiece(m_iCurPiece, ttoPiece); |
631 m_iCurLine = m_ttoLines.Add(ttoLine); | 635 m_iCurLine = m_ttoLines.Add(ttoLine); |
632 } else { | 636 } else { |
633 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); | 637 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(m_iCurLine); |
634 pLine->m_bNewReload = bNeedReload; | 638 pLine->m_bNewReload = bNeedReload; |
635 m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); | 639 m_iCurPiece = pLine->AddPiece(m_iCurPiece, ttoPiece); |
636 if (bEnd) { | 640 if (bEnd) { |
637 int32_t iPieces = pLine->GetSize(); | 641 int32_t iPieces = pLine->GetSize(); |
638 if (m_iCurPiece < iPieces) { | 642 if (m_iCurPiece < iPieces) { |
639 pLine->RemoveLast(iPieces - m_iCurPiece - 1); | 643 pLine->RemoveLast(iPieces - m_iCurPiece - 1); |
640 } | 644 } |
641 } | 645 } |
642 } | 646 } |
643 if (!bEnd && bNeedReload) { | 647 if (!bEnd && bNeedReload) { |
644 m_iCurPiece = 0; | 648 m_iCurPiece = 0; |
645 } | 649 } |
646 } | 650 } |
651 | |
647 void CFDE_TextOut::ReplaceWidthEllipsis() { | 652 void CFDE_TextOut::ReplaceWidthEllipsis() { |
648 LoadEllipsis(); | 653 LoadEllipsis(); |
649 int32_t iLength = m_wsEllipsis.GetLength(); | 654 int32_t iLength = m_wsEllipsis.GetLength(); |
650 if (iLength < 1) { | 655 if (iLength < 1) { |
651 return; | 656 return; |
652 } | 657 } |
653 int32_t iLines = m_ttoLines.GetSize(); | 658 int32_t iLines = m_ttoLines.GetSize(); |
654 for (int32_t i = 0; i < iLines; i++) { | 659 for (int32_t i = 0; i < iLines; i++) { |
655 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 660 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
656 if (!pLine->m_bNewReload) { | 661 if (!pLine->m_bNewReload) { |
657 continue; | 662 continue; |
658 } | 663 } |
659 int32_t iEllipsisCharIndex = iLength - 1; | 664 int32_t iEllipsisCharIndex = iLength - 1; |
660 int32_t iCharWidth = 0; | 665 int32_t iCharWidth = 0; |
661 int32_t iCharCount = 0; | 666 int32_t iCharCount = 0; |
662 int32_t iPiece = pLine->GetSize(); | 667 int32_t iPiece = pLine->GetSize(); |
663 while (iPiece-- > 0) { | 668 while (iPiece-- > 0) { |
664 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); | 669 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(iPiece); |
665 if (!pPiece) | 670 if (!pPiece) |
666 break; | 671 break; |
667 | 672 |
668 for (int32_t j = pPiece->iChars - 1; j >= 0; j--) { | 673 for (int32_t j = pPiece->iChars - 1; j >= 0; j--) { |
669 if (iEllipsisCharIndex < 0) { | 674 if (iEllipsisCharIndex < 0) { |
670 break; | 675 break; |
671 } | 676 } |
672 int32_t index = pPiece->iStartChar + j; | 677 int32_t index = pPiece->iStartChar + j; |
673 iCharWidth += m_pCharWidths[index]; | 678 iCharWidth += m_CharWidths[index]; |
674 iCharCount++; | 679 iCharCount++; |
675 if (iCharCount <= iLength) { | 680 if (iCharCount <= iLength) { |
676 m_wsText.SetAt(index, m_wsEllipsis.GetAt(iEllipsisCharIndex)); | 681 m_wsText.SetAt(index, m_wsEllipsis.GetAt(iEllipsisCharIndex)); |
677 m_pCharWidths[index] = m_pEllCharWidths[iEllipsisCharIndex]; | 682 m_CharWidths[index] = m_EllCharWidths[iEllipsisCharIndex]; |
678 } else if (iCharWidth <= m_iEllipsisWidth) { | 683 } else if (iCharWidth <= m_iEllipsisWidth) { |
679 m_wsText.SetAt(index, 0); | 684 m_wsText.SetAt(index, 0); |
680 m_pCharWidths[index] = 0; | 685 m_CharWidths[index] = 0; |
681 } | 686 } |
682 iEllipsisCharIndex--; | 687 iEllipsisCharIndex--; |
683 } | 688 } |
684 if (iEllipsisCharIndex < 0) { | 689 if (iEllipsisCharIndex < 0) { |
685 break; | 690 break; |
686 } | 691 } |
687 } | 692 } |
688 } | 693 } |
689 } | 694 } |
695 | |
690 void CFDE_TextOut::Reload(const CFX_RectF& rect) { | 696 void CFDE_TextOut::Reload(const CFX_RectF& rect) { |
691 int32_t iCount = m_ttoLines.GetSize(); | 697 int32_t iCount = m_ttoLines.GetSize(); |
692 for (int32_t i = 0; i < iCount; i++) { | 698 for (int32_t i = 0; i < iCount; i++) { |
693 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 699 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
694 if (!pLine || !pLine->m_bNewReload) | 700 if (!pLine || !pLine->m_bNewReload) |
695 continue; | 701 continue; |
696 | 702 |
697 m_iCurLine = i; | 703 m_iCurLine = i; |
698 m_iCurPiece = 0; | 704 m_iCurPiece = 0; |
699 ReloadLinePiece(pLine, rect); | 705 ReloadLinePiece(pLine, rect); |
700 } | 706 } |
701 } | 707 } |
708 | |
702 void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { | 709 void CFDE_TextOut::ReloadLinePiece(CFDE_TTOLine* pLine, const CFX_RectF& rect) { |
703 const FX_WCHAR* pwsStr = m_wsText.c_str(); | 710 const FX_WCHAR* pwsStr = m_wsText.c_str(); |
704 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 711 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
705 int32_t iPieceWidths = 0; | 712 int32_t iPieceWidths = 0; |
706 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); | 713 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(0); |
707 int32_t iStartChar = pPiece->iStartChar; | 714 int32_t iStartChar = pPiece->iStartChar; |
708 m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; | 715 m_fLinePos = bVertical ? pPiece->rtPiece.left : pPiece->rtPiece.top; |
709 int32_t iPieceCount = pLine->GetSize(); | 716 int32_t iPieceCount = pLine->GetSize(); |
710 int32_t iPieceIndex = 0; | 717 int32_t iPieceIndex = 0; |
711 uint32_t dwBreakStatus = 0; | 718 uint32_t dwBreakStatus = 0; |
(...skipping 11 matching lines...) Expand all Loading... | |
723 } | 730 } |
724 iPieceIndex++; | 731 iPieceIndex++; |
725 pPiece = pLine->GetPtrAt(iPieceIndex); | 732 pPiece = pLine->GetPtrAt(iPieceIndex); |
726 } | 733 } |
727 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); | 734 dwBreakStatus = m_pTxtBreak->EndBreak(FX_TXTBREAK_ParagraphBreak); |
728 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { | 735 if (dwBreakStatus > FX_TXTBREAK_PieceBreak) { |
729 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, TRUE, rect); | 736 RetriecePieces(dwBreakStatus, iStartChar, iPieceWidths, TRUE, rect); |
730 } | 737 } |
731 m_pTxtBreak->Reset(); | 738 m_pTxtBreak->Reset(); |
732 } | 739 } |
740 | |
733 void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { | 741 void CFDE_TextOut::DoAlignment(const CFX_RectF& rect) { |
734 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); | 742 FX_BOOL bVertical = !!(m_dwStyles & FDE_TTOSTYLE_VerticalLayout); |
735 FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); | 743 FX_FLOAT fLineStopS = bVertical ? rect.right() : rect.bottom(); |
736 int32_t iLines = m_ttoLines.GetSize(); | 744 int32_t iLines = m_ttoLines.GetSize(); |
737 if (iLines < 1) | 745 if (iLines < 1) |
738 return; | 746 return; |
739 FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); | 747 FDE_TTOPIECE* pFirstPiece = m_ttoLines.GetPtrAt(iLines - 1)->GetPtrAt(0); |
740 if (!pFirstPiece) | 748 if (!pFirstPiece) |
741 return; | 749 return; |
742 | 750 |
(...skipping 13 matching lines...) Expand all Loading... | |
756 int32_t iPieces = pLine->GetSize(); | 764 int32_t iPieces = pLine->GetSize(); |
757 for (int32_t j = 0; j < iPieces; j++) { | 765 for (int32_t j = 0; j < iPieces; j++) { |
758 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); | 766 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); |
759 if (bVertical) | 767 if (bVertical) |
760 pPiece->rtPiece.left += fInc; | 768 pPiece->rtPiece.left += fInc; |
761 else | 769 else |
762 pPiece->rtPiece.top += fInc; | 770 pPiece->rtPiece.top += fInc; |
763 } | 771 } |
764 } | 772 } |
765 } | 773 } |
774 | |
766 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { | 775 void CFDE_TextOut::OnDraw(const CFX_RectF& rtClip) { |
767 if (!m_pRenderDevice) | 776 if (!m_pRenderDevice) |
768 return; | 777 return; |
769 | 778 |
770 int32_t iLines = m_ttoLines.GetSize(); | 779 int32_t iLines = m_ttoLines.GetSize(); |
771 if (iLines < 1) | 780 if (iLines < 1) |
772 return; | 781 return; |
773 | 782 |
774 CFDE_Brush* pBrush = new CFDE_Brush; | 783 CFDE_Brush* pBrush = new CFDE_Brush; |
775 pBrush->SetColor(m_TxtColor); | 784 pBrush->SetColor(m_TxtColor); |
776 CFDE_Pen* pPen = nullptr; | 785 CFDE_Pen* pPen = nullptr; |
777 m_pRenderDevice->SaveState(); | 786 m_pRenderDevice->SaveState(); |
778 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { | 787 if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f) { |
779 m_pRenderDevice->SetClipRect(rtClip); | 788 m_pRenderDevice->SetClipRect(rtClip); |
780 } | 789 } |
781 for (int32_t i = 0; i < iLines; i++) { | 790 for (int32_t i = 0; i < iLines; i++) { |
782 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); | 791 CFDE_TTOLine* pLine = m_ttoLines.GetPtrAt(i); |
783 int32_t iPieces = pLine->GetSize(); | 792 int32_t iPieces = pLine->GetSize(); |
784 for (int32_t j = 0; j < iPieces; j++) { | 793 for (int32_t j = 0; j < iPieces; j++) { |
785 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); | 794 FDE_TTOPIECE* pPiece = pLine->GetPtrAt(j); |
786 if (!pPiece) | 795 if (!pPiece) |
787 continue; | 796 continue; |
788 | 797 |
789 int32_t iCount = GetDisplayPos(pPiece); | 798 int32_t iCount = GetDisplayPos(pPiece); |
790 if (iCount > 0) { | 799 if (iCount > 0) { |
791 m_pRenderDevice->DrawString(pBrush, m_pFont, m_pCharPos, iCount, | 800 m_pRenderDevice->DrawString(pBrush, m_pFont, m_CharPos.data(), iCount, |
792 m_fFontSize, &m_Matrix); | 801 m_fFontSize, &m_Matrix); |
793 } | 802 } |
794 DrawLine(pPiece, pPen); | 803 DrawLine(pPiece, pPen); |
795 } | 804 } |
796 } | 805 } |
797 m_pRenderDevice->RestoreState(); | 806 m_pRenderDevice->RestoreState(); |
798 delete pBrush; | 807 delete pBrush; |
799 delete pPen; | 808 delete pPen; |
800 } | 809 } |
801 | 810 |
802 int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { | 811 int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) { |
803 FX_TXTRUN tr = ToTextRun(pPiece); | 812 FX_TXTRUN tr = ToTextRun(pPiece); |
804 ExpandBuffer(tr.iLength, 2); | 813 ExpandBuffer(tr.iLength, 2); |
805 return m_pTxtBreak->GetDisplayPos(&tr, m_pCharPos); | 814 return m_pTxtBreak->GetDisplayPos(&tr, m_CharPos.data()); |
806 } | 815 } |
807 | 816 |
808 int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { | 817 int32_t CFDE_TextOut::GetCharRects(const FDE_TTOPIECE* pPiece) { |
809 FX_TXTRUN tr = ToTextRun(pPiece); | 818 FX_TXTRUN tr = ToTextRun(pPiece); |
810 m_rectArray.RemoveAll(); | 819 m_rectArray.RemoveAll(); |
811 return m_pTxtBreak->GetCharRects(&tr, m_rectArray); | 820 return m_pTxtBreak->GetCharRects(&tr, m_rectArray); |
812 } | 821 } |
813 | 822 |
814 FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { | 823 FX_TXTRUN CFDE_TextOut::ToTextRun(const FDE_TTOPIECE* pPiece) { |
815 FX_TXTRUN tr; | 824 FX_TXTRUN tr; |
816 tr.wsStr = m_wsText + pPiece->iStartChar; | 825 tr.wsStr = m_wsText + pPiece->iStartChar; |
817 tr.pWidths = m_pCharWidths + pPiece->iStartChar; | 826 tr.pWidths = &m_CharWidths[pPiece->iStartChar]; |
818 tr.iLength = pPiece->iChars; | 827 tr.iLength = pPiece->iChars; |
819 tr.pFont = m_pFont; | 828 tr.pFont = m_pFont; |
820 tr.fFontSize = m_fFontSize; | 829 tr.fFontSize = m_fFontSize; |
821 tr.dwStyles = m_dwTxtBkStyles; | 830 tr.dwStyles = m_dwTxtBkStyles; |
822 tr.dwCharStyles = pPiece->dwCharStyles; | 831 tr.dwCharStyles = pPiece->dwCharStyles; |
823 tr.wLineBreakChar = m_wParagraphBkChar; | 832 tr.wLineBreakChar = m_wParagraphBkChar; |
824 tr.pRect = &pPiece->rtPiece; | 833 tr.pRect = &pPiece->rtPiece; |
825 return tr; | 834 return tr; |
826 } | 835 } |
827 | 836 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { | 924 int32_t CFDE_TTOLine::AddPiece(int32_t index, const FDE_TTOPIECE& ttoPiece) { |
916 if (index >= m_iPieceCount) { | 925 if (index >= m_iPieceCount) { |
917 index = m_pieces.Add(ttoPiece) + 1; | 926 index = m_pieces.Add(ttoPiece) + 1; |
918 m_iPieceCount++; | 927 m_iPieceCount++; |
919 } else { | 928 } else { |
920 FDE_TTOPIECE& piece = m_pieces.GetAt(index); | 929 FDE_TTOPIECE& piece = m_pieces.GetAt(index); |
921 piece = ttoPiece; | 930 piece = ttoPiece; |
922 } | 931 } |
923 return index; | 932 return index; |
924 } | 933 } |
934 | |
925 int32_t CFDE_TTOLine::GetSize() const { | 935 int32_t CFDE_TTOLine::GetSize() const { |
926 return m_iPieceCount; | 936 return m_iPieceCount; |
927 } | 937 } |
938 | |
928 FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { | 939 FDE_TTOPIECE* CFDE_TTOLine::GetPtrAt(int32_t index) { |
929 if (index >= m_iPieceCount) { | 940 if (index >= m_iPieceCount) { |
930 return nullptr; | 941 return nullptr; |
931 } | 942 } |
932 return m_pieces.GetPtrAt(index); | 943 return m_pieces.GetPtrAt(index); |
933 } | 944 } |
945 | |
934 void CFDE_TTOLine::RemoveLast(int32_t iCount) { | 946 void CFDE_TTOLine::RemoveLast(int32_t iCount) { |
935 m_pieces.RemoveLast(iCount); | 947 m_pieces.RemoveLast(iCount); |
936 } | 948 } |
949 | |
937 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { | 950 void CFDE_TTOLine::RemoveAll(FX_BOOL bLeaveMemory) { |
938 m_pieces.RemoveAll(bLeaveMemory); | 951 m_pieces.RemoveAll(bLeaveMemory); |
939 } | 952 } |
OLD | NEW |