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/fee/fde_txtedtbuf.h" | 7 #include "xfa/fee/fde_txtedtbuf.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 m_bChanged(FALSE), | 115 m_bChanged(FALSE), |
116 m_pAllocator(NULL) { | 116 m_pAllocator(NULL) { |
117 ASSERT(m_nChunkSize); | 117 ASSERT(m_nChunkSize); |
118 ResetChunkBuffer(FDE_DEFCHUNKCOUNT, m_nChunkSize); | 118 ResetChunkBuffer(FDE_DEFCHUNKCOUNT, m_nChunkSize); |
119 } | 119 } |
120 void CFDE_TxtEdtBuf::Release() { | 120 void CFDE_TxtEdtBuf::Release() { |
121 delete this; | 121 delete this; |
122 } | 122 } |
123 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() { | 123 CFDE_TxtEdtBuf::~CFDE_TxtEdtBuf() { |
124 Clear(TRUE); | 124 Clear(TRUE); |
125 m_pAllocator->Release(); | 125 delete m_pAllocator; |
126 m_Chunks.RemoveAll(); | 126 m_Chunks.RemoveAll(); |
127 } | 127 } |
128 FX_BOOL CFDE_TxtEdtBuf::SetChunkSize(int32_t nChunkSize) { | 128 FX_BOOL CFDE_TxtEdtBuf::SetChunkSize(int32_t nChunkSize) { |
129 ASSERT(nChunkSize); | 129 ASSERT(nChunkSize); |
130 ResetChunkBuffer(FDE_DEFCHUNKCOUNT, nChunkSize); | 130 ResetChunkBuffer(FDE_DEFCHUNKCOUNT, nChunkSize); |
131 return TRUE; | 131 return TRUE; |
132 } | 132 } |
133 int32_t CFDE_TxtEdtBuf::GetChunkSize() const { | 133 int32_t CFDE_TxtEdtBuf::GetChunkSize() const { |
134 return m_nChunkSize; | 134 return m_nChunkSize; |
135 } | 135 } |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 return FALSE; | 355 return FALSE; |
356 } | 356 } |
357 } | 357 } |
358 m_bChanged = FALSE; | 358 m_bChanged = FALSE; |
359 return TRUE; | 359 return TRUE; |
360 } | 360 } |
361 void CFDE_TxtEdtBuf::ResetChunkBuffer(int32_t nDefChunkCount, | 361 void CFDE_TxtEdtBuf::ResetChunkBuffer(int32_t nDefChunkCount, |
362 int32_t nChunkSize) { | 362 int32_t nChunkSize) { |
363 ASSERT(nChunkSize); | 363 ASSERT(nChunkSize); |
364 ASSERT(nDefChunkCount); | 364 ASSERT(nDefChunkCount); |
365 if (m_pAllocator) { | 365 delete m_pAllocator; |
366 m_pAllocator->Release(); | 366 m_pAllocator = nullptr; |
367 m_pAllocator = NULL; | |
368 } | |
369 m_Chunks.RemoveAll(); | 367 m_Chunks.RemoveAll(); |
370 m_nChunkSize = nChunkSize; | 368 m_nChunkSize = nChunkSize; |
371 int32_t nChunkLength = | 369 int32_t nChunkLength = |
372 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR); | 370 sizeof(FDE_CHUNKHEADER) + (m_nChunkSize - 1) * sizeof(FX_WCHAR); |
373 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Fixed, nDefChunkCount, | 371 m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Fixed, nDefChunkCount, |
374 nChunkLength); | 372 nChunkLength); |
375 FDE_CHUNKHEADER* lpChunkHeader = | 373 FDE_CHUNKHEADER* lpChunkHeader = |
376 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(nChunkLength)); | 374 static_cast<FDE_CHUNKHEADER*>(m_pAllocator->Alloc(nChunkLength)); |
377 ASSERT(lpChunkHeader); | 375 ASSERT(lpChunkHeader); |
378 lpChunkHeader->nUsed = 0; | 376 lpChunkHeader->nUsed = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
399 int32_t nCount = m_Chunks.GetSize(); | 397 int32_t nCount = m_Chunks.GetSize(); |
400 for (; i < nCount; i++) { | 398 for (; i < nCount; i++) { |
401 nTotal += m_Chunks[i]->nUsed; | 399 nTotal += m_Chunks[i]->nUsed; |
402 if (nTotal > nIndex) { | 400 if (nTotal > nIndex) { |
403 break; | 401 break; |
404 } | 402 } |
405 } | 403 } |
406 cp.nChunkIndex = i; | 404 cp.nChunkIndex = i; |
407 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); | 405 cp.nCharIndex = m_Chunks[i]->nUsed - (nTotal - nIndex); |
408 } | 406 } |
OLD | NEW |