1 // Copyright 2017 The PDFium Authors 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 <stddef.h> 11 #include <stdint.h> 12 13 #include "core/fxcrt/fx_codepage.h" 14 #include "core/fxcrt/fx_stream.h" 15 #include "core/fxcrt/fx_types.h" 16 #include "core/fxcrt/retain_ptr.h" 17 #include "core/fxcrt/span.h" 18 19 class CFX_SeekableStreamProxy final : public Retainable { 20 public: 21 CONSTRUCT_VIA_MAKE_RETAIN; 22 23 FX_FILESIZE GetSize() const; // Estimate under worst possible expansion. 24 bool IsEOF() const; 25 26 // Returns number of wchar_t elements placed into `buffer`. 27 size_t ReadBlock(pdfium::span<wchar_t> buffer); 28 GetCodePage()29 FX_CodePage GetCodePage() const { return m_wCodePage; } 30 void SetCodePage(FX_CodePage wCodePage); 31 32 private: 33 enum class From { 34 Begin = 0, 35 Current, 36 }; 37 38 explicit CFX_SeekableStreamProxy( 39 const RetainPtr<IFX_SeekableReadStream>& stream); 40 ~CFX_SeekableStreamProxy() override; 41 42 FX_FILESIZE GetPosition() const; 43 void Seek(From eSeek, FX_FILESIZE iOffset); 44 size_t ReadData(pdfium::span<uint8_t> buffer); 45 46 FX_CodePage m_wCodePage = FX_CodePage::kDefANSI; 47 size_t m_wBOMLength = 0; 48 FX_FILESIZE m_iPosition = 0; 49 RetainPtr<IFX_SeekableReadStream> const m_pStream; 50 }; 51 52 #endif // CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_ 53