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

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
« no previous file with comments | « xfa/fee/fde_txtedtbuf.h ('k') | xfa/fee/fde_txtedtengine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
13 namespace {
14
15 const int kDefaultChunkSize = 1024;
16
17 } // namespace
18
14 #define FDE_DEFCHUNKCOUNT 2 19 #define FDE_DEFCHUNKCOUNT 2
15 #define FDE_TXTEDT_FORMATBLOCK_BGN 0xFFF9 20 #define FDE_TXTEDT_FORMATBLOCK_BGN 0xFFF9
16 #define FDE_TXTEDT_FORMATBLOCK_END 0xFFFB 21 #define FDE_TXTEDT_FORMATBLOCK_END 0xFFFB
17 #define FDE_TXTEDT_ZEROWIDTHSPACE 0x200B 22 #define FDE_TXTEDT_ZEROWIDTHSPACE 0x200B
18 23
19 CFDE_TxtEdtBufIter::CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias) 24 CFDE_TxtEdtBufIter::CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias)
20 : m_pBuf(pBuf), 25 : m_pBuf(pBuf),
21 m_nCurChunk(0), 26 m_nCurChunk(0),
22 m_nCurIndex(0), 27 m_nCurIndex(0),
23 m_nIndex(0), 28 m_nIndex(0),
24 m_Alias(wcAlias) { 29 m_Alias(wcAlias) {
25 ASSERT(m_pBuf); 30 ASSERT(m_pBuf);
26 } 31 }
27 CFDE_TxtEdtBufIter::~CFDE_TxtEdtBufIter() {} 32 CFDE_TxtEdtBufIter::~CFDE_TxtEdtBufIter() {}
28 void CFDE_TxtEdtBufIter::Release() { 33 void CFDE_TxtEdtBufIter::Release() {
29 delete this; 34 delete this;
30 } 35 }
31 FX_BOOL CFDE_TxtEdtBufIter::Next(FX_BOOL bPrev) { 36 FX_BOOL CFDE_TxtEdtBufIter::Next(FX_BOOL bPrev) {
32 if (bPrev) { 37 if (bPrev) {
33 if (m_nIndex == 0) { 38 if (m_nIndex == 0) {
34 return FALSE; 39 return FALSE;
35 } 40 }
36 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize()); 41 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize());
37 CFDE_TxtEdtBuf::FDE_LPCHUNKHEADER lpChunk = NULL; 42 CFDE_TxtEdtBuf::FDE_CHUNKHEADER* lpChunk = nullptr;
38 if (m_nCurIndex > 0) { 43 if (m_nCurIndex > 0) {
39 m_nCurIndex--; 44 m_nCurIndex--;
40 } else { 45 } else {
41 while (m_nCurChunk > 0) { 46 while (m_nCurChunk > 0) {
42 --m_nCurChunk; 47 --m_nCurChunk;
43 lpChunk = m_pBuf->m_Chunks[m_nCurChunk]; 48 lpChunk = m_pBuf->m_Chunks[m_nCurChunk];
44 if (lpChunk->nUsed > 0) { 49 if (lpChunk->nUsed > 0) {
45 m_nCurIndex = lpChunk->nUsed - 1; 50 m_nCurIndex = lpChunk->nUsed - 1;
46 break; 51 break;
47 } 52 }
48 } 53 }
49 } 54 }
50 ASSERT(m_nCurChunk >= 0); 55 ASSERT(m_nCurChunk >= 0);
51 m_nIndex--; 56 m_nIndex--;
52 return TRUE; 57 return TRUE;
53 } else { 58 } else {
54 if (m_nIndex >= (m_pBuf->m_nTotal - 1)) { 59 if (m_nIndex >= (m_pBuf->m_nTotal - 1)) {
55 return FALSE; 60 return FALSE;
56 } 61 }
57 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize()); 62 ASSERT(m_nCurChunk < m_pBuf->m_Chunks.GetSize());
58 CFDE_TxtEdtBuf::FDE_LPCHUNKHEADER lpChunk = m_pBuf->m_Chunks[m_nCurChunk]; 63 CFDE_TxtEdtBuf::FDE_CHUNKHEADER* lpChunk = m_pBuf->m_Chunks[m_nCurChunk];
59 if (lpChunk->nUsed != (m_nCurIndex + 1)) { 64 if (lpChunk->nUsed != (m_nCurIndex + 1)) {
60 m_nCurIndex++; 65 m_nCurIndex++;
61 } else { 66 } else {
62 int32_t nEnd = m_pBuf->m_Chunks.GetSize() - 1; 67 int32_t nEnd = m_pBuf->m_Chunks.GetSize() - 1;
63 while (m_nCurChunk < nEnd) { 68 while (m_nCurChunk < nEnd) {
64 m_nCurChunk++; 69 m_nCurChunk++;
65 CFDE_TxtEdtBuf::FDE_LPCHUNKHEADER lpChunkTemp = 70 CFDE_TxtEdtBuf::FDE_CHUNKHEADER* lpChunkTemp =
66 m_pBuf->m_Chunks[m_nCurChunk]; 71 m_pBuf->m_Chunks[m_nCurChunk];
67 if (lpChunkTemp->nUsed > 0) { 72 if (lpChunkTemp->nUsed > 0) {
68 m_nCurIndex = 0; 73 m_nCurIndex = 0;
69 break; 74 break;
70 } 75 }
71 } 76 }
72 } 77 }
73 m_nIndex++; 78 m_nIndex++;
74 return TRUE; 79 return TRUE;
75 } 80 }
(...skipping 20 matching lines...) Expand all
96 return bTail ? m_nIndex == (m_pBuf->GetTextLength() - 2) : m_nIndex == 0; 101 return bTail ? m_nIndex == (m_pBuf->GetTextLength() - 2) : m_nIndex == 0;
97 } 102 }
98 IFX_CharIter* CFDE_TxtEdtBufIter::Clone() { 103 IFX_CharIter* CFDE_TxtEdtBufIter::Clone() {
99 CFDE_TxtEdtBufIter* pIter = new CFDE_TxtEdtBufIter(m_pBuf); 104 CFDE_TxtEdtBufIter* pIter = new CFDE_TxtEdtBufIter(m_pBuf);
100 pIter->m_nCurChunk = m_nCurChunk; 105 pIter->m_nCurChunk = m_nCurChunk;
101 pIter->m_nCurIndex = m_nCurIndex; 106 pIter->m_nCurIndex = m_nCurIndex;
102 pIter->m_nIndex = m_nIndex; 107 pIter->m_nIndex = m_nIndex;
103 pIter->m_Alias = m_Alias; 108 pIter->m_Alias = m_Alias;
104 return pIter; 109 return pIter;
105 } 110 }
106 CFDE_TxtEdtBuf::CFDE_TxtEdtBuf(int32_t nDefChunkSize) 111
107 : m_nChunkSize(nDefChunkSize), 112 CFDE_TxtEdtBuf::CFDE_TxtEdtBuf()
113 : m_nChunkSize(kDefaultChunkSize),
108 m_nTotal(0), 114 m_nTotal(0),
109 m_bChanged(FALSE), 115 m_bChanged(FALSE),
110 m_pAllocator(NULL) { 116 m_pAllocator(NULL) {
111 ASSERT(m_nChunkSize); 117 ASSERT(m_nChunkSize);
112 ResetChunkBuffer(FDE_DEFCHUNKCOUNT, m_nChunkSize); 118 ResetChunkBuffer(FDE_DEFCHUNKCOUNT, m_nChunkSize);
113 } 119 }
114 void CFDE_TxtEdtBuf::Release() { 120 void CFDE_TxtEdtBuf::Release() {
115 delete this; 121 delete this;
116 } 122 }
117 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() { 123 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() {
(...skipping 13 matching lines...) Expand all
131 return m_nTotal; 137 return m_nTotal;
132 } 138 }
133 void CFDE_TxtEdtBuf::SetText(const CFX_WideString& wsText) { 139 void CFDE_TxtEdtBuf::SetText(const CFX_WideString& wsText) {
134 ASSERT(!wsText.IsEmpty()); 140 ASSERT(!wsText.IsEmpty());
135 Clear(FALSE); 141 Clear(FALSE);
136 int32_t nTextLength = wsText.GetLength(); 142 int32_t nTextLength = wsText.GetLength();
137 int32_t nNeedCount = 143 int32_t nNeedCount =
138 ((nTextLength - 1) / m_nChunkSize + 1) - m_Chunks.GetSize(); 144 ((nTextLength - 1) / m_nChunkSize + 1) - m_Chunks.GetSize();
139 int32_t i = 0; 145 int32_t i = 0;
140 for (i = 0; i < nNeedCount; i++) { 146 for (i = 0; i < nNeedCount; i++) {
141 FDE_LPCHUNKHEADER lpChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc( 147 FDE_CHUNKHEADER* lpChunk =
142 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)); 148 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(
149 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)));
143 lpChunk->nUsed = 0; 150 lpChunk->nUsed = 0;
144 m_Chunks.Add(lpChunk); 151 m_Chunks.Add(lpChunk);
145 } 152 }
146 int32_t nTotalCount = m_Chunks.GetSize(); 153 int32_t nTotalCount = m_Chunks.GetSize();
147 const FX_WCHAR* lpSrcBuf = wsText.c_str(); 154 const FX_WCHAR* lpSrcBuf = wsText.c_str();
148 int32_t nLeave = nTextLength; 155 int32_t nLeave = nTextLength;
149 int32_t nCopyedLength = m_nChunkSize; 156 int32_t nCopyedLength = m_nChunkSize;
150 for (i = 0; i < nTotalCount && nLeave > 0; i++) { 157 for (i = 0; i < nTotalCount && nLeave > 0; i++) {
151 if (nLeave < nCopyedLength) { 158 if (nLeave < nCopyedLength) {
152 nCopyedLength = nLeave; 159 nCopyedLength = nLeave;
153 } 160 }
154 FDE_LPCHUNKHEADER lpChunk = m_Chunks[i]; 161 FDE_CHUNKHEADER* lpChunk = m_Chunks[i];
155 FXSYS_memcpy(lpChunk->wChars, lpSrcBuf, nCopyedLength * sizeof(FX_WCHAR)); 162 FXSYS_memcpy(lpChunk->wChars, lpSrcBuf, nCopyedLength * sizeof(FX_WCHAR));
156 nLeave -= nCopyedLength; 163 nLeave -= nCopyedLength;
157 lpSrcBuf += nCopyedLength; 164 lpSrcBuf += nCopyedLength;
158 lpChunk->nUsed = nCopyedLength; 165 lpChunk->nUsed = nCopyedLength;
159 } 166 }
160 m_nTotal = nTextLength; 167 m_nTotal = nTextLength;
161 m_bChanged = TRUE; 168 m_bChanged = TRUE;
162 } 169 }
163 void CFDE_TxtEdtBuf::GetText(CFX_WideString& wsText) const { 170 void CFDE_TxtEdtBuf::GetText(CFX_WideString& wsText) const {
164 GetRange(wsText, 0, m_nTotal); 171 GetRange(wsText, 0, m_nTotal);
165 } 172 }
166 FX_WCHAR CFDE_TxtEdtBuf::GetCharByIndex(int32_t nIndex) const { 173 FX_WCHAR CFDE_TxtEdtBuf::GetCharByIndex(int32_t nIndex) const {
167 ASSERT(nIndex >= 0 && nIndex < GetTextLength()); 174 ASSERT(nIndex >= 0 && nIndex < GetTextLength());
168 FDE_LPCHUNKHEADER pChunkHeader = NULL; 175 FDE_CHUNKHEADER* pChunkHeader = nullptr;
169 int32_t nTotal = 0; 176 int32_t nTotal = 0;
170 int32_t nCount = m_Chunks.GetSize(); 177 int32_t nCount = m_Chunks.GetSize();
171 int32_t i = 0; 178 int32_t i = 0;
172 for (i = 0; i < nCount; i++) { 179 for (i = 0; i < nCount; i++) {
173 pChunkHeader = m_Chunks[i]; 180 pChunkHeader = m_Chunks[i];
174 nTotal += pChunkHeader->nUsed; 181 nTotal += pChunkHeader->nUsed;
175 if (nTotal > nIndex) { 182 if (nTotal > nIndex) {
176 break; 183 break;
177 } 184 }
178 } 185 }
179 ASSERT(pChunkHeader); 186 ASSERT(pChunkHeader);
180 return pChunkHeader->wChars[pChunkHeader->nUsed - (nTotal - nIndex)]; 187 return pChunkHeader->wChars[pChunkHeader->nUsed - (nTotal - nIndex)];
181 } 188 }
182 void CFDE_TxtEdtBuf::GetRange(CFX_WideString& wsText, 189 void CFDE_TxtEdtBuf::GetRange(CFX_WideString& wsText,
183 int32_t nBegin, 190 int32_t nBegin,
184 int32_t nLength) const { 191 int32_t nLength) const {
185 FDE_CHUNKPLACE cp; 192 FDE_CHUNKPLACE cp;
186 Index2CP(nBegin, cp); 193 Index2CP(nBegin, cp);
187 int32_t nLeave = nLength; 194 int32_t nLeave = nLength;
188 int32_t nCount = m_Chunks.GetSize(); 195 int32_t nCount = m_Chunks.GetSize();
189 FX_WCHAR* lpDstBuf = wsText.GetBuffer(nLength); 196 FX_WCHAR* lpDstBuf = wsText.GetBuffer(nLength);
190 int32_t nChunkIndex = cp.nChunkIndex; 197 int32_t nChunkIndex = cp.nChunkIndex;
191 FDE_LPCHUNKHEADER lpChunkHeader = m_Chunks[nChunkIndex]; 198 FDE_CHUNKHEADER* lpChunkHeader = m_Chunks[nChunkIndex];
192 int32_t nCopyLength = lpChunkHeader->nUsed - cp.nCharIndex; 199 int32_t nCopyLength = lpChunkHeader->nUsed - cp.nCharIndex;
193 FX_WCHAR* lpSrcBuf = lpChunkHeader->wChars + cp.nCharIndex; 200 FX_WCHAR* lpSrcBuf = lpChunkHeader->wChars + cp.nCharIndex;
194 while (nLeave > 0) { 201 while (nLeave > 0) {
195 if (nLeave <= nCopyLength) { 202 if (nLeave <= nCopyLength) {
196 nCopyLength = nLeave; 203 nCopyLength = nLeave;
197 } 204 }
198 FXSYS_memcpy(lpDstBuf, lpSrcBuf, nCopyLength * sizeof(FX_WCHAR)); 205 FXSYS_memcpy(lpDstBuf, lpSrcBuf, nCopyLength * sizeof(FX_WCHAR));
199 nChunkIndex++; 206 nChunkIndex++;
200 if (nChunkIndex >= nCount) { 207 if (nChunkIndex >= nCount) {
201 break; 208 break;
202 } 209 }
203 lpChunkHeader = m_Chunks[nChunkIndex]; 210 lpChunkHeader = m_Chunks[nChunkIndex];
204 lpSrcBuf = lpChunkHeader->wChars; 211 lpSrcBuf = lpChunkHeader->wChars;
205 nLeave -= nCopyLength; 212 nLeave -= nCopyLength;
206 lpDstBuf += nCopyLength; 213 lpDstBuf += nCopyLength;
207 nCopyLength = lpChunkHeader->nUsed; 214 nCopyLength = lpChunkHeader->nUsed;
208 } 215 }
209 wsText.ReleaseBuffer(); 216 wsText.ReleaseBuffer();
210 } 217 }
211 void CFDE_TxtEdtBuf::Insert(int32_t nPos, 218 void CFDE_TxtEdtBuf::Insert(int32_t nPos,
212 const FX_WCHAR* lpText, 219 const FX_WCHAR* lpText,
213 int32_t nLength) { 220 int32_t nLength) {
214 ASSERT(nPos >= 0 && nPos <= m_nTotal); 221 ASSERT(nPos >= 0 && nPos <= m_nTotal);
215 FDE_CHUNKPLACE cp; 222 FDE_CHUNKPLACE cp;
216 Index2CP(nPos, cp); 223 Index2CP(nPos, cp);
217 int32_t nLengthTemp = nLength; 224 int32_t nLengthTemp = nLength;
218 if (cp.nCharIndex != 0) { 225 if (cp.nCharIndex != 0) {
219 FDE_LPCHUNKHEADER lpNewChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc( 226 FDE_CHUNKHEADER* lpNewChunk =
220 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)); 227 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(
221 FDE_LPCHUNKHEADER lpChunk = m_Chunks[cp.nChunkIndex]; 228 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)));
229 FDE_CHUNKHEADER* lpChunk = m_Chunks[cp.nChunkIndex];
222 int32_t nCopy = lpChunk->nUsed - cp.nCharIndex; 230 int32_t nCopy = lpChunk->nUsed - cp.nCharIndex;
223 FXSYS_memcpy(lpNewChunk->wChars, lpChunk->wChars + cp.nCharIndex, 231 FXSYS_memcpy(lpNewChunk->wChars, lpChunk->wChars + cp.nCharIndex,
224 nCopy * sizeof(FX_WCHAR)); 232 nCopy * sizeof(FX_WCHAR));
225 lpChunk->nUsed -= nCopy; 233 lpChunk->nUsed -= nCopy;
226 cp.nChunkIndex++; 234 cp.nChunkIndex++;
227 m_Chunks.InsertAt(cp.nChunkIndex, lpNewChunk); 235 m_Chunks.InsertAt(cp.nChunkIndex, lpNewChunk);
228 lpNewChunk->nUsed = nCopy; 236 lpNewChunk->nUsed = nCopy;
229 cp.nCharIndex = 0; 237 cp.nCharIndex = 0;
230 } 238 }
231 if (cp.nChunkIndex != 0) { 239 if (cp.nChunkIndex != 0) {
232 FDE_LPCHUNKHEADER lpChunk = m_Chunks[cp.nChunkIndex - 1]; 240 FDE_CHUNKHEADER* lpChunk = m_Chunks[cp.nChunkIndex - 1];
233 if (lpChunk->nUsed != m_nChunkSize) { 241 if (lpChunk->nUsed != m_nChunkSize) {
234 cp.nChunkIndex--; 242 cp.nChunkIndex--;
235 int32_t nFree = m_nChunkSize - lpChunk->nUsed; 243 int32_t nFree = m_nChunkSize - lpChunk->nUsed;
236 int32_t nCopy = std::min(nLengthTemp, nFree); 244 int32_t nCopy = std::min(nLengthTemp, nFree);
237 FXSYS_memcpy(lpChunk->wChars + lpChunk->nUsed, lpText, 245 FXSYS_memcpy(lpChunk->wChars + lpChunk->nUsed, lpText,
238 nCopy * sizeof(FX_WCHAR)); 246 nCopy * sizeof(FX_WCHAR));
239 lpText += nCopy; 247 lpText += nCopy;
240 nLengthTemp -= nCopy; 248 nLengthTemp -= nCopy;
241 lpChunk->nUsed += nCopy; 249 lpChunk->nUsed += nCopy;
242 cp.nChunkIndex++; 250 cp.nChunkIndex++;
243 } 251 }
244 } 252 }
245 while (nLengthTemp > 0) { 253 while (nLengthTemp > 0) {
246 FDE_LPCHUNKHEADER lpChunk = (FDE_LPCHUNKHEADER)m_pAllocator->Alloc( 254 FDE_CHUNKHEADER* lpChunk =
247 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)); 255 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(
256 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR)));
248 ASSERT(lpChunk); 257 ASSERT(lpChunk);
249 int32_t nCopy = std::min(nLengthTemp, m_nChunkSize); 258 int32_t nCopy = std::min(nLengthTemp, m_nChunkSize);
250 FXSYS_memcpy(lpChunk->wChars, lpText, nCopy * sizeof(FX_WCHAR)); 259 FXSYS_memcpy(lpChunk->wChars, lpText, nCopy * sizeof(FX_WCHAR));
251 lpText += nCopy; 260 lpText += nCopy;
252 nLengthTemp -= nCopy; 261 nLengthTemp -= nCopy;
253 lpChunk->nUsed = nCopy; 262 lpChunk->nUsed = nCopy;
254 m_Chunks.InsertAt(cp.nChunkIndex, lpChunk); 263 m_Chunks.InsertAt(cp.nChunkIndex, lpChunk);
255 cp.nChunkIndex++; 264 cp.nChunkIndex++;
256 } 265 }
257 m_nTotal += nLength; 266 m_nTotal += nLength;
258 m_bChanged = TRUE; 267 m_bChanged = TRUE;
259 } 268 }
260 void CFDE_TxtEdtBuf::Delete(int32_t nIndex, int32_t nLength) { 269 void CFDE_TxtEdtBuf::Delete(int32_t nIndex, int32_t nLength) {
261 ASSERT(nLength > 0 && nIndex >= 0 && nIndex + nLength <= m_nTotal); 270 ASSERT(nLength > 0 && nIndex >= 0 && nIndex + nLength <= m_nTotal);
262 FDE_CHUNKPLACE cpEnd; 271 FDE_CHUNKPLACE cpEnd;
263 Index2CP(nIndex + nLength - 1, cpEnd); 272 Index2CP(nIndex + nLength - 1, cpEnd);
264 m_nTotal -= nLength; 273 m_nTotal -= nLength;
265 FDE_LPCHUNKHEADER lpChunk = m_Chunks[cpEnd.nChunkIndex]; 274 FDE_CHUNKHEADER* lpChunk = m_Chunks[cpEnd.nChunkIndex];
266 int32_t nFirstPart = cpEnd.nCharIndex + 1; 275 int32_t nFirstPart = cpEnd.nCharIndex + 1;
267 int32_t nMovePart = lpChunk->nUsed - nFirstPart; 276 int32_t nMovePart = lpChunk->nUsed - nFirstPart;
268 if (nMovePart != 0) { 277 if (nMovePart != 0) {
269 int32_t nDelete = std::min(nFirstPart, nLength); 278 int32_t nDelete = std::min(nFirstPart, nLength);
270 FXSYS_memmove(lpChunk->wChars + nFirstPart - nDelete, 279 FXSYS_memmove(lpChunk->wChars + nFirstPart - nDelete,
271 lpChunk->wChars + nFirstPart, nMovePart * sizeof(FX_WCHAR)); 280 lpChunk->wChars + nFirstPart, nMovePart * sizeof(FX_WCHAR));
272 lpChunk->nUsed -= nDelete; 281 lpChunk->nUsed -= nDelete;
273 nLength -= nDelete; 282 nLength -= nDelete;
274 cpEnd.nChunkIndex--; 283 cpEnd.nChunkIndex--;
275 } 284 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 318 }
310 if (m_nTotal == 0) { 319 if (m_nTotal == 0) {
311 return TRUE; 320 return TRUE;
312 } 321 }
313 int32_t nCount = m_Chunks.GetSize(); 322 int32_t nCount = m_Chunks.GetSize();
314 if (nCount == 0) { 323 if (nCount == 0) {
315 return TRUE; 324 return TRUE;
316 } 325 }
317 int32_t i = 0; 326 int32_t i = 0;
318 for (; i < nCount; i++) { 327 for (; i < nCount; i++) {
319 FDE_LPCHUNKHEADER lpChunk = m_Chunks[i]; 328 FDE_CHUNKHEADER* lpChunk = m_Chunks[i];
320 if (lpChunk->nUsed == 0) { 329 if (lpChunk->nUsed == 0) {
321 m_pAllocator->Free(lpChunk); 330 m_pAllocator->Free(lpChunk);
322 m_Chunks.RemoveAt(i); 331 m_Chunks.RemoveAt(i);
323 --i; 332 --i;
324 --nCount; 333 --nCount;
325 } 334 }
326 } 335 }
327 if (pPause != NULL && pPause->NeedToPauseNow()) { 336 if (pPause && pPause->NeedToPauseNow())
328 return FALSE; 337 return FALSE;
329 } 338
330 FDE_LPCHUNKHEADER lpPreChunk = m_Chunks[0]; 339 FDE_CHUNKHEADER* lpPreChunk = m_Chunks[0];
331 FDE_LPCHUNKHEADER lpCurChunk = NULL; 340 FDE_CHUNKHEADER* lpCurChunk = nullptr;
332 for (i = 1; i < nCount; i++) { 341 for (i = 1; i < nCount; i++) {
333 lpCurChunk = m_Chunks[i]; 342 lpCurChunk = m_Chunks[i];
334 if (lpPreChunk->nUsed + lpCurChunk->nUsed <= m_nChunkSize) { 343 if (lpPreChunk->nUsed + lpCurChunk->nUsed <= m_nChunkSize) {
335 FXSYS_memcpy(lpPreChunk->wChars + lpPreChunk->nUsed, lpCurChunk->wChars, 344 FXSYS_memcpy(lpPreChunk->wChars + lpPreChunk->nUsed, lpCurChunk->wChars,
336 lpCurChunk->nUsed * sizeof(FX_WCHAR)); 345 lpCurChunk->nUsed * sizeof(FX_WCHAR));
337 lpPreChunk->nUsed += lpCurChunk->nUsed; 346 lpPreChunk->nUsed += lpCurChunk->nUsed;
338 m_pAllocator->Free(lpCurChunk); 347 m_pAllocator->Free(lpCurChunk);
339 m_Chunks.RemoveAt(i); 348 m_Chunks.RemoveAt(i);
340 --i; 349 --i;
341 --nCount; 350 --nCount;
(...skipping 15 matching lines...) Expand all
357 m_pAllocator->Release(); 366 m_pAllocator->Release();
358 m_pAllocator = NULL; 367 m_pAllocator = NULL;
359 } 368 }
360 m_Chunks.RemoveAll(); 369 m_Chunks.RemoveAll();
361 m_nChunkSize = nChunkSize; 370 m_nChunkSize = nChunkSize;
362 int32_t nChunkLength = 371 int32_t nChunkLength =
363 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR); 372 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR);
364 m_pAllocator = 373 m_pAllocator =
365 FX_CreateAllocator(FX_ALLOCTYPE_Fixed, nDefChunkCount, nChunkLength); 374 FX_CreateAllocator(FX_ALLOCTYPE_Fixed, nDefChunkCount, nChunkLength);
366 ASSERT(m_pAllocator); 375 ASSERT(m_pAllocator);
367 FDE_LPCHUNKHEADER lpChunkHeader = 376 FDE_CHUNKHEADER* lpChunkHeader =
368 (FDE_LPCHUNKHEADER)m_pAllocator->Alloc(nChunkLength); 377 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(nChunkLength));
369 ASSERT(lpChunkHeader); 378 ASSERT(lpChunkHeader);
370 lpChunkHeader->nUsed = 0; 379 lpChunkHeader->nUsed = 0;
371 m_Chunks.Add(lpChunkHeader); 380 m_Chunks.Add(lpChunkHeader);
372 m_nTotal = 0; 381 m_nTotal = 0;
373 } 382 }
374 int32_t CFDE_TxtEdtBuf::CP2Index(const FDE_CHUNKPLACE& cp) const { 383 int32_t CFDE_TxtEdtBuf::CP2Index(const FDE_CHUNKPLACE& cp) const {
375 int32_t nTotal = cp.nCharIndex; 384 int32_t nTotal = cp.nCharIndex;
376 int32_t i = 0; 385 int32_t i = 0;
377 for (i = 0; i < cp.nChunkIndex; i++) { 386 for (i = 0; i < cp.nChunkIndex; i++) {
378 nTotal += m_Chunks[i]->nUsed; 387 nTotal += m_Chunks[i]->nUsed;
(...skipping 12 matching lines...) Expand all
391 int32_t nCount = m_Chunks.GetSize(); 400 int32_t nCount = m_Chunks.GetSize();
392 for (; i < nCount; i++) { 401 for (; i < nCount; i++) {
393 nTotal += m_Chunks[i]->nUsed; 402 nTotal += m_Chunks[i]->nUsed;
394 if (nTotal > nIndex) { 403 if (nTotal > nIndex) {
395 break; 404 break;
396 } 405 }
397 } 406 }
398 cp.nChunkIndex = i; 407 cp.nChunkIndex = i;
399 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); 408 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex);
400 } 409 }
OLDNEW
« no previous file with comments | « xfa/fee/fde_txtedtbuf.h ('k') | xfa/fee/fde_txtedtengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698