Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: xfa/fee/fde_txtedtbuf.cpp

Issue 1927973003: Remove IFDE_TxtEdt interfaces where possible. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/fee/fde_txtedtbuf.h" 7 #include "xfa/fee/fde_txtedtbuf.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "xfa/fee/ifde_txtedtbuf.h"
12 #include "xfa/fee/ifde_txtedtengine.h" 11 #include "xfa/fee/ifde_txtedtengine.h"
13 12
14 #define FDE_DEFCHUNKCOUNT 2 13 #define FDE_DEFCHUNKCOUNT 2
15 #define FDE_TXTEDT_FORMATBLOCK_BGN 0xFFF9 14 #define FDE_TXTEDT_FORMATBLOCK_BGN 0xFFF9
16 #define FDE_TXTEDT_FORMATBLOCK_END 0xFFFB 15 #define FDE_TXTEDT_FORMATBLOCK_END 0xFFFB
17 #define FDE_TXTEDT_ZEROWIDTHSPACE 0x200B 16 #define FDE_TXTEDT_ZEROWIDTHSPACE 0x200B
18 17
19 CFDE_TxtEdtBufIter::CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias) 18 CFDE_TxtEdtBufIter::CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias)
20 : m_pBuf(pBuf), 19 : m_pBuf(pBuf),
21 m_nCurChunk(0), 20 m_nCurChunk(0),
22 m_nCurIndex(0), 21 m_nCurIndex(0),
23 m_nIndex(0), 22 m_nIndex(0),
24 m_Alias(wcAlias) { 23 m_Alias(wcAlias) {
25 ASSERT(m_pBuf); 24 ASSERT(m_pBuf);
26 } 25 }
27 CFDE_TxtEdtBufIter::~CFDE_TxtEdtBufIter() {} 26 CFDE_TxtEdtBufIter::~CFDE_TxtEdtBufIter() {}
28 void CFDE_TxtEdtBufIter::Release() { 27 void CFDE_TxtEdtBufIter::Release() {
29 delete this; 28 delete this;
30 } 29 }
31 FX_BOOL CFDE_TxtEdtBufIter::Next(FX_BOOL bPrev) { 30 FX_BOOL CFDE_TxtEdtBufIter::Next(FX_BOOL bPrev) {
32 if (bPrev) { 31 if (bPrev) {
33 if (m_nIndex == 0) { 32 if (m_nIndex == 0) {
34 return FALSE; 33 return FALSE;
35 } 34 }
36 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize()); 35 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize());
37 CFDE_TxtEdtBuf::FDE_LPCHUNKHEADER lpChunk = NULL; 36 CFDE_TxtEdtBuf::FDE_CHUNKHEADER* lpChunk = nullptr;
38 if (m_nCurIndex > 0) { 37 if (m_nCurIndex > 0) {
39 m_nCurIndex--; 38 m_nCurIndex--;
40 } else { 39 } else {
41 while (m_nCurChunk > 0) { 40 while (m_nCurChunk > 0) {
42 --m_nCurChunk; 41 --m_nCurChunk;
43 lpChunk = m_pBuf->m_Chunks[m_nCurChunk]; 42 lpChunk = m_pBuf->m_Chunks[m_nCurChunk];
44 if (lpChunk->nUsed > 0) { 43 if (lpChunk->nUsed > 0) {
45 m_nCurIndex = lpChunk->nUsed - 1; 44 m_nCurIndex = lpChunk->nUsed - 1;
46 break; 45 break;
47 } 46 }
48 } 47 }
49 } 48 }
50 ASSERT(m_nCurChunk >= 0); 49 ASSERT(m_nCurChunk >= 0);
51 m_nIndex--; 50 m_nIndex--;
52 return TRUE; 51 return TRUE;
53 } else { 52 } else {
54 if (m_nIndex >= (m_pBuf->m_nTotal - 1)) { 53 if (m_nIndex >= (m_pBuf->m_nTotal - 1)) {
55 return FALSE; 54 return FALSE;
56 } 55 }
57 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize()); 56 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize());
58 CFDE_TxtEdtBuf::FDE_LPCHUNKHEADER lpChunk = m_pBuf->m_Chunks[m_nCurChunk]; 57 CFDE_TxtEdtBuf::FDE_CHUNKHEADER* lpChunk = m_pBuf->m_Chunks[m_nCurChunk];
59 if (lpChunk->nUsed != (m_nCurIndex + 1)) { 58 if (lpChunk->nUsed != (m_nCurIndex + 1)) {
60 m_nCurIndex++; 59 m_nCurIndex++;
61 } else { 60 } else {
62 int32_t nEnd = m_pBuf->m_Chunks.GetSize() - 1; 61 int32_t nEnd = m_pBuf->m_Chunks.GetSize() - 1;
63 while (m_nCurChunk < nEnd) { 62 while (m_nCurChunk < nEnd) {
64 m_nCurChunk++; 63 m_nCurChunk++;
65 CFDE_TxtEdtBuf::FDE_LPCHUNKHEADER lpChunkTemp = 64 CFDE_TxtEdtBuf::FDE_CHUNKHEADER* lpChunkTemp =
66 m_pBuf->m_Chunks[m_nCurChunk]; 65 m_pBuf->m_Chunks[m_nCurChunk];
67 if (lpChunkTemp->nUsed > 0) { 66 if (lpChunkTemp->nUsed > 0) {
68 m_nCurIndex = 0; 67 m_nCurIndex = 0;
69 break; 68 break;
70 } 69 }
71 } 70 }
72 } 71 }
73 m_nIndex++; 72 m_nIndex++;
74 return TRUE; 73 return TRUE;
75 } 74 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return m_nTotal; 130 return m_nTotal;
132 } 131 }
133 void CFDE_TxtEdtBuf::SetText(const CFX_WideString& wsText) { 132 void CFDE_TxtEdtBuf::SetText(const CFX_WideString& wsText) {
134 ASSERT(!wsText.IsEmpty()); 133 ASSERT(!wsText.IsEmpty());
135 Clear(FALSE); 134 Clear(FALSE);
136 int32_t nTextLength = wsText.GetLength(); 135 int32_t nTextLength = wsText.GetLength();
137 int32_t nNeedCount = 136 int32_t nNeedCount =
138 ((nTextLength - 1) / m_nChunkSize + 1) - m_Chunks.GetSize(); 137 ((nTextLength - 1) / m_nChunkSize + 1) - m_Chunks.GetSize();
139 int32_t i = 0; 138 int32_t i = 0;
140 for (i = 0; i < nNeedCount; i++) { 139 for (i = 0; i < nNeedCount; i++) {
141 FDE_LPCHUNKHEADER lpChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc( 140 FDE_CHUNKHEADER* lpChunk =
142 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)); 141 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(
142 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)));
143 lpChunk->nUsed = 0; 143 lpChunk->nUsed = 0;
144 m_Chunks.Add(lpChunk); 144 m_Chunks.Add(lpChunk);
145 } 145 }
146 int32_t nTotalCount = m_Chunks.GetSize(); 146 int32_t nTotalCount = m_Chunks.GetSize();
147 const FX_WCHAR* lpSrcBuf = wsText.c_str(); 147 const FX_WCHAR* lpSrcBuf = wsText.c_str();
148 int32_t nLeave = nTextLength; 148 int32_t nLeave = nTextLength;
149 int32_t nCopyedLength = m_nChunkSize; 149 int32_t nCopyedLength = m_nChunkSize;
150 for (i = 0; i < nTotalCount && nLeave > 0; i++) { 150 for (i = 0; i < nTotalCount && nLeave > 0; i++) {
151 if (nLeave < nCopyedLength) { 151 if (nLeave < nCopyedLength) {
152 nCopyedLength = nLeave; 152 nCopyedLength = nLeave;
153 } 153 }
154 FDE_LPCHUNKHEADER lpChunk = m_Chunks[i]; 154 FDE_CHUNKHEADER* lpChunk = m_Chunks[i];
155 FXSYS_memcpy(lpChunk->wChars, lpSrcBuf, nCopyedLength * sizeof(FX_WCHAR)); 155 FXSYS_memcpy(lpChunk->wChars, lpSrcBuf, nCopyedLength * sizeof(FX_WCHAR));
156 nLeave -= nCopyedLength; 156 nLeave -= nCopyedLength;
157 lpSrcBuf += nCopyedLength; 157 lpSrcBuf += nCopyedLength;
158 lpChunk->nUsed = nCopyedLength; 158 lpChunk->nUsed = nCopyedLength;
159 } 159 }
160 m_nTotal = nTextLength; 160 m_nTotal = nTextLength;
161 m_bChanged = TRUE; 161 m_bChanged = TRUE;
162 } 162 }
163 void CFDE_TxtEdtBuf::GetText(CFX_WideString& wsText) const { 163 void CFDE_TxtEdtBuf::GetText(CFX_WideString& wsText) const {
164 GetRange(wsText, 0, m_nTotal); 164 GetRange(wsText, 0, m_nTotal);
165 } 165 }
166 FX_WCHAR CFDE_TxtEdtBuf::GetCharByIndex(int32_t nIndex) const { 166 FX_WCHAR CFDE_TxtEdtBuf::GetCharByIndex(int32_t nIndex) const {
167 ASSERT(nIndex >= 0 && nIndex < GetTextLength()); 167 ASSERT(nIndex >= 0 && nIndex < GetTextLength());
168 FDE_LPCHUNKHEADER pChunkHeader = NULL; 168 FDE_CHUNKHEADER* pChunkHeader = nullptr;
169 int32_t nTotal = 0; 169 int32_t nTotal = 0;
170 int32_t nCount = m_Chunks.GetSize(); 170 int32_t nCount = m_Chunks.GetSize();
171 int32_t i = 0; 171 int32_t i = 0;
172 for (i = 0; i < nCount; i++) { 172 for (i = 0; i < nCount; i++) {
173 pChunkHeader = m_Chunks[i]; 173 pChunkHeader = m_Chunks[i];
174 nTotal += pChunkHeader->nUsed; 174 nTotal += pChunkHeader->nUsed;
175 if (nTotal > nIndex) { 175 if (nTotal > nIndex) {
176 break; 176 break;
177 } 177 }
178 } 178 }
179 ASSERT(pChunkHeader); 179 ASSERT(pChunkHeader);
180 return pChunkHeader->wChars[pChunkHeader->nUsed - (nTotal - nIndex)]; 180 return pChunkHeader->wChars[pChunkHeader->nUsed - (nTotal - nIndex)];
181 } 181 }
182 void CFDE_TxtEdtBuf::GetRange(CFX_WideString& wsText, 182 void CFDE_TxtEdtBuf::GetRange(CFX_WideString& wsText,
183 int32_t nBegin, 183 int32_t nBegin,
184 int32_t nLength) const { 184 int32_t nLength) const {
185 FDE_CHUNKPLACE cp; 185 FDE_CHUNKPLACE cp;
186 Index2CP(nBegin, cp); 186 Index2CP(nBegin, cp);
187 int32_t nLeave = nLength; 187 int32_t nLeave = nLength;
188 int32_t nCount = m_Chunks.GetSize(); 188 int32_t nCount = m_Chunks.GetSize();
189 FX_WCHAR* lpDstBuf = wsText.GetBuffer(nLength); 189 FX_WCHAR* lpDstBuf = wsText.GetBuffer(nLength);
190 int32_t nChunkIndex = cp.nChunkIndex; 190 int32_t nChunkIndex = cp.nChunkIndex;
191 FDE_LPCHUNKHEADER lpChunkHeader = m_Chunks[nChunkIndex]; 191 FDE_CHUNKHEADER* lpChunkHeader = m_Chunks[nChunkIndex];
192 int32_t nCopyLength = lpChunkHeader->nUsed - cp.nCharIndex; 192 int32_t nCopyLength = lpChunkHeader->nUsed - cp.nCharIndex;
193 FX_WCHAR* lpSrcBuf = lpChunkHeader->wChars + cp.nCharIndex; 193 FX_WCHAR* lpSrcBuf = lpChunkHeader->wChars + cp.nCharIndex;
194 while (nLeave > 0) { 194 while (nLeave > 0) {
195 if (nLeave <= nCopyLength) { 195 if (nLeave <= nCopyLength) {
196 nCopyLength = nLeave; 196 nCopyLength = nLeave;
197 } 197 }
198 FXSYS_memcpy(lpDstBuf, lpSrcBuf, nCopyLength * sizeof(FX_WCHAR)); 198 FXSYS_memcpy(lpDstBuf, lpSrcBuf, nCopyLength * sizeof(FX_WCHAR));
199 nChunkIndex++; 199 nChunkIndex++;
200 if (nChunkIndex >= nCount) { 200 if (nChunkIndex >= nCount) {
201 break; 201 break;
202 } 202 }
203 lpChunkHeader = m_Chunks[nChunkIndex]; 203 lpChunkHeader = m_Chunks[nChunkIndex];
204 lpSrcBuf = lpChunkHeader->wChars; 204 lpSrcBuf = lpChunkHeader->wChars;
205 nLeave -= nCopyLength; 205 nLeave -= nCopyLength;
206 lpDstBuf += nCopyLength; 206 lpDstBuf += nCopyLength;
207 nCopyLength = lpChunkHeader->nUsed; 207 nCopyLength = lpChunkHeader->nUsed;
208 } 208 }
209 wsText.ReleaseBuffer(); 209 wsText.ReleaseBuffer();
210 } 210 }
211 void CFDE_TxtEdtBuf::Insert(int32_t nPos, 211 void CFDE_TxtEdtBuf::Insert(int32_t nPos,
212 const FX_WCHAR* lpText, 212 const FX_WCHAR* lpText,
213 int32_t nLength) { 213 int32_t nLength) {
214 ASSERT(nPos >= 0 && nPos <= m_nTotal); 214 ASSERT(nPos >= 0 && nPos <= m_nTotal);
215 FDE_CHUNKPLACE cp; 215 FDE_CHUNKPLACE cp;
216 Index2CP(nPos, cp); 216 Index2CP(nPos, cp);
217 int32_t nLengthTemp = nLength; 217 int32_t nLengthTemp = nLength;
218 if (cp.nCharIndex != 0) { 218 if (cp.nCharIndex != 0) {
219 FDE_LPCHUNKHEADER lpNewChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc( 219 FDE_CHUNKHEADER* lpNewChunk =
220 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)); 220 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(
221 FDE_LPCHUNKHEADER lpChunk = m_Chunks[cp.nChunkIndex]; 221 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)));
222 FDE_CHUNKHEADER* lpChunk = m_Chunks[cp.nChunkIndex];
222 int32_t nCopy = lpChunk->nUsed - cp.nCharIndex; 223 int32_t nCopy = lpChunk->nUsed - cp.nCharIndex;
223 FXSYS_memcpy(lpNewChunk->wChars, lpChunk->wChars + cp.nCharIndex, 224 FXSYS_memcpy(lpNewChunk->wChars, lpChunk->wChars + cp.nCharIndex,
224 nCopy * sizeof(FX_WCHAR)); 225 nCopy * sizeof(FX_WCHAR));
225 lpChunk->nUsed -= nCopy; 226 lpChunk->nUsed -= nCopy;
226 cp.nChunkIndex++; 227 cp.nChunkIndex++;
227 m_Chunks.InsertAt(cp.nChunkIndex, lpNewChunk); 228 m_Chunks.InsertAt(cp.nChunkIndex, lpNewChunk);
228 lpNewChunk->nUsed = nCopy; 229 lpNewChunk->nUsed = nCopy;
229 cp.nCharIndex = 0; 230 cp.nCharIndex = 0;
230 } 231 }
231 if (cp.nChunkIndex != 0) { 232 if (cp.nChunkIndex != 0) {
232 FDE_LPCHUNKHEADER lpChunk = m_Chunks[cp.nChunkIndex - 1]; 233 FDE_CHUNKHEADER* lpChunk = m_Chunks[cp.nChunkIndex - 1];
233 if (lpChunk->nUsed != m_nChunkSize) { 234 if (lpChunk->nUsed != m_nChunkSize) {
234 cp.nChunkIndex--; 235 cp.nChunkIndex--;
235 int32_t nFree = m_nChunkSize - lpChunk->nUsed; 236 int32_t nFree = m_nChunkSize - lpChunk->nUsed;
236 int32_t nCopy = std::min(nLengthTemp, nFree); 237 int32_t nCopy = std::min(nLengthTemp, nFree);
237 FXSYS_memcpy(lpChunk->wChars + lpChunk->nUsed, lpText, 238 FXSYS_memcpy(lpChunk->wChars + lpChunk->nUsed, lpText,
238 nCopy * sizeof(FX_WCHAR)); 239 nCopy * sizeof(FX_WCHAR));
239 lpText += nCopy; 240 lpText += nCopy;
240 nLengthTemp -= nCopy; 241 nLengthTemp -= nCopy;
241 lpChunk->nUsed += nCopy; 242 lpChunk->nUsed += nCopy;
242 cp.nChunkIndex++; 243 cp.nChunkIndex++;
243 } 244 }
244 } 245 }
245 while (nLengthTemp > 0) { 246 while (nLengthTemp > 0) {
246 FDE_LPCHUNKHEADER lpChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc( 247 FDE_CHUNKHEADER* lpChunk =
247 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)); 248 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(
249 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)));
248 ASSERT(lpChunk); 250 ASSERT(lpChunk);
249 int32_t nCopy = std::min(nLengthTemp, m_nChunkSize); 251 int32_t nCopy = std::min(nLengthTemp, m_nChunkSize);
250 FXSYS_memcpy(lpChunk->wChars, lpText, nCopy * sizeof(FX_WCHAR)); 252 FXSYS_memcpy(lpChunk->wChars, lpText, nCopy * sizeof(FX_WCHAR));
251 lpText += nCopy; 253 lpText += nCopy;
252 nLengthTemp -= nCopy; 254 nLengthTemp -= nCopy;
253 lpChunk->nUsed = nCopy; 255 lpChunk->nUsed = nCopy;
254 m_Chunks.InsertAt(cp.nChunkIndex, lpChunk); 256 m_Chunks.InsertAt(cp.nChunkIndex, lpChunk);
255 cp.nChunkIndex++; 257 cp.nChunkIndex++;
256 } 258 }
257 m_nTotal += nLength; 259 m_nTotal += nLength;
258 m_bChanged = TRUE; 260 m_bChanged = TRUE;
259 } 261 }
260 void CFDE_TxtEdtBuf::Delete(int32_t nIndex, int32_t nLength) { 262 void CFDE_TxtEdtBuf::Delete(int32_t nIndex, int32_t nLength) {
261 ASSERT(nLength > 0 && nIndex >= 0 && nIndex + nLength <= m_nTotal); 263 ASSERT(nLength > 0 && nIndex >= 0 && nIndex + nLength <= m_nTotal);
262 FDE_CHUNKPLACE cpEnd; 264 FDE_CHUNKPLACE cpEnd;
263 Index2CP(nIndex + nLength - 1, cpEnd); 265 Index2CP(nIndex + nLength - 1, cpEnd);
264 m_nTotal -= nLength; 266 m_nTotal -= nLength;
265 FDE_LPCHUNKHEADER lpChunk = m_Chunks[cpEnd.nChunkIndex]; 267 FDE_CHUNKHEADER* lpChunk = m_Chunks[cpEnd.nChunkIndex];
266 int32_t nFirstPart = cpEnd.nCharIndex + 1; 268 int32_t nFirstPart = cpEnd.nCharIndex + 1;
267 int32_t nMovePart = lpChunk->nUsed - nFirstPart; 269 int32_t nMovePart = lpChunk->nUsed - nFirstPart;
268 if (nMovePart != 0) { 270 if (nMovePart != 0) {
269 int32_t nDelete = std::min(nFirstPart, nLength); 271 int32_t nDelete = std::min(nFirstPart, nLength);
270 FXSYS_memmove(lpChunk->wChars + nFirstPart - nDelete, 272 FXSYS_memmove(lpChunk->wChars + nFirstPart - nDelete,
271 lpChunk->wChars + nFirstPart, nMovePart * sizeof(FX_WCHAR)); 273 lpChunk->wChars + nFirstPart, nMovePart * sizeof(FX_WCHAR));
272 lpChunk->nUsed -= nDelete; 274 lpChunk->nUsed -= nDelete;
273 nLength -= nDelete; 275 nLength -= nDelete;
274 cpEnd.nChunkIndex--; 276 cpEnd.nChunkIndex--;
275 } 277 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 311 }
310 if (m_nTotal == 0) { 312 if (m_nTotal == 0) {
311 return TRUE; 313 return TRUE;
312 } 314 }
313 int32_t nCount = m_Chunks.GetSize(); 315 int32_t nCount = m_Chunks.GetSize();
314 if (nCount == 0) { 316 if (nCount == 0) {
315 return TRUE; 317 return TRUE;
316 } 318 }
317 int32_t i = 0; 319 int32_t i = 0;
318 for (; i < nCount; i++) { 320 for (; i < nCount; i++) {
319 FDE_LPCHUNKHEADER lpChunk = m_Chunks[i]; 321 FDE_CHUNKHEADER* lpChunk = m_Chunks[i];
320 if (lpChunk->nUsed == 0) { 322 if (lpChunk->nUsed == 0) {
321 m_pAllocator->Free(lpChunk); 323 m_pAllocator->Free(lpChunk);
322 m_Chunks.RemoveAt(i); 324 m_Chunks.RemoveAt(i);
323 --i; 325 --i;
324 --nCount; 326 --nCount;
325 } 327 }
326 } 328 }
327 if (pPause != NULL && pPause->NeedToPauseNow()) { 329 if (pPause && pPause->NeedToPauseNow())
328 return FALSE; 330 return FALSE;
329 } 331
330 FDE_LPCHUNKHEADER lpPreChunk = m_Chunks[0]; 332 FDE_CHUNKHEADER* lpPreChunk = m_Chunks[0];
331 FDE_LPCHUNKHEADER lpCurChunk = NULL; 333 FDE_CHUNKHEADER* lpCurChunk = nullptr;
332 for (i = 1; i < nCount; i++) { 334 for (i = 1; i < nCount; i++) {
333 lpCurChunk = m_Chunks[i]; 335 lpCurChunk = m_Chunks[i];
334 if (lpPreChunk->nUsed + lpCurChunk->nUsed <= m_nChunkSize) { 336 if (lpPreChunk->nUsed + lpCurChunk->nUsed <= m_nChunkSize) {
335 FXSYS_memcpy(lpPreChunk->wChars + lpPreChunk->nUsed, lpCurChunk->wChars, 337 FXSYS_memcpy(lpPreChunk->wChars + lpPreChunk->nUsed, lpCurChunk->wChars,
336 lpCurChunk->nUsed * sizeof(FX_WCHAR)); 338 lpCurChunk->nUsed * sizeof(FX_WCHAR));
337 lpPreChunk->nUsed += lpCurChunk->nUsed; 339 lpPreChunk->nUsed += lpCurChunk->nUsed;
338 m_pAllocator->Free(lpCurChunk); 340 m_pAllocator->Free(lpCurChunk);
339 m_Chunks.RemoveAt(i); 341 m_Chunks.RemoveAt(i);
340 --i; 342 --i;
341 --nCount; 343 --nCount;
(...skipping 15 matching lines...) Expand all
357 m_pAllocator->Release(); 359 m_pAllocator->Release();
358 m_pAllocator = NULL; 360 m_pAllocator = NULL;
359 } 361 }
360 m_Chunks.RemoveAll(); 362 m_Chunks.RemoveAll();
361 m_nChunkSize = nChunkSize; 363 m_nChunkSize = nChunkSize;
362 int32_t nChunkLength = 364 int32_t nChunkLength =
363 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR); 365 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR);
364 m_pAllocator = 366 m_pAllocator =
365 FX_CreateAllocator(FX_ALLOCTYPE_Fixed, nDefChunkCount, nChunkLength); 367 FX_CreateAllocator(FX_ALLOCTYPE_Fixed, nDefChunkCount, nChunkLength);
366 ASSERT(m_pAllocator); 368 ASSERT(m_pAllocator);
367 FDE_LPCHUNKHEADER lpChunkHeader = 369 FDE_CHUNKHEADER* lpChunkHeader =
368 (FDE_LPCHUNKHEADER)m_pAllocator->Alloc(nChunkLength); 370 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(nChunkLength));
369 ASSERT(lpChunkHeader); 371 ASSERT(lpChunkHeader);
370 lpChunkHeader->nUsed = 0; 372 lpChunkHeader->nUsed = 0;
371 m_Chunks.Add(lpChunkHeader); 373 m_Chunks.Add(lpChunkHeader);
372 m_nTotal = 0; 374 m_nTotal = 0;
373 } 375 }
374 int32_t CFDE_TxtEdtBuf::CP2Index(const FDE_CHUNKPLACE& cp) const { 376 int32_t CFDE_TxtEdtBuf::CP2Index(const FDE_CHUNKPLACE& cp) const {
375 int32_t nTotal = cp.nCharIndex; 377 int32_t nTotal = cp.nCharIndex;
376 int32_t i = 0; 378 int32_t i = 0;
377 for (i = 0; i < cp.nChunkIndex; i++) { 379 for (i = 0; i < cp.nChunkIndex; i++) {
378 nTotal += m_Chunks[i]->nUsed; 380 nTotal += m_Chunks[i]->nUsed;
(...skipping 12 matching lines...) Expand all
391 int32_t nCount = m_Chunks.GetSize(); 393 int32_t nCount = m_Chunks.GetSize();
392 for (; i < nCount; i++) { 394 for (; i < nCount; i++) {
393 nTotal += m_Chunks[i]->nUsed; 395 nTotal += m_Chunks[i]->nUsed;
394 if (nTotal > nIndex) { 396 if (nTotal > nIndex) {
395 break; 397 break;
396 } 398 }
397 } 399 }
398 cp.nChunkIndex = i; 400 cp.nChunkIndex = i;
399 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); 401 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex);
400 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698