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 "core/include/fxcrt/fx_basic.h" | 7 #include "core/include/fxcrt/fx_basic.h" |
8 | 8 |
9 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 9 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
10 CFX_BinaryBuf::CFX_BinaryBuf() | 10 CFX_BinaryBuf::CFX_BinaryBuf() |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 AppendBlock(buf.m_pBuffer, buf.m_DataSize); | 200 AppendBlock(buf.m_pBuffer, buf.m_DataSize); |
201 return *this; | 201 return *this; |
202 } | 202 } |
203 void CFX_WideTextBuf::operator=(const CFX_WideStringC& str) { | 203 void CFX_WideTextBuf::operator=(const CFX_WideStringC& str) { |
204 CopyData(str.GetPtr(), str.GetLength() * sizeof(FX_WCHAR)); | 204 CopyData(str.GetPtr(), str.GetLength() * sizeof(FX_WCHAR)); |
205 } | 205 } |
206 CFX_WideStringC CFX_WideTextBuf::GetWideString() const { | 206 CFX_WideStringC CFX_WideTextBuf::GetWideString() const { |
207 return CFX_WideStringC((const FX_WCHAR*)m_pBuffer, | 207 return CFX_WideStringC((const FX_WCHAR*)m_pBuffer, |
208 m_DataSize / sizeof(FX_WCHAR)); | 208 m_DataSize / sizeof(FX_WCHAR)); |
209 } | 209 } |
| 210 #ifdef PDF_ENABLE_XFA |
| 211 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(uint8_t i) { |
| 212 if (m_pStream) { |
| 213 m_pStream->WriteBlock(&i, 1); |
| 214 } else { |
| 215 m_SavingBuf.AppendByte(i); |
| 216 } |
| 217 return *this; |
| 218 } |
| 219 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(int i) { |
| 220 if (m_pStream) { |
| 221 m_pStream->WriteBlock(&i, sizeof(int)); |
| 222 } else { |
| 223 m_SavingBuf.AppendBlock(&i, sizeof(int)); |
| 224 } |
| 225 return *this; |
| 226 } |
| 227 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_DWORD i) { |
| 228 if (m_pStream) { |
| 229 m_pStream->WriteBlock(&i, sizeof(FX_DWORD)); |
| 230 } else { |
| 231 m_SavingBuf.AppendBlock(&i, sizeof(FX_DWORD)); |
| 232 } |
| 233 return *this; |
| 234 } |
| 235 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(FX_FLOAT f) { |
| 236 if (m_pStream) { |
| 237 m_pStream->WriteBlock(&f, sizeof(FX_FLOAT)); |
| 238 } else { |
| 239 m_SavingBuf.AppendBlock(&f, sizeof(FX_FLOAT)); |
| 240 } |
| 241 return *this; |
| 242 } |
| 243 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const CFX_ByteStringC& bstr) { |
| 244 int len = bstr.GetLength(); |
| 245 if (m_pStream) { |
| 246 m_pStream->WriteBlock(&len, sizeof(int)); |
| 247 m_pStream->WriteBlock(bstr.GetPtr(), len); |
| 248 } else { |
| 249 m_SavingBuf.AppendBlock(&len, sizeof(int)); |
| 250 m_SavingBuf.AppendBlock(bstr.GetPtr(), len); |
| 251 } |
| 252 return *this; |
| 253 } |
| 254 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const FX_WCHAR* wstr) { |
| 255 FX_STRSIZE len = FXSYS_wcslen(wstr); |
| 256 if (m_pStream) { |
| 257 m_pStream->WriteBlock(&len, sizeof(int)); |
| 258 m_pStream->WriteBlock(wstr, len); |
| 259 } else { |
| 260 m_SavingBuf.AppendBlock(&len, sizeof(int)); |
| 261 m_SavingBuf.AppendBlock(wstr, len); |
| 262 } |
| 263 return *this; |
| 264 } |
| 265 CFX_ArchiveSaver& CFX_ArchiveSaver::operator<<(const CFX_WideString& wstr) { |
| 266 CFX_ByteString encoded = wstr.UTF16LE_Encode(); |
| 267 return operator<<(encoded); |
| 268 } |
| 269 void CFX_ArchiveSaver::Write(const void* pData, FX_STRSIZE dwSize) { |
| 270 if (m_pStream) { |
| 271 m_pStream->WriteBlock(pData, dwSize); |
| 272 } else { |
| 273 m_SavingBuf.AppendBlock(pData, dwSize); |
| 274 } |
| 275 } |
| 276 CFX_ArchiveLoader::CFX_ArchiveLoader(const uint8_t* pData, FX_DWORD dwSize) { |
| 277 m_pLoadingBuf = pData; |
| 278 m_LoadingPos = 0; |
| 279 m_LoadingSize = dwSize; |
| 280 } |
| 281 FX_BOOL CFX_ArchiveLoader::IsEOF() { |
| 282 return m_LoadingPos >= m_LoadingSize; |
| 283 } |
| 284 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(uint8_t& i) { |
| 285 if (m_LoadingPos >= m_LoadingSize) { |
| 286 return *this; |
| 287 } |
| 288 i = m_pLoadingBuf[m_LoadingPos++]; |
| 289 return *this; |
| 290 } |
| 291 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(int& i) { |
| 292 Read(&i, sizeof(int)); |
| 293 return *this; |
| 294 } |
| 295 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_DWORD& i) { |
| 296 Read(&i, sizeof(FX_DWORD)); |
| 297 return *this; |
| 298 } |
| 299 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(FX_FLOAT& i) { |
| 300 Read(&i, sizeof(FX_FLOAT)); |
| 301 return *this; |
| 302 } |
| 303 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_ByteString& str) { |
| 304 if (m_LoadingPos + 4 > m_LoadingSize) { |
| 305 return *this; |
| 306 } |
| 307 int len; |
| 308 operator>>(len); |
| 309 str.Empty(); |
| 310 if (len <= 0 || m_LoadingPos + len > m_LoadingSize) { |
| 311 return *this; |
| 312 } |
| 313 FX_CHAR* buffer = str.GetBuffer(len); |
| 314 FXSYS_memcpy(buffer, m_pLoadingBuf + m_LoadingPos, len); |
| 315 str.ReleaseBuffer(len); |
| 316 m_LoadingPos += len; |
| 317 return *this; |
| 318 } |
| 319 CFX_ArchiveLoader& CFX_ArchiveLoader::operator>>(CFX_WideString& str) { |
| 320 CFX_ByteString encoded; |
| 321 operator>>(encoded); |
| 322 str = CFX_WideString::FromUTF16LE((const unsigned short*)encoded.c_str(), |
| 323 encoded.GetLength()); |
| 324 return *this; |
| 325 } |
| 326 FX_BOOL CFX_ArchiveLoader::Read(void* pBuf, FX_DWORD dwSize) { |
| 327 if (m_LoadingPos + dwSize > m_LoadingSize) { |
| 328 return FALSE; |
| 329 } |
| 330 FXSYS_memcpy(pBuf, m_pLoadingBuf + m_LoadingPos, dwSize); |
| 331 m_LoadingPos += dwSize; |
| 332 return TRUE; |
| 333 } |
| 334 #endif |
210 void CFX_BitStream::Init(const uint8_t* pData, FX_DWORD dwSize) { | 335 void CFX_BitStream::Init(const uint8_t* pData, FX_DWORD dwSize) { |
211 m_pData = pData; | 336 m_pData = pData; |
212 m_BitSize = dwSize * 8; | 337 m_BitSize = dwSize * 8; |
213 m_BitPos = 0; | 338 m_BitPos = 0; |
214 } | 339 } |
215 void CFX_BitStream::ByteAlign() { | 340 void CFX_BitStream::ByteAlign() { |
216 int mod = m_BitPos % 8; | 341 int mod = m_BitPos % 8; |
217 if (mod == 0) { | 342 if (mod == 0) { |
218 return; | 343 return; |
219 } | 344 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 449 } |
325 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { | 450 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { |
326 if (!m_pFile) { | 451 if (!m_pFile) { |
327 return FALSE; | 452 return FALSE; |
328 } | 453 } |
329 if (!pBuf || size < 1) { | 454 if (!pBuf || size < 1) { |
330 return TRUE; | 455 return TRUE; |
331 } | 456 } |
332 return m_pFile->WriteBlock(pBuf, size); | 457 return m_pFile->WriteBlock(pBuf, size); |
333 } | 458 } |
OLD | NEW |