diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-04-23 20:04:39 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-23 20:04:39 +0000 |
commit | 4e4147eccd25e66a5c61712121c30c8d5f2ba56c (patch) | |
tree | 054553a3d2b26118288bbfa70fc49dfc4cd503fa /core/fxcrt/cfx_seekablestreamproxy.cpp | |
parent | a3dd6c390ebc2af63fc0b706a4747315acef02bf (diff) | |
download | pdfium-4e4147eccd25e66a5c61712121c30c8d5f2ba56c.tar.xz |
Make CFX_SeekableStreamProxy a subclass of IFX_SeekableReadStreamchromium/3405
This CL changes CFX_SeekableStreamProxy to be an IFX_SeekableReadStream
subclass.
This is a reland of https://pdfium-review.googlesource.com/c/pdfium/+/30879
after fix bad merge.
Change-Id: Iad58abe7e065541867f202059a944e9be4da5713
Reviewed-on: https://pdfium-review.googlesource.com/31195
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_seekablestreamproxy.cpp')
-rw-r--r-- | core/fxcrt/cfx_seekablestreamproxy.cpp | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/core/fxcrt/cfx_seekablestreamproxy.cpp b/core/fxcrt/cfx_seekablestreamproxy.cpp index d8fe4f4832..eb5874b7a2 100644 --- a/core/fxcrt/cfx_seekablestreamproxy.cpp +++ b/core/fxcrt/cfx_seekablestreamproxy.cpp @@ -134,7 +134,7 @@ void SwapByteOrder(wchar_t* pStr, size_t iLength) { #define BOM_UTF16_LE 0x0000FEFF CFX_SeekableStreamProxy::CFX_SeekableStreamProxy( - const RetainPtr<IFX_SeekableStream>& stream) + const RetainPtr<IFX_SeekableReadStream>& stream) : m_wCodePage(FX_CODEPAGE_DefANSI), m_wBOMLength(0), m_iPosition(0), @@ -169,6 +169,18 @@ CFX_SeekableStreamProxy::CFX_SeekableStreamProxy( CFX_SeekableStreamProxy::~CFX_SeekableStreamProxy() = default; +FX_FILESIZE CFX_SeekableStreamProxy::GetSize() { + return m_pStream->GetSize(); +} + +FX_FILESIZE CFX_SeekableStreamProxy::GetPosition() { + return m_iPosition; +} + +bool CFX_SeekableStreamProxy::IsEOF() { + return m_iPosition >= GetSize(); +} + void CFX_SeekableStreamProxy::Seek(From eSeek, FX_FILESIZE iOffset) { switch (eSeek) { case From::Begin: @@ -182,7 +194,7 @@ void CFX_SeekableStreamProxy::Seek(From eSeek, FX_FILESIZE iOffset) { } break; } m_iPosition = - pdfium::clamp(m_iPosition, static_cast<FX_FILESIZE>(0), GetLength()); + pdfium::clamp(m_iPosition, static_cast<FX_FILESIZE>(0), GetSize()); } void CFX_SeekableStreamProxy::SetCodePage(uint16_t wCodePage) { @@ -195,7 +207,7 @@ size_t CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, size_t iBufferSize) { ASSERT(pBuffer && iBufferSize > 0); iBufferSize = - std::min(iBufferSize, static_cast<size_t>(GetLength() - m_iPosition)); + std::min(iBufferSize, static_cast<size_t>(GetSize() - m_iPosition)); if (iBufferSize <= 0) return 0; @@ -208,27 +220,24 @@ size_t CFX_SeekableStreamProxy::ReadData(uint8_t* pBuffer, size_t iBufferSize) { return new_pos.IsValid() ? iBufferSize : 0; } -size_t CFX_SeekableStreamProxy::ReadString(wchar_t* pStr, - size_t iMaxLength, - bool* bEOS) { - if (!pStr || iMaxLength == 0) +size_t CFX_SeekableStreamProxy::ReadBlock(void* pStr, size_t size) { + if (!pStr || size == 0) return 0; if (m_wCodePage == FX_CODEPAGE_UTF16LE || m_wCodePage == FX_CODEPAGE_UTF16BE) { - size_t iBytes = iMaxLength * 2; + size_t iBytes = size * 2; size_t iLen = ReadData(reinterpret_cast<uint8_t*>(pStr), iBytes); - iMaxLength = iLen / 2; - if (sizeof(wchar_t) > 2 && iMaxLength > 0) - UTF16ToWChar(pStr, iMaxLength); + size = iLen / 2; + if (sizeof(wchar_t) > 2 && size > 0) + UTF16ToWChar(pStr, size); if (m_wCodePage == FX_CODEPAGE_UTF16BE) - SwapByteOrder(pStr, iMaxLength); + SwapByteOrder(static_cast<wchar_t*>(pStr), size); } else { FX_FILESIZE pos = GetPosition(); - size_t iBytes = - std::min(iMaxLength, static_cast<size_t>(GetLength() - pos)); + size_t iBytes = std::min(size, static_cast<size_t>(GetSize() - pos)); if (iBytes > 0) { std::vector<uint8_t> buf(iBytes); @@ -238,14 +247,21 @@ size_t CFX_SeekableStreamProxy::ReadString(wchar_t* pStr, return 0; size_t iSrc = 0; - std::tie(iSrc, iMaxLength) = UTF8Decode( - reinterpret_cast<const char*>(buf.data()), iLen, pStr, iMaxLength); + std::tie(iSrc, size) = + UTF8Decode(reinterpret_cast<const char*>(buf.data()), iLen, + static_cast<wchar_t*>(pStr), size); Seek(From::Current, iSrc - iLen); } else { - iMaxLength = 0; + size = 0; } } - *bEOS = IsEOF(); - return iMaxLength; + return size; +} + +bool CFX_SeekableStreamProxy::ReadBlock(void* pStr, + FX_FILESIZE offset, + size_t size) { + NOTREACHED(); + return false; } |