| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const FX_WCHAR* lpsz) { | 175 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const FX_WCHAR* lpsz) { |
| 176 AppendBlock(lpsz, FXSYS_wcslen(lpsz) * sizeof(FX_WCHAR)); | 176 AppendBlock(lpsz, FXSYS_wcslen(lpsz) * sizeof(FX_WCHAR)); |
| 177 return *this; | 177 return *this; |
| 178 } | 178 } |
| 179 | 179 |
| 180 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) { | 180 CFX_WideTextBuf& CFX_WideTextBuf::operator<<(const CFX_WideTextBuf& buf) { |
| 181 AppendBlock(buf.m_pBuffer.get(), buf.m_DataSize); | 181 AppendBlock(buf.m_pBuffer.get(), buf.m_DataSize); |
| 182 return *this; | 182 return *this; |
| 183 } | 183 } |
| 184 | 184 |
| 185 #ifdef PDF_ENABLE_XFA | |
| 186 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(uint8_t i) { | |
| 187 if (m_pStream) { | |
| 188 m_pStream->WriteBlock(&i, 1); | |
| 189 } else { | |
| 190 m_SavingBuf.AppendByte(i); | |
| 191 } | |
| 192 return *this; | |
| 193 } | |
| 194 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(int i) { | |
| 195 if (m_pStream) { | |
| 196 m_pStream->WriteBlock(&i, sizeof(int)); | |
| 197 } else { | |
| 198 m_SavingBuf.AppendBlock(&i, sizeof(int)); | |
| 199 } | |
| 200 return *this; | |
| 201 } | |
| 202 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(uint32_t i) { | |
| 203 if (m_pStream) { | |
| 204 m_pStream->WriteBlock(&i, sizeof(uint32_t)); | |
| 205 } else { | |
| 206 m_SavingBuf.AppendBlock(&i, sizeof(uint32_t)); | |
| 207 } | |
| 208 return *this; | |
| 209 } | |
| 210 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_FLOAT f) { | |
| 211 if (m_pStream) { | |
| 212 m_pStream->WriteBlock(&f, sizeof(FX_FLOAT)); | |
| 213 } else { | |
| 214 m_SavingBuf.AppendBlock(&f, sizeof(FX_FLOAT)); | |
| 215 } | |
| 216 return *this; | |
| 217 } | |
| 218 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const CFX_ByteStringC& bstr) { | |
| 219 int len = bstr.GetLength(); | |
| 220 if (m_pStream) { | |
| 221 m_pStream->WriteBlock(&len, sizeof(int)); | |
| 222 m_pStream->WriteBlock(bstr.raw_str(), len); | |
| 223 } else { | |
| 224 m_SavingBuf.AppendBlock(&len, sizeof(int)); | |
| 225 m_SavingBuf.AppendBlock(bstr.raw_str(), len); | |
| 226 } | |
| 227 return *this; | |
| 228 } | |
| 229 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const FX_WCHAR* wstr) { | |
| 230 FX_STRSIZE len = FXSYS_wcslen(wstr); | |
| 231 if (m_pStream) { | |
| 232 m_pStream->WriteBlock(&len, sizeof(int)); | |
| 233 m_pStream->WriteBlock(wstr, len); | |
| 234 } else { | |
| 235 m_SavingBuf.AppendBlock(&len, sizeof(int)); | |
| 236 m_SavingBuf.AppendBlock(wstr, len); | |
| 237 } | |
| 238 return *this; | |
| 239 } | |
| 240 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const CFX_WideString& wstr) { | |
| 241 CFX_ByteString encoded = wstr.UTF16LE_Encode(); | |
| 242 return operator<<(encoded.AsStringC()); | |
| 243 } | |
| 244 void CFX_ArchiveSaver::Write(const void* pData, FX_STRSIZE dwSize) { | |
| 245 if (m_pStream) { | |
| 246 m_pStream->WriteBlock(pData, dwSize); | |
| 247 } else { | |
| 248 m_SavingBuf.AppendBlock(pData, dwSize); | |
| 249 } | |
| 250 } | |
| 251 CFX_ArchiveLoader::CFX_ArchiveLoader(const uint8_t* pData, uint32_t dwSize) { | |
| 252 m_pLoadingBuf = pData; | |
| 253 m_LoadingPos = 0; | |
| 254 m_LoadingSize = dwSize; | |
| 255 } | |
| 256 FX_BOOL CFX_ArchiveLoader::IsEOF() { | |
| 257 return m_LoadingPos >= m_LoadingSize; | |
| 258 } | |
| 259 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint8_t& i) { | |
| 260 if (m_LoadingPos >= m_LoadingSize) { | |
| 261 return *this; | |
| 262 } | |
| 263 i = m_pLoadingBuf[m_LoadingPos++]; | |
| 264 return *this; | |
| 265 } | |
| 266 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(int& i) { | |
| 267 Read(&i, sizeof(int)); | |
| 268 return *this; | |
| 269 } | |
| 270 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint32_t& i) { | |
| 271 Read(&i, sizeof(uint32_t)); | |
| 272 return *this; | |
| 273 } | |
| 274 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_FLOAT& i) { | |
| 275 Read(&i, sizeof(FX_FLOAT)); | |
| 276 return *this; | |
| 277 } | |
| 278 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_ByteString& str) { | |
| 279 if (m_LoadingPos + 4 > m_LoadingSize) { | |
| 280 return *this; | |
| 281 } | |
| 282 int len; | |
| 283 operator>>(len); | |
| 284 str.clear(); | |
| 285 if (len <= 0 || m_LoadingPos + len > m_LoadingSize) { | |
| 286 return *this; | |
| 287 } | |
| 288 FX_CHAR* buffer = str.GetBuffer(len); | |
| 289 FXSYS_memcpy(buffer, m_pLoadingBuf + m_LoadingPos, len); | |
| 290 str.ReleaseBuffer(len); | |
| 291 m_LoadingPos += len; | |
| 292 return *this; | |
| 293 } | |
| 294 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_WideString& str) { | |
| 295 CFX_ByteString encoded; | |
| 296 operator>>(encoded); | |
| 297 str = CFX_WideString::FromUTF16LE( | |
| 298 reinterpret_cast<const unsigned short*>(encoded.c_str()), | |
| 299 encoded.GetLength() / sizeof(unsigned short)); | |
| 300 return *this; | |
| 301 } | |
| 302 FX_BOOL CFX_ArchiveLoader::Read(void* pBuf, uint32_t dwSize) { | |
| 303 if (m_LoadingPos + dwSize > m_LoadingSize) { | |
| 304 return FALSE; | |
| 305 } | |
| 306 FXSYS_memcpy(pBuf, m_pLoadingBuf + m_LoadingPos, dwSize); | |
| 307 m_LoadingPos += dwSize; | |
| 308 return TRUE; | |
| 309 } | |
| 310 #endif // PDF_ENABLE_XFA | |
| 311 | |
| 312 void CFX_BitStream::Init(const uint8_t* pData, uint32_t dwSize) { | 185 void CFX_BitStream::Init(const uint8_t* pData, uint32_t dwSize) { |
| 313 m_pData = pData; | 186 m_pData = pData; |
| 314 m_BitSize = dwSize * 8; | 187 m_BitSize = dwSize * 8; |
| 315 m_BitPos = 0; | 188 m_BitPos = 0; |
| 316 } | 189 } |
| 317 void CFX_BitStream::ByteAlign() { | 190 void CFX_BitStream::ByteAlign() { |
| 318 int mod = m_BitPos % 8; | 191 int mod = m_BitPos % 8; |
| 319 if (mod == 0) { | 192 if (mod == 0) { |
| 320 return; | 193 return; |
| 321 } | 194 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 283 } |
| 411 | 284 |
| 412 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { | 285 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { |
| 413 return AppendBlock(lpsz.raw_str(), lpsz.GetLength()); | 286 return AppendBlock(lpsz.raw_str(), lpsz.GetLength()); |
| 414 } | 287 } |
| 415 | 288 |
| 416 void CFX_FileBufferArchive::AttachFile(IFX_StreamWrite* pFile) { | 289 void CFX_FileBufferArchive::AttachFile(IFX_StreamWrite* pFile) { |
| 417 ASSERT(pFile); | 290 ASSERT(pFile); |
| 418 m_pFile = pFile; | 291 m_pFile = pFile; |
| 419 } | 292 } |
| OLD | NEW |