Chromium Code Reviews| 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/fxcrt/extension.h" | 7 #include "core/fxcrt/extension.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { | 67 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { |
| 68 m_path = wsPath; | 68 m_path = wsPath; |
| 69 m_RefCount = 1; | 69 m_RefCount = 1; |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 #endif // PDF_ENABLE_XFA | 73 #endif // PDF_ENABLE_XFA |
| 74 | 74 |
| 75 class CFX_CRTFileStream final : public IFX_SeekableStream { | 75 class CFX_CRTFileStream final : public IFX_SeekableStream { |
| 76 public: | 76 public: |
| 77 explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA); | |
| 78 ~CFX_CRTFileStream() override; | |
| 79 | |
| 80 // IFX_SeekableStream: | 77 // IFX_SeekableStream: |
| 81 FX_FILESIZE GetSize() override; | 78 FX_FILESIZE GetSize() override; |
| 82 bool IsEOF() override; | 79 bool IsEOF() override; |
| 83 FX_FILESIZE GetPosition() override; | 80 FX_FILESIZE GetPosition() override; |
| 84 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 81 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 85 size_t ReadBlock(void* buffer, size_t size) override; | 82 size_t ReadBlock(void* buffer, size_t size) override; |
| 86 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; | 83 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; |
| 87 bool Flush() override; | 84 bool Flush() override; |
| 88 | 85 |
| 89 private: | 86 private: |
| 87 template <typename T, typename... Args> | |
| 88 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); | |
| 89 | |
| 90 explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA); | |
| 91 ~CFX_CRTFileStream() override; | |
| 92 | |
| 90 std::unique_ptr<IFXCRT_FileAccess> m_pFile; | 93 std::unique_ptr<IFXCRT_FileAccess> m_pFile; |
| 91 }; | 94 }; |
| 92 | 95 |
| 93 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) | 96 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) |
| 94 : m_pFile(std::move(pFA)) {} | 97 : m_pFile(std::move(pFA)) {} |
| 95 | 98 |
| 96 CFX_CRTFileStream::~CFX_CRTFileStream() {} | 99 CFX_CRTFileStream::~CFX_CRTFileStream() {} |
| 97 | 100 |
| 98 FX_FILESIZE CFX_CRTFileStream::GetSize() { | 101 FX_FILESIZE CFX_CRTFileStream::GetSize() { |
| 99 return m_pFile->GetSize(); | 102 return m_pFile->GetSize(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 126 bool CFX_CRTFileStream::Flush() { | 129 bool CFX_CRTFileStream::Flush() { |
| 127 return m_pFile->Flush(); | 130 return m_pFile->Flush(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 #define FX_MEMSTREAM_BlockSize (64 * 1024) | 133 #define FX_MEMSTREAM_BlockSize (64 * 1024) |
| 131 #define FX_MEMSTREAM_Consecutive 0x01 | 134 #define FX_MEMSTREAM_Consecutive 0x01 |
| 132 #define FX_MEMSTREAM_TakeOver 0x02 | 135 #define FX_MEMSTREAM_TakeOver 0x02 |
| 133 | 136 |
| 134 class CFX_MemoryStream final : public IFX_MemoryStream { | 137 class CFX_MemoryStream final : public IFX_MemoryStream { |
| 135 public: | 138 public: |
| 136 explicit CFX_MemoryStream(bool bConsecutive); | |
| 137 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver); | |
| 138 ~CFX_MemoryStream() override; | |
| 139 | |
| 140 // IFX_MemoryStream | 139 // IFX_MemoryStream |
| 141 FX_FILESIZE GetSize() override; | 140 FX_FILESIZE GetSize() override; |
| 142 bool IsEOF() override; | 141 bool IsEOF() override; |
| 143 FX_FILESIZE GetPosition() override; | 142 FX_FILESIZE GetPosition() override; |
| 144 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 143 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 145 size_t ReadBlock(void* buffer, size_t size) override; | 144 size_t ReadBlock(void* buffer, size_t size) override; |
| 146 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; | 145 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; |
| 147 bool Flush() override; | 146 bool Flush() override; |
| 148 bool IsConsecutive() const override; | 147 bool IsConsecutive() const override; |
| 149 void EstimateSize(size_t nInitSize, size_t nGrowSize) override; | 148 void EstimateSize(size_t nInitSize, size_t nGrowSize) override; |
| 150 uint8_t* GetBuffer() const override; | 149 uint8_t* GetBuffer() const override; |
| 151 void AttachBuffer(uint8_t* pBuffer, | 150 void AttachBuffer(uint8_t* pBuffer, |
| 152 size_t nSize, | 151 size_t nSize, |
| 153 bool bTakeOver = false) override; | 152 bool bTakeOver = false) override; |
| 154 void DetachBuffer() override; | 153 void DetachBuffer() override; |
| 155 | 154 |
| 156 private: | 155 private: |
| 156 template <typename T, typename... Args> | |
| 157 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); | |
|
dsinclair
2016/12/07 21:12:57
I didn't know you could do that..... cool.
| |
| 158 | |
| 159 explicit CFX_MemoryStream(bool bConsecutive); | |
| 160 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver); | |
| 161 ~CFX_MemoryStream() override; | |
| 162 | |
| 157 bool ExpandBlocks(size_t size); | 163 bool ExpandBlocks(size_t size); |
| 158 | 164 |
| 159 CFX_ArrayTemplate<uint8_t*> m_Blocks; | 165 CFX_ArrayTemplate<uint8_t*> m_Blocks; |
| 160 size_t m_nTotalSize; | 166 size_t m_nTotalSize; |
| 161 size_t m_nCurSize; | 167 size_t m_nCurSize; |
| 162 size_t m_nCurPos; | 168 size_t m_nCurPos; |
| 163 size_t m_nGrowSize; | 169 size_t m_nGrowSize; |
| 164 uint32_t m_dwFlags; | 170 uint32_t m_dwFlags; |
| 165 }; | 171 }; |
| 166 | 172 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 } | 395 } |
| 390 #endif // PDF_ENABLE_XFA | 396 #endif // PDF_ENABLE_XFA |
| 391 | 397 |
| 392 // static | 398 // static |
| 393 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( | 399 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( |
| 394 const FX_CHAR* filename, | 400 const FX_CHAR* filename, |
| 395 uint32_t dwModes) { | 401 uint32_t dwModes) { |
| 396 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); | 402 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); |
| 397 if (!pFA->Open(filename, dwModes)) | 403 if (!pFA->Open(filename, dwModes)) |
| 398 return nullptr; | 404 return nullptr; |
| 399 return CFX_RetainPtr<IFX_SeekableStream>( | 405 return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA)); |
| 400 new CFX_CRTFileStream(std::move(pFA))); | |
| 401 } | 406 } |
| 402 | 407 |
| 403 // static | 408 // static |
| 404 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( | 409 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( |
| 405 const FX_WCHAR* filename, | 410 const FX_WCHAR* filename, |
| 406 uint32_t dwModes) { | 411 uint32_t dwModes) { |
| 407 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); | 412 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); |
| 408 if (!pFA->Open(filename, dwModes)) | 413 if (!pFA->Open(filename, dwModes)) |
| 409 return nullptr; | 414 return nullptr; |
| 410 return CFX_RetainPtr<IFX_SeekableStream>( | 415 return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA)); |
| 411 new CFX_CRTFileStream(std::move(pFA))); | |
| 412 } | 416 } |
| 413 | 417 |
| 414 // static | 418 // static |
| 415 CFX_RetainPtr<IFX_SeekableReadStream> | 419 CFX_RetainPtr<IFX_SeekableReadStream> |
| 416 IFX_SeekableReadStream::CreateFromFilename(const FX_CHAR* filename) { | 420 IFX_SeekableReadStream::CreateFromFilename(const FX_CHAR* filename) { |
| 417 return IFX_SeekableStream::CreateFromFilename(filename, FX_FILEMODE_ReadOnly); | 421 return IFX_SeekableStream::CreateFromFilename(filename, FX_FILEMODE_ReadOnly); |
| 418 } | 422 } |
| 419 | 423 |
| 420 // static | 424 // static |
| 421 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(uint8_t* pBuffer, | 425 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(uint8_t* pBuffer, |
| 422 size_t dwSize, | 426 size_t dwSize, |
| 423 bool bTakeOver) { | 427 bool bTakeOver) { |
| 424 return CFX_RetainPtr<IFX_MemoryStream>( | 428 return pdfium::MakeRetain<CFX_MemoryStream>(pBuffer, dwSize, bTakeOver); |
| 425 new CFX_MemoryStream(pBuffer, dwSize, bTakeOver)); | |
| 426 } | 429 } |
| 427 | 430 |
| 428 // static | 431 // static |
| 429 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(bool bConsecutive) { | 432 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(bool bConsecutive) { |
| 430 return CFX_RetainPtr<IFX_MemoryStream>(new CFX_MemoryStream(bConsecutive)); | 433 return pdfium::MakeRetain<CFX_MemoryStream>(bConsecutive); |
| 431 } | 434 } |
| 432 | 435 |
| 433 FX_FLOAT FXSYS_tan(FX_FLOAT a) { | 436 FX_FLOAT FXSYS_tan(FX_FLOAT a) { |
| 434 return (FX_FLOAT)tan(a); | 437 return (FX_FLOAT)tan(a); |
| 435 } | 438 } |
| 436 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) { | 439 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) { |
| 437 return FXSYS_log(x) / FXSYS_log(b); | 440 return FXSYS_log(x) / FXSYS_log(b); |
| 438 } | 441 } |
| 439 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, | 442 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, |
| 440 int32_t iLength, | 443 int32_t iLength, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 b = ((const uint8_t*)pGUID)[i]; | 677 b = ((const uint8_t*)pGUID)[i]; |
| 675 *pBuf++ = gs_FX_pHexChars[b >> 4]; | 678 *pBuf++ = gs_FX_pHexChars[b >> 4]; |
| 676 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; | 679 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; |
| 677 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { | 680 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { |
| 678 *pBuf++ = L'-'; | 681 *pBuf++ = L'-'; |
| 679 } | 682 } |
| 680 } | 683 } |
| 681 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); | 684 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); |
| 682 } | 685 } |
| 683 #endif // PDF_ENABLE_XFA | 686 #endif // PDF_ENABLE_XFA |
| OLD | NEW |