1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_ 8 #define CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_ 9 10 #include "core/fxcrt/fx_stream.h" 11 #include "core/fxcrt/fx_system.h" 12 #include "core/fxcrt/retain_ptr.h" 13 14 class CFX_SeekableStreamProxy final : public Retainable { 15 public: 16 template <typename T, typename... Args> 17 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 18 19 // Unlike IFX_SeekableStreamProxy, buffers and sizes are always in terms 20 // of the number of wchar_t elementss, not bytes. 21 FX_FILESIZE GetSize(); // Estimate under worst possible expansion. 22 bool IsEOF(); 23 size_t ReadBlock(wchar_t* pStr, size_t size); 24 GetCodePage()25 uint16_t GetCodePage() const { return m_wCodePage; } 26 void SetCodePage(uint16_t wCodePage); 27 28 private: 29 enum class From { 30 Begin = 0, 31 Current, 32 }; 33 34 explicit CFX_SeekableStreamProxy( 35 const RetainPtr<IFX_SeekableReadStream>& stream); 36 ~CFX_SeekableStreamProxy() override; 37 38 FX_FILESIZE GetPosition(); 39 void Seek(From eSeek, FX_FILESIZE iOffset); 40 size_t ReadData(uint8_t* pBuffer, size_t iBufferSize); 41 42 uint16_t m_wCodePage; 43 size_t m_wBOMLength; 44 FX_FILESIZE m_iPosition; 45 RetainPtr<IFX_SeekableReadStream> m_pStream; 46 }; 47 48 #endif // CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_ 49