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