| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 FX_SREAMTYPE_Unknown = 0, | 198 FX_SREAMTYPE_Unknown = 0, |
| 199 FX_STREAMTYPE_File, | 199 FX_STREAMTYPE_File, |
| 200 FX_STREAMTYPE_Buffer, | 200 FX_STREAMTYPE_Buffer, |
| 201 FX_STREAMTYPE_Stream, | 201 FX_STREAMTYPE_Stream, |
| 202 FX_STREAMTYPE_BufferRead, | 202 FX_STREAMTYPE_BufferRead, |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 class CFX_Stream : public IFX_Stream { | 205 class CFX_Stream : public IFX_Stream { |
| 206 public: | 206 public: |
| 207 CFX_Stream(); | 207 CFX_Stream(); |
| 208 ~CFX_Stream(); | 208 ~CFX_Stream() override; |
| 209 |
| 209 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 210 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
| 210 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 211 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
| 211 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); | 212 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); |
| 212 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); | 213 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); |
| 213 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 214 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, |
| 214 int32_t iFileSize, | 215 int32_t iFileSize, |
| 215 uint32_t dwAccess, | 216 uint32_t dwAccess, |
| 216 FX_BOOL bReleaseBufferRead); | 217 FX_BOOL bReleaseBufferRead); |
| 217 virtual void Release(); | 218 |
| 218 virtual IFX_Stream* Retain(); | 219 // IFX_Stream |
| 219 virtual uint32_t GetAccessModes() const { return m_dwAccess; } | 220 void Release() override; |
| 220 virtual int32_t GetLength() const; | 221 IFX_Stream* Retain() override; |
| 221 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 222 uint32_t GetAccessModes() const override; |
| 222 virtual int32_t GetPosition(); | 223 int32_t GetLength() const override; |
| 223 virtual FX_BOOL IsEOF() const; | 224 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 224 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 225 int32_t GetPosition() override; |
| 225 virtual int32_t ReadString(FX_WCHAR* pStr, | 226 FX_BOOL IsEOF() const override; |
| 226 int32_t iMaxLength, | 227 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
| 227 FX_BOOL& bEOS, | 228 int32_t ReadString(FX_WCHAR* pStr, |
| 228 int32_t const* pByteSize = NULL); | 229 int32_t iMaxLength, |
| 229 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 230 FX_BOOL& bEOS, |
| 230 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 231 int32_t const* pByteSize = NULL) override; |
| 231 virtual void Flush(); | 232 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
| 232 virtual FX_BOOL SetLength(int32_t iLength); | 233 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
| 233 virtual int32_t GetBOM(uint8_t bom[4]) const; | 234 void Flush() override; |
| 234 virtual uint16_t GetCodePage() const; | 235 FX_BOOL SetLength(int32_t iLength) override; |
| 235 virtual uint16_t SetCodePage(uint16_t wCodePage); | 236 int32_t GetBOM(uint8_t bom[4]) const override; |
| 236 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 237 uint16_t GetCodePage() const override; |
| 237 int32_t iOffset, | 238 uint16_t SetCodePage(uint16_t wCodePage) override; |
| 238 int32_t iLength); | 239 IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
| 240 int32_t iOffset, |
| 241 int32_t iLength) override; |
| 239 | 242 |
| 240 protected: | 243 protected: |
| 241 FX_STREAMTYPE m_eStreamType; | 244 FX_STREAMTYPE m_eStreamType; |
| 242 IFX_StreamImp* m_pStreamImp; | 245 IFX_StreamImp* m_pStreamImp; |
| 243 uint32_t m_dwAccess; | 246 uint32_t m_dwAccess; |
| 244 int32_t m_iTotalSize; | 247 int32_t m_iTotalSize; |
| 245 int32_t m_iPosition; | 248 int32_t m_iPosition; |
| 246 int32_t m_iStart; | 249 int32_t m_iStart; |
| 247 int32_t m_iLength; | 250 int32_t m_iLength; |
| 248 int32_t m_iRefCount; | 251 int32_t m_iRefCount; |
| 249 }; | 252 }; |
| 250 | 253 |
| 251 class CFX_TextStream : public IFX_Stream { | 254 class CFX_TextStream : public IFX_Stream { |
| 252 public: | 255 public: |
| 253 CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream); | 256 CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream); |
| 254 ~CFX_TextStream(); | 257 ~CFX_TextStream() override; |
| 255 virtual void Release(); | |
| 256 virtual IFX_Stream* Retain(); | |
| 257 | 258 |
| 258 virtual uint32_t GetAccessModes() const; | 259 // IFX_Stream |
| 259 virtual int32_t GetLength() const; | 260 void Release() override; |
| 260 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 261 IFX_Stream* Retain() override; |
| 261 virtual int32_t GetPosition(); | 262 uint32_t GetAccessModes() const override; |
| 262 virtual FX_BOOL IsEOF() const; | 263 int32_t GetLength() const override; |
| 263 | 264 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
| 264 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 265 int32_t GetPosition() override; |
| 265 virtual int32_t ReadString(FX_WCHAR* pStr, | 266 FX_BOOL IsEOF() const override; |
| 266 int32_t iMaxLength, | 267 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
| 267 FX_BOOL& bEOS, | 268 int32_t ReadString(FX_WCHAR* pStr, |
| 268 int32_t const* pByteSize = NULL); | 269 int32_t iMaxLength, |
| 269 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 270 FX_BOOL& bEOS, |
| 270 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 271 int32_t const* pByteSize = NULL) override; |
| 271 virtual void Flush(); | 272 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
| 272 virtual FX_BOOL SetLength(int32_t iLength); | 273 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
| 273 | 274 void Flush() override; |
| 274 virtual int32_t GetBOM(uint8_t bom[4]) const; | 275 FX_BOOL SetLength(int32_t iLength) override; |
| 275 virtual uint16_t GetCodePage() const; | 276 int32_t GetBOM(uint8_t bom[4]) const override; |
| 276 virtual uint16_t SetCodePage(uint16_t wCodePage); | 277 uint16_t GetCodePage() const override; |
| 277 | 278 uint16_t SetCodePage(uint16_t wCodePage) override; |
| 278 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 279 IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
| 279 int32_t iOffset, | 280 int32_t iOffset, |
| 280 int32_t iLength); | 281 int32_t iLength) override; |
| 281 | 282 |
| 282 protected: | 283 protected: |
| 283 uint16_t m_wCodePage; | 284 uint16_t m_wCodePage; |
| 284 int32_t m_wBOMLength; | 285 int32_t m_wBOMLength; |
| 285 uint32_t m_dwBOM; | 286 uint32_t m_dwBOM; |
| 286 uint8_t* m_pBuf; | 287 uint8_t* m_pBuf; |
| 287 int32_t m_iBufSize; | 288 int32_t m_iBufSize; |
| 288 FX_BOOL m_bDelStream; | 289 FX_BOOL m_bDelStream; |
| 289 IFX_Stream* m_pStreamImp; | 290 IFX_Stream* m_pStreamImp; |
| 290 int32_t m_iRefCount; | 291 int32_t m_iRefCount; |
| 291 void InitStream(); | 292 void InitStream(); |
| 292 }; | 293 }; |
| 293 | 294 |
| 294 class CFGAS_FileRead : public IFX_FileRead { | 295 class CFGAS_FileRead : public IFX_FileRead { |
| 295 public: | 296 public: |
| 296 CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream); | 297 CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream); |
| 297 virtual ~CFGAS_FileRead(); | 298 ~CFGAS_FileRead() override; |
| 298 virtual void Release() { delete this; } | 299 |
| 299 virtual FX_FILESIZE GetSize(); | 300 // IFX_FileRead |
| 300 virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size); | 301 void Release() override; |
| 302 FX_FILESIZE GetSize() override; |
| 303 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 301 | 304 |
| 302 protected: | 305 protected: |
| 303 FX_BOOL m_bReleaseStream; | 306 FX_BOOL m_bReleaseStream; |
| 304 IFX_Stream* m_pStream; | 307 IFX_Stream* m_pStream; |
| 305 }; | 308 }; |
| 306 | 309 |
| 307 int32_t FileLength(FXSYS_FILE* file) { | 310 int32_t FileLength(FXSYS_FILE* file) { |
| 308 ASSERT(file != NULL); | 311 ASSERT(file != NULL); |
| 309 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | 312 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ |
| 310 return _filelength(_fileno(file)); | 313 return _filelength(_fileno(file)); |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 | 1256 |
| 1254 void CFX_Stream::Release() { | 1257 void CFX_Stream::Release() { |
| 1255 if (--m_iRefCount < 1) { | 1258 if (--m_iRefCount < 1) { |
| 1256 delete this; | 1259 delete this; |
| 1257 } | 1260 } |
| 1258 } | 1261 } |
| 1259 IFX_Stream* CFX_Stream::Retain() { | 1262 IFX_Stream* CFX_Stream::Retain() { |
| 1260 m_iRefCount++; | 1263 m_iRefCount++; |
| 1261 return this; | 1264 return this; |
| 1262 } | 1265 } |
| 1266 |
| 1267 uint32_t CFX_Stream::GetAccessModes() const { |
| 1268 return m_dwAccess; |
| 1269 } |
| 1270 |
| 1263 int32_t CFX_Stream::GetLength() const { | 1271 int32_t CFX_Stream::GetLength() const { |
| 1264 if (m_pStreamImp == NULL) { | 1272 if (m_pStreamImp == NULL) { |
| 1265 return -1; | 1273 return -1; |
| 1266 } | 1274 } |
| 1267 if (m_eStreamType == FX_STREAMTYPE_File || | 1275 if (m_eStreamType == FX_STREAMTYPE_File || |
| 1268 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1276 m_eStreamType == FX_STREAMTYPE_Buffer) { |
| 1269 return m_pStreamImp->GetLength(); | 1277 return m_pStreamImp->GetLength(); |
| 1270 } | 1278 } |
| 1271 return m_iLength; | 1279 return m_iLength; |
| 1272 } | 1280 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 FX_FILESIZE CFGAS_FileRead::GetSize() { | 1511 FX_FILESIZE CFGAS_FileRead::GetSize() { |
| 1504 return (FX_FILESIZE)m_pStream->GetLength(); | 1512 return (FX_FILESIZE)m_pStream->GetLength(); |
| 1505 } | 1513 } |
| 1506 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, | 1514 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, |
| 1507 FX_FILESIZE offset, | 1515 FX_FILESIZE offset, |
| 1508 size_t size) { | 1516 size_t size) { |
| 1509 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1517 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
| 1510 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1518 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
| 1511 return iLen == (int32_t)size; | 1519 return iLen == (int32_t)size; |
| 1512 } | 1520 } |
| 1521 |
| 1522 void CFGAS_FileRead::Release() { |
| 1523 delete this; |
| 1524 } |
| OLD | NEW |