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 "../../include/fxcrt/fx_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); | 8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); |
9 CFX_BinaryBuf::CFX_BinaryBuf() | 9 CFX_BinaryBuf::CFX_BinaryBuf() |
10 : m_AllocStep(0) | 10 : m_AllocStep(0) |
11 , m_pBuffer(NULL) | 11 , m_pBuffer(NULL) |
12 , m_DataSize(0) | 12 , m_DataSize(0) |
13 , m_AllocSize(0) | 13 , m_AllocSize(0) |
14 { | 14 { |
15 } | 15 } |
16 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) | 16 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) |
17 : m_AllocStep(0) | 17 : m_AllocStep(0) |
18 , m_DataSize(size) | 18 , m_DataSize(size) |
19 , m_AllocSize(size) | 19 , m_AllocSize(size) |
20 { | 20 { |
21 m_pBuffer = FX_Alloc(FX_BYTE, size); | 21 m_pBuffer = FX_Alloc(uint8_t, size); |
22 } | 22 } |
23 CFX_BinaryBuf::~CFX_BinaryBuf() | 23 CFX_BinaryBuf::~CFX_BinaryBuf() |
24 { | 24 { |
25 if (m_pBuffer) { | 25 if (m_pBuffer) { |
26 FX_Free(m_pBuffer); | 26 FX_Free(m_pBuffer); |
27 } | 27 } |
28 } | 28 } |
29 void CFX_BinaryBuf::Delete(int start_index, int count) | 29 void CFX_BinaryBuf::Delete(int start_index, int count) |
30 { | 30 { |
31 if (!m_pBuffer || start_index < 0 || start_index + count > m_DataSize) { | 31 if (!m_pBuffer || start_index < 0 || start_index + count > m_DataSize) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 alloc_step = m_AllocSize / 4; | 77 alloc_step = m_AllocSize / 4; |
78 if (alloc_step < 128 ) { | 78 if (alloc_step < 128 ) { |
79 alloc_step = 128; | 79 alloc_step = 128; |
80 } | 80 } |
81 } else { | 81 } else { |
82 alloc_step = m_AllocStep; | 82 alloc_step = m_AllocStep; |
83 } | 83 } |
84 new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step; | 84 new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step; |
85 FX_LPBYTE pNewBuffer = m_pBuffer; | 85 FX_LPBYTE pNewBuffer = m_pBuffer; |
86 if (pNewBuffer) { | 86 if (pNewBuffer) { |
87 pNewBuffer = FX_Realloc(FX_BYTE, m_pBuffer, new_size); | 87 pNewBuffer = FX_Realloc(uint8_t, m_pBuffer, new_size); |
88 } else { | 88 } else { |
89 pNewBuffer = FX_Alloc(FX_BYTE, new_size); | 89 pNewBuffer = FX_Alloc(uint8_t, new_size); |
90 } | 90 } |
91 m_pBuffer = pNewBuffer; | 91 m_pBuffer = pNewBuffer; |
92 m_AllocSize = new_size; | 92 m_AllocSize = new_size; |
93 } | 93 } |
94 void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) | 94 void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) |
95 { | 95 { |
96 if (size == 0) { | 96 if (size == 0) { |
97 m_DataSize = 0; | 97 m_DataSize = 0; |
98 return; | 98 return; |
99 } | 99 } |
(...skipping 19 matching lines...) Expand all Loading... |
119 ExpandBuf(size); | 119 ExpandBuf(size); |
120 if (!m_pBuffer) { | 120 if (!m_pBuffer) { |
121 return; | 121 return; |
122 } | 122 } |
123 FXSYS_memmove32(m_pBuffer + pos + size, m_pBuffer + pos, m_DataSize - pos); | 123 FXSYS_memmove32(m_pBuffer + pos + size, m_pBuffer + pos, m_DataSize - pos); |
124 if (pBuf) { | 124 if (pBuf) { |
125 FXSYS_memcpy32(m_pBuffer + pos, pBuf, size); | 125 FXSYS_memcpy32(m_pBuffer + pos, pBuf, size); |
126 } | 126 } |
127 m_DataSize += size; | 127 m_DataSize += size; |
128 } | 128 } |
129 void CFX_BinaryBuf::AppendFill(FX_BYTE byte, FX_STRSIZE count) | 129 void CFX_BinaryBuf::AppendFill(uint8_t byte, FX_STRSIZE count) |
130 { | 130 { |
131 ExpandBuf(count); | 131 ExpandBuf(count); |
132 if (!m_pBuffer) { | 132 if (!m_pBuffer) { |
133 return; | 133 return; |
134 } | 134 } |
135 FXSYS_memset8(m_pBuffer + m_DataSize, byte, count); | 135 FXSYS_memset8(m_pBuffer + m_DataSize, byte, count); |
136 m_DataSize += count; | 136 m_DataSize += count; |
137 } | 137 } |
138 CFX_ByteStringC CFX_BinaryBuf::GetByteString() const | 138 CFX_ByteStringC CFX_BinaryBuf::GetByteString() const |
139 { | 139 { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return *this; | 235 return *this; |
236 } | 236 } |
237 void CFX_WideTextBuf::operator =(FX_WSTR str) | 237 void CFX_WideTextBuf::operator =(FX_WSTR str) |
238 { | 238 { |
239 CopyData(str.GetPtr(), str.GetLength() * sizeof(FX_WCHAR)); | 239 CopyData(str.GetPtr(), str.GetLength() * sizeof(FX_WCHAR)); |
240 } | 240 } |
241 CFX_WideStringC CFX_WideTextBuf::GetWideString() const | 241 CFX_WideStringC CFX_WideTextBuf::GetWideString() const |
242 { | 242 { |
243 return CFX_WideStringC((FX_LPCWSTR)m_pBuffer, m_DataSize / sizeof(FX_WCHAR))
; | 243 return CFX_WideStringC((FX_LPCWSTR)m_pBuffer, m_DataSize / sizeof(FX_WCHAR))
; |
244 } | 244 } |
245 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (FX_BYTE i) | 245 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (uint8_t i) |
246 { | 246 { |
247 if (m_pStream) { | 247 if (m_pStream) { |
248 m_pStream->WriteBlock(&i, 1); | 248 m_pStream->WriteBlock(&i, 1); |
249 } else { | 249 } else { |
250 m_SavingBuf.AppendByte(i); | 250 m_SavingBuf.AppendByte(i); |
251 } | 251 } |
252 return *this; | 252 return *this; |
253 } | 253 } |
254 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (int i) | 254 CFX_ArchiveSaver& CFX_ArchiveSaver::operator << (int i) |
255 { | 255 { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 CFX_ArchiveLoader::CFX_ArchiveLoader(FX_LPCBYTE pData, FX_DWORD dwSize) | 318 CFX_ArchiveLoader::CFX_ArchiveLoader(FX_LPCBYTE pData, FX_DWORD dwSize) |
319 { | 319 { |
320 m_pLoadingBuf = pData; | 320 m_pLoadingBuf = pData; |
321 m_LoadingPos = 0; | 321 m_LoadingPos = 0; |
322 m_LoadingSize = dwSize; | 322 m_LoadingSize = dwSize; |
323 } | 323 } |
324 FX_BOOL CFX_ArchiveLoader::IsEOF() | 324 FX_BOOL CFX_ArchiveLoader::IsEOF() |
325 { | 325 { |
326 return m_LoadingPos >= m_LoadingSize; | 326 return m_LoadingPos >= m_LoadingSize; |
327 } | 327 } |
328 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (FX_BYTE& i) | 328 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (uint8_t& i) |
329 { | 329 { |
330 if (m_LoadingPos >= m_LoadingSize) { | 330 if (m_LoadingPos >= m_LoadingSize) { |
331 return *this; | 331 return *this; |
332 } | 332 } |
333 i = m_pLoadingBuf[m_LoadingPos++]; | 333 i = m_pLoadingBuf[m_LoadingPos++]; |
334 return *this; | 334 return *this; |
335 } | 335 } |
336 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (int& i) | 336 CFX_ArchiveLoader& CFX_ArchiveLoader::operator >> (int& i) |
337 { | 337 { |
338 Read(&i, sizeof(int)); | 338 Read(&i, sizeof(int)); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 FX_Free(m_pBuffer); | 440 FX_Free(m_pBuffer); |
441 m_pBuffer = NULL; | 441 m_pBuffer = NULL; |
442 } | 442 } |
443 } | 443 } |
444 FX_BOOL IFX_BufferArchive::Flush() | 444 FX_BOOL IFX_BufferArchive::Flush() |
445 { | 445 { |
446 FX_BOOL bRet = DoWork(m_pBuffer, m_Length); | 446 FX_BOOL bRet = DoWork(m_pBuffer, m_Length); |
447 m_Length = 0; | 447 m_Length = 0; |
448 return bRet; | 448 return bRet; |
449 } | 449 } |
450 FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) | 450 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) |
451 { | 451 { |
452 if (!pBuf || size < 1) { | 452 if (!pBuf || size < 1) { |
453 return 0; | 453 return 0; |
454 } | 454 } |
455 if (!m_pBuffer) { | 455 if (!m_pBuffer) { |
456 m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize); | 456 m_pBuffer = FX_Alloc(uint8_t, m_BufSize); |
457 } | 457 } |
458 FX_LPBYTE buffer = (FX_LPBYTE)pBuf; | 458 FX_LPBYTE buffer = (FX_LPBYTE)pBuf; |
459 FX_STRSIZE temp_size = (FX_STRSIZE)size; | 459 FX_STRSIZE temp_size = (FX_STRSIZE)size; |
460 while (temp_size > 0) { | 460 while (temp_size > 0) { |
461 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size
); | 461 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size
); |
462 FXSYS_memcpy32(m_pBuffer + m_Length, buffer, buf_size); | 462 FXSYS_memcpy32(m_pBuffer + m_Length, buffer, buf_size); |
463 m_Length += buf_size; | 463 m_Length += buf_size; |
464 if (m_Length == m_BufSize) { | 464 if (m_Length == m_BufSize) { |
465 if (!Flush()) { | 465 if (!Flush()) { |
466 return -1; | 466 return -1; |
467 } | 467 } |
468 } | 468 } |
469 temp_size -= buf_size; | 469 temp_size -= buf_size; |
470 buffer += buf_size; | 470 buffer += buf_size; |
471 } | 471 } |
472 return (FX_INT32)size; | 472 return (int32_t)size; |
473 } | 473 } |
474 FX_INT32 IFX_BufferArchive::AppendByte(FX_BYTE byte) | 474 int32_t IFX_BufferArchive::AppendByte(uint8_t byte) |
475 { | 475 { |
476 return AppendBlock(&byte, 1); | 476 return AppendBlock(&byte, 1); |
477 } | 477 } |
478 FX_INT32 IFX_BufferArchive::AppendDWord(FX_DWORD i) | 478 int32_t IFX_BufferArchive::AppendDWord(FX_DWORD i) |
479 { | 479 { |
480 char buf[32]; | 480 char buf[32]; |
481 FXSYS_itoa(i, buf, 10); | 481 FXSYS_itoa(i, buf, 10); |
482 return AppendBlock(buf, (size_t)FXSYS_strlen(buf)); | 482 return AppendBlock(buf, (size_t)FXSYS_strlen(buf)); |
483 } | 483 } |
484 FX_INT32 IFX_BufferArchive::AppendString(FX_BSTR lpsz) | 484 int32_t IFX_BufferArchive::AppendString(FX_BSTR lpsz) |
485 { | 485 { |
486 return AppendBlock(lpsz.GetPtr(), lpsz.GetLength()); | 486 return AppendBlock(lpsz.GetPtr(), lpsz.GetLength()); |
487 } | 487 } |
488 CFX_FileBufferArchive::CFX_FileBufferArchive(FX_STRSIZE size) | 488 CFX_FileBufferArchive::CFX_FileBufferArchive(FX_STRSIZE size) |
489 : IFX_BufferArchive(size) | 489 : IFX_BufferArchive(size) |
490 , m_pFile(NULL) | 490 , m_pFile(NULL) |
491 , m_bTakeover(FALSE) | 491 , m_bTakeover(FALSE) |
492 { | 492 { |
493 } | 493 } |
494 CFX_FileBufferArchive::~CFX_FileBufferArchive() | 494 CFX_FileBufferArchive::~CFX_FileBufferArchive() |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) | 549 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) |
550 { | 550 { |
551 if (!m_pFile) { | 551 if (!m_pFile) { |
552 return FALSE; | 552 return FALSE; |
553 } | 553 } |
554 if (!pBuf || size < 1) { | 554 if (!pBuf || size < 1) { |
555 return TRUE; | 555 return TRUE; |
556 } | 556 } |
557 return m_pFile->WriteBlock(pBuf, size); | 557 return m_pFile->WriteBlock(pBuf, size); |
558 } | 558 } |
OLD | NEW |