| 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 "xfa/fgas/crt/fgas_stream.h" | 7 #include "xfa/fgas/crt/fgas_stream.h" |
| 8 | 8 |
| 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
| 10 _FX_OS_ == _FX_WIN64_ | 10 _FX_OS_ == _FX_WIN64_ |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 enum FX_STREAMTYPE { | 187 enum FX_STREAMTYPE { |
| 188 FX_SREAMTYPE_Unknown = 0, | 188 FX_SREAMTYPE_Unknown = 0, |
| 189 FX_STREAMTYPE_File, | 189 FX_STREAMTYPE_File, |
| 190 FX_STREAMTYPE_Buffer, | 190 FX_STREAMTYPE_Buffer, |
| 191 FX_STREAMTYPE_Stream, | 191 FX_STREAMTYPE_Stream, |
| 192 FX_STREAMTYPE_BufferRead, | 192 FX_STREAMTYPE_BufferRead, |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 class CFGAS_Stream : public IFGAS_Stream { | 195 class CFGAS_Stream : public IFGAS_Stream { |
| 196 public: | 196 public: |
| 197 CFGAS_Stream(); | 197 template <typename T, typename... Args> |
| 198 ~CFGAS_Stream() override; | 198 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); |
| 199 | 199 |
| 200 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 200 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
| 201 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 201 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
| 202 bool LoadFileRead(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, | 202 bool LoadFileRead(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, |
| 203 uint32_t dwAccess); | 203 uint32_t dwAccess); |
| 204 bool LoadFileWrite(const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, | 204 bool LoadFileWrite(const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, |
| 205 uint32_t dwAccess); | 205 uint32_t dwAccess); |
| 206 bool LoadBufferRead(const CFX_RetainPtr<IFX_BufferedReadStream>& pBufferRead, | 206 bool LoadBufferRead(const CFX_RetainPtr<IFX_BufferedReadStream>& pBufferRead, |
| 207 int32_t iFileSize, | 207 int32_t iFileSize, |
| 208 uint32_t dwAccess); | 208 uint32_t dwAccess); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 220 void Flush() override; | 220 void Flush() override; |
| 221 bool SetLength(int32_t iLength) override; | 221 bool SetLength(int32_t iLength) override; |
| 222 int32_t GetBOM(uint8_t bom[4]) const override; | 222 int32_t GetBOM(uint8_t bom[4]) const override; |
| 223 uint16_t GetCodePage() const override; | 223 uint16_t GetCodePage() const override; |
| 224 uint16_t SetCodePage(uint16_t wCodePage) override; | 224 uint16_t SetCodePage(uint16_t wCodePage) override; |
| 225 CFX_RetainPtr<IFGAS_Stream> CreateSharedStream(uint32_t dwAccess, | 225 CFX_RetainPtr<IFGAS_Stream> CreateSharedStream(uint32_t dwAccess, |
| 226 int32_t iOffset, | 226 int32_t iOffset, |
| 227 int32_t iLength) override; | 227 int32_t iLength) override; |
| 228 | 228 |
| 229 protected: | 229 protected: |
| 230 CFGAS_Stream(); |
| 231 ~CFGAS_Stream() override; |
| 232 |
| 230 FX_STREAMTYPE m_eStreamType; | 233 FX_STREAMTYPE m_eStreamType; |
| 231 IFGAS_StreamImp* m_pStreamImp; | 234 IFGAS_StreamImp* m_pStreamImp; |
| 232 uint32_t m_dwAccess; | 235 uint32_t m_dwAccess; |
| 233 int32_t m_iTotalSize; | 236 int32_t m_iTotalSize; |
| 234 int32_t m_iPosition; | 237 int32_t m_iPosition; |
| 235 int32_t m_iStart; | 238 int32_t m_iStart; |
| 236 int32_t m_iLength; | 239 int32_t m_iLength; |
| 237 int32_t m_iRefCount; | 240 int32_t m_iRefCount; |
| 238 }; | 241 }; |
| 239 | 242 |
| 240 class CFGAS_TextStream : public IFGAS_Stream { | 243 class CFGAS_TextStream : public IFGAS_Stream { |
| 241 public: | 244 public: |
| 242 explicit CFGAS_TextStream(const CFX_RetainPtr<IFGAS_Stream>& pStream); | 245 template <typename T, typename... Args> |
| 243 ~CFGAS_TextStream() override; | 246 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); |
| 244 | 247 |
| 245 // IFGAS_Stream | 248 // IFGAS_Stream |
| 246 uint32_t GetAccessModes() const override; | 249 uint32_t GetAccessModes() const override; |
| 247 int32_t GetLength() const override; | 250 int32_t GetLength() const override; |
| 248 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 251 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 249 int32_t GetPosition() override; | 252 int32_t GetPosition() override; |
| 250 bool IsEOF() const override; | 253 bool IsEOF() const override; |
| 251 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 254 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
| 252 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; | 255 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
| 253 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 256 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
| 254 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 257 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
| 255 void Flush() override; | 258 void Flush() override; |
| 256 bool SetLength(int32_t iLength) override; | 259 bool SetLength(int32_t iLength) override; |
| 257 int32_t GetBOM(uint8_t bom[4]) const override; | 260 int32_t GetBOM(uint8_t bom[4]) const override; |
| 258 uint16_t GetCodePage() const override; | 261 uint16_t GetCodePage() const override; |
| 259 uint16_t SetCodePage(uint16_t wCodePage) override; | 262 uint16_t SetCodePage(uint16_t wCodePage) override; |
| 260 CFX_RetainPtr<IFGAS_Stream> CreateSharedStream(uint32_t dwAccess, | 263 CFX_RetainPtr<IFGAS_Stream> CreateSharedStream(uint32_t dwAccess, |
| 261 int32_t iOffset, | 264 int32_t iOffset, |
| 262 int32_t iLength) override; | 265 int32_t iLength) override; |
| 263 | 266 |
| 264 protected: | 267 protected: |
| 268 explicit CFGAS_TextStream(const CFX_RetainPtr<IFGAS_Stream>& pStream); |
| 269 ~CFGAS_TextStream() override; |
| 270 |
| 265 void InitStream(); | 271 void InitStream(); |
| 266 | 272 |
| 267 uint16_t m_wCodePage; | 273 uint16_t m_wCodePage; |
| 268 int32_t m_wBOMLength; | 274 int32_t m_wBOMLength; |
| 269 uint32_t m_dwBOM; | 275 uint32_t m_dwBOM; |
| 270 uint8_t* m_pBuf; | 276 uint8_t* m_pBuf; |
| 271 int32_t m_iBufSize; | 277 int32_t m_iBufSize; |
| 272 CFX_RetainPtr<IFGAS_Stream> m_pStreamImp; | 278 CFX_RetainPtr<IFGAS_Stream> m_pStreamImp; |
| 273 }; | 279 }; |
| 274 | 280 |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 | 1474 |
| 1469 FX_FILESIZE CFGAS_FileRead::GetSize() { | 1475 FX_FILESIZE CFGAS_FileRead::GetSize() { |
| 1470 return (FX_FILESIZE)m_pStream->GetLength(); | 1476 return (FX_FILESIZE)m_pStream->GetLength(); |
| 1471 } | 1477 } |
| 1472 | 1478 |
| 1473 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { | 1479 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { |
| 1474 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1480 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
| 1475 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1481 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
| 1476 return iLen == (int32_t)size; | 1482 return iLen == (int32_t)size; |
| 1477 } | 1483 } |
| OLD | NEW |