| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return *this; | 109 return *this; |
| 110 } | 110 } |
| 111 | 111 |
| 112 CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(int i) { | 112 CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(int i) { |
| 113 char buf[32]; | 113 char buf[32]; |
| 114 FXSYS_itoa(i, buf, 10); | 114 FXSYS_itoa(i, buf, 10); |
| 115 AppendBlock(buf, FXSYS_strlen(buf)); | 115 AppendBlock(buf, FXSYS_strlen(buf)); |
| 116 return *this; | 116 return *this; |
| 117 } | 117 } |
| 118 | 118 |
| 119 CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(FX_DWORD i) { | 119 CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(uint32_t i) { |
| 120 char buf[32]; | 120 char buf[32]; |
| 121 FXSYS_itoa(i, buf, 10); | 121 FXSYS_itoa(i, buf, 10); |
| 122 AppendBlock(buf, FXSYS_strlen(buf)); | 122 AppendBlock(buf, FXSYS_strlen(buf)); |
| 123 return *this; | 123 return *this; |
| 124 } | 124 } |
| 125 | 125 |
| 126 CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(double f) { | 126 CFX_ByteTextBuf& CFX_ByteTextBuf::operator<<(double f) { |
| 127 char buf[32]; | 127 char buf[32]; |
| 128 FX_STRSIZE len = FX_ftoa((FX_FLOAT)f, buf); | 128 FX_STRSIZE len = FX_ftoa((FX_FLOAT)f, buf); |
| 129 AppendBlock(buf, len); | 129 AppendBlock(buf, len); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return *this; | 201 return *this; |
| 202 } | 202 } |
| 203 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(int i) { | 203 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(int i) { |
| 204 if (m_pStream) { | 204 if (m_pStream) { |
| 205 m_pStream->WriteBlock(&i, sizeof(int)); | 205 m_pStream->WriteBlock(&i, sizeof(int)); |
| 206 } else { | 206 } else { |
| 207 m_SavingBuf.AppendBlock(&i, sizeof(int)); | 207 m_SavingBuf.AppendBlock(&i, sizeof(int)); |
| 208 } | 208 } |
| 209 return *this; | 209 return *this; |
| 210 } | 210 } |
| 211 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_DWORD i) { | 211 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(uint32_t i) { |
| 212 if (m_pStream) { | 212 if (m_pStream) { |
| 213 m_pStream->WriteBlock(&i, sizeof(FX_DWORD)); | 213 m_pStream->WriteBlock(&i, sizeof(uint32_t)); |
| 214 } else { | 214 } else { |
| 215 m_SavingBuf.AppendBlock(&i, sizeof(FX_DWORD)); | 215 m_SavingBuf.AppendBlock(&i, sizeof(uint32_t)); |
| 216 } | 216 } |
| 217 return *this; | 217 return *this; |
| 218 } | 218 } |
| 219 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_FLOAT f) { | 219 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_FLOAT f) { |
| 220 if (m_pStream) { | 220 if (m_pStream) { |
| 221 m_pStream->WriteBlock(&f, sizeof(FX_FLOAT)); | 221 m_pStream->WriteBlock(&f, sizeof(FX_FLOAT)); |
| 222 } else { | 222 } else { |
| 223 m_SavingBuf.AppendBlock(&f, sizeof(FX_FLOAT)); | 223 m_SavingBuf.AppendBlock(&f, sizeof(FX_FLOAT)); |
| 224 } | 224 } |
| 225 return *this; | 225 return *this; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 250 CFX_ByteString encoded = wstr.UTF16LE_Encode(); | 250 CFX_ByteString encoded = wstr.UTF16LE_Encode(); |
| 251 return operator<<(encoded); | 251 return operator<<(encoded); |
| 252 } | 252 } |
| 253 void CFX_ArchiveSaver::Write(const void* pData, FX_STRSIZE dwSize) { | 253 void CFX_ArchiveSaver::Write(const void* pData, FX_STRSIZE dwSize) { |
| 254 if (m_pStream) { | 254 if (m_pStream) { |
| 255 m_pStream->WriteBlock(pData, dwSize); | 255 m_pStream->WriteBlock(pData, dwSize); |
| 256 } else { | 256 } else { |
| 257 m_SavingBuf.AppendBlock(pData, dwSize); | 257 m_SavingBuf.AppendBlock(pData, dwSize); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 CFX_ArchiveLoader::CFX_ArchiveLoader(const uint8_t* pData, FX_DWORD dwSize) { | 260 CFX_ArchiveLoader::CFX_ArchiveLoader(const uint8_t* pData, uint32_t dwSize) { |
| 261 m_pLoadingBuf = pData; | 261 m_pLoadingBuf = pData; |
| 262 m_LoadingPos = 0; | 262 m_LoadingPos = 0; |
| 263 m_LoadingSize = dwSize; | 263 m_LoadingSize = dwSize; |
| 264 } | 264 } |
| 265 FX_BOOL CFX_ArchiveLoader::IsEOF() { | 265 FX_BOOL CFX_ArchiveLoader::IsEOF() { |
| 266 return m_LoadingPos >= m_LoadingSize; | 266 return m_LoadingPos >= m_LoadingSize; |
| 267 } | 267 } |
| 268 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint8_t& i) { | 268 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint8_t& i) { |
| 269 if (m_LoadingPos >= m_LoadingSize) { | 269 if (m_LoadingPos >= m_LoadingSize) { |
| 270 return *this; | 270 return *this; |
| 271 } | 271 } |
| 272 i = m_pLoadingBuf[m_LoadingPos++]; | 272 i = m_pLoadingBuf[m_LoadingPos++]; |
| 273 return *this; | 273 return *this; |
| 274 } | 274 } |
| 275 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(int& i) { | 275 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(int& i) { |
| 276 Read(&i, sizeof(int)); | 276 Read(&i, sizeof(int)); |
| 277 return *this; | 277 return *this; |
| 278 } | 278 } |
| 279 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_DWORD& i) { | 279 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint32_t& i) { |
| 280 Read(&i, sizeof(FX_DWORD)); | 280 Read(&i, sizeof(uint32_t)); |
| 281 return *this; | 281 return *this; |
| 282 } | 282 } |
| 283 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_FLOAT& i) { | 283 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_FLOAT& i) { |
| 284 Read(&i, sizeof(FX_FLOAT)); | 284 Read(&i, sizeof(FX_FLOAT)); |
| 285 return *this; | 285 return *this; |
| 286 } | 286 } |
| 287 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_ByteString& str) { | 287 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_ByteString& str) { |
| 288 if (m_LoadingPos + 4 > m_LoadingSize) { | 288 if (m_LoadingPos + 4 > m_LoadingSize) { |
| 289 return *this; | 289 return *this; |
| 290 } | 290 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 301 return *this; | 301 return *this; |
| 302 } | 302 } |
| 303 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_WideString& str) { | 303 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_WideString& str) { |
| 304 CFX_ByteString encoded; | 304 CFX_ByteString encoded; |
| 305 operator>>(encoded); | 305 operator>>(encoded); |
| 306 str = CFX_WideString::FromUTF16LE( | 306 str = CFX_WideString::FromUTF16LE( |
| 307 reinterpret_cast<const unsigned short*>(encoded.c_str()), | 307 reinterpret_cast<const unsigned short*>(encoded.c_str()), |
| 308 encoded.GetLength() / sizeof(unsigned short)); | 308 encoded.GetLength() / sizeof(unsigned short)); |
| 309 return *this; | 309 return *this; |
| 310 } | 310 } |
| 311 FX_BOOL CFX_ArchiveLoader::Read(void* pBuf, FX_DWORD dwSize) { | 311 FX_BOOL CFX_ArchiveLoader::Read(void* pBuf, uint32_t dwSize) { |
| 312 if (m_LoadingPos + dwSize > m_LoadingSize) { | 312 if (m_LoadingPos + dwSize > m_LoadingSize) { |
| 313 return FALSE; | 313 return FALSE; |
| 314 } | 314 } |
| 315 FXSYS_memcpy(pBuf, m_pLoadingBuf + m_LoadingPos, dwSize); | 315 FXSYS_memcpy(pBuf, m_pLoadingBuf + m_LoadingPos, dwSize); |
| 316 m_LoadingPos += dwSize; | 316 m_LoadingPos += dwSize; |
| 317 return TRUE; | 317 return TRUE; |
| 318 } | 318 } |
| 319 #endif // PDF_ENABLE_XFA | 319 #endif // PDF_ENABLE_XFA |
| 320 | 320 |
| 321 void CFX_BitStream::Init(const uint8_t* pData, FX_DWORD dwSize) { | 321 void CFX_BitStream::Init(const uint8_t* pData, uint32_t dwSize) { |
| 322 m_pData = pData; | 322 m_pData = pData; |
| 323 m_BitSize = dwSize * 8; | 323 m_BitSize = dwSize * 8; |
| 324 m_BitPos = 0; | 324 m_BitPos = 0; |
| 325 } | 325 } |
| 326 void CFX_BitStream::ByteAlign() { | 326 void CFX_BitStream::ByteAlign() { |
| 327 int mod = m_BitPos % 8; | 327 int mod = m_BitPos % 8; |
| 328 if (mod == 0) { | 328 if (mod == 0) { |
| 329 return; | 329 return; |
| 330 } | 330 } |
| 331 m_BitPos += 8 - mod; | 331 m_BitPos += 8 - mod; |
| 332 } | 332 } |
| 333 FX_DWORD CFX_BitStream::GetBits(FX_DWORD nBits) { | 333 uint32_t CFX_BitStream::GetBits(uint32_t nBits) { |
| 334 if (nBits > m_BitSize || m_BitPos + nBits > m_BitSize) { | 334 if (nBits > m_BitSize || m_BitPos + nBits > m_BitSize) { |
| 335 return 0; | 335 return 0; |
| 336 } | 336 } |
| 337 if (nBits == 1) { | 337 if (nBits == 1) { |
| 338 int bit = (m_pData[m_BitPos / 8] & (1 << (7 - m_BitPos % 8))) ? 1 : 0; | 338 int bit = (m_pData[m_BitPos / 8] & (1 << (7 - m_BitPos % 8))) ? 1 : 0; |
| 339 m_BitPos++; | 339 m_BitPos++; |
| 340 return bit; | 340 return bit; |
| 341 } | 341 } |
| 342 FX_DWORD byte_pos = m_BitPos / 8; | 342 uint32_t byte_pos = m_BitPos / 8; |
| 343 FX_DWORD bit_pos = m_BitPos % 8, bit_left = nBits; | 343 uint32_t bit_pos = m_BitPos % 8, bit_left = nBits; |
| 344 FX_DWORD result = 0; | 344 uint32_t result = 0; |
| 345 if (bit_pos) { | 345 if (bit_pos) { |
| 346 if (8 - bit_pos >= bit_left) { | 346 if (8 - bit_pos >= bit_left) { |
| 347 result = | 347 result = |
| 348 (m_pData[byte_pos] & (0xff >> bit_pos)) >> (8 - bit_pos - bit_left); | 348 (m_pData[byte_pos] & (0xff >> bit_pos)) >> (8 - bit_pos - bit_left); |
| 349 m_BitPos += bit_left; | 349 m_BitPos += bit_left; |
| 350 return result; | 350 return result; |
| 351 } | 351 } |
| 352 bit_left -= 8 - bit_pos; | 352 bit_left -= 8 - bit_pos; |
| 353 result = (m_pData[byte_pos++] & ((1 << (8 - bit_pos)) - 1)) << bit_left; | 353 result = (m_pData[byte_pos++] & ((1 << (8 - bit_pos)) - 1)) << bit_left; |
| 354 } | 354 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 temp_size -= buf_size; | 405 temp_size -= buf_size; |
| 406 buffer += buf_size; | 406 buffer += buf_size; |
| 407 } | 407 } |
| 408 return pdfium::base::checked_cast<int32_t>(size); | 408 return pdfium::base::checked_cast<int32_t>(size); |
| 409 } | 409 } |
| 410 | 410 |
| 411 int32_t CFX_FileBufferArchive::AppendByte(uint8_t byte) { | 411 int32_t CFX_FileBufferArchive::AppendByte(uint8_t byte) { |
| 412 return AppendBlock(&byte, 1); | 412 return AppendBlock(&byte, 1); |
| 413 } | 413 } |
| 414 | 414 |
| 415 int32_t CFX_FileBufferArchive::AppendDWord(FX_DWORD i) { | 415 int32_t CFX_FileBufferArchive::AppendDWord(uint32_t i) { |
| 416 char buf[32]; | 416 char buf[32]; |
| 417 FXSYS_itoa(i, buf, 10); | 417 FXSYS_itoa(i, buf, 10); |
| 418 return AppendBlock(buf, (size_t)FXSYS_strlen(buf)); | 418 return AppendBlock(buf, (size_t)FXSYS_strlen(buf)); |
| 419 } | 419 } |
| 420 | 420 |
| 421 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { | 421 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { |
| 422 return AppendBlock(lpsz.GetPtr(), lpsz.GetLength()); | 422 return AppendBlock(lpsz.GetPtr(), lpsz.GetLength()); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void CFX_FileBufferArchive::AttachFile(IFX_StreamWrite* pFile) { | 425 void CFX_FileBufferArchive::AttachFile(IFX_StreamWrite* pFile) { |
| 426 FXSYS_assert(pFile); | 426 FXSYS_assert(pFile); |
| 427 m_pFile = pFile; | 427 m_pFile = pFile; |
| 428 } | 428 } |
| OLD | NEW |