From 4fcdf058734b5df696420aa653ea787842678224 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 18 Apr 2017 11:55:27 -0400 Subject: Subclass the stream implementations from CFGAS_Stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename CFGAS_TextStream to CFGAS_Stream. CFGAS_Stream is converted to a base class instead of accepting an IFGAS_StreamImp. Things which inherted from IFGAS_StreamImp now inherit from CFGAS_Stream. The stream type inputs are changed to IFX_SeekableStream so that they can accept the same type (IFX_SeekableStream is an IFX_SeekableWriteStream and an IFX_SeekableReadStream). This way the storage can be shared in the base class. Change-Id: I06645071e68e2a4d4120c0e336529f2c18c2b705 Reviewed-on: https://pdfium-review.googlesource.com/4152 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- xfa/fgas/crt/ifgas_stream.cpp | 367 +++++++++++-------------------- xfa/fgas/crt/ifgas_stream.h | 4 +- xfa/fxfa/cxfa_ffdoc.cpp | 19 +- xfa/fxfa/cxfa_ffdoc.h | 8 +- xfa/fxfa/cxfa_fileread.cpp | 25 +++ xfa/fxfa/cxfa_fileread.h | 7 +- xfa/fxfa/parser/cxfa_dataexporter.cpp | 11 +- xfa/fxfa/parser/cxfa_dataexporter.h | 6 +- xfa/fxfa/parser/cxfa_dataimporter.cpp | 2 +- xfa/fxfa/parser/cxfa_dataimporter.h | 4 +- xfa/fxfa/parser/cxfa_document_parser.cpp | 2 +- xfa/fxfa/parser/cxfa_document_parser.h | 4 +- xfa/fxfa/parser/cxfa_simple_parser.cpp | 2 +- xfa/fxfa/parser/cxfa_simple_parser.h | 6 +- 14 files changed, 194 insertions(+), 273 deletions(-) (limited to 'xfa') diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp index 41913b28b6..3f5069e4bb 100644 --- a/xfa/fgas/crt/ifgas_stream.cpp +++ b/xfa/fgas/crt/ifgas_stream.cpp @@ -23,91 +23,64 @@ namespace { -class IFGAS_StreamImp { +class CFGAS_Stream : public IFGAS_Stream { public: - virtual ~IFGAS_StreamImp() {} - - virtual FX_FILESIZE GetLength() const = 0; - virtual FX_FILESIZE GetPosition() = 0; - - virtual void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) = 0; - virtual bool IsEOF() const = 0; - - virtual FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) = 0; - virtual void WriteData(const CFX_WideStringC& str) = 0; + // IFGAS_Stream + FX_FILESIZE GetLength() const override { return m_pStream->GetSize(); } + FX_FILESIZE GetPosition() override { return m_iPosition; } + FX_STRSIZE GetBOMLength() const override { return std::max(0, m_wBOMLength); } + FX_STRSIZE ReadString(wchar_t* pStr, + FX_STRSIZE iMaxLength, + bool* bEOS) override; + void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; + bool IsEOF() const override { return m_iPosition >= GetLength(); } + void WriteString(const CFX_WideStringC& str) override; + uint16_t GetCodePage() const override { return m_wCodePage; } + void SetCodePage(uint16_t wCodePage) override; protected: - IFGAS_StreamImp(); -}; - -class CFGAS_FileReadStreamImp : public IFGAS_StreamImp { - public: - explicit CFGAS_FileReadStreamImp( - const CFX_RetainPtr& pFileRead); - ~CFGAS_FileReadStreamImp() override {} + CFGAS_Stream(const CFX_RetainPtr& stream, + bool isWriteSteam); + ~CFGAS_Stream() override; - // IFGAS_StreamImp: - FX_FILESIZE GetLength() const override; - FX_FILESIZE GetPosition() override { return m_iPosition; } - void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; - bool IsEOF() const override; - FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override; - void WriteData(const CFX_WideStringC& str) override {} + virtual FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) { + return 0; + } + virtual void WriteData(const CFX_WideStringC& str) {} - private: - CFX_RetainPtr m_pFileRead; + uint16_t m_wCodePage; + FX_STRSIZE m_wBOMLength; + bool m_IsWriteStream; FX_FILESIZE m_iPosition; + CFX_RetainPtr m_pStream; }; -class CFGAS_FileWriteStreamImp : public IFGAS_StreamImp { +class CFGAS_FileReadStreamImp : public CFGAS_Stream { public: - CFGAS_FileWriteStreamImp( - const CFX_RetainPtr& pFileWrite); - ~CFGAS_FileWriteStreamImp() override {} + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); - // IFGAS_StreamImp: - FX_FILESIZE GetLength() const override; - FX_FILESIZE GetPosition() override { return m_iPosition; } - void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; - bool IsEOF() const override; - FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override { - return 0; - } - void WriteData(const CFX_WideStringC& str) override; + // CFGAS_Stream: + FX_STRSIZE ReadData(uint8_t* pBuffer, FX_STRSIZE iBufferSize) override; private: - CFX_RetainPtr m_pFileWrite; - FX_FILESIZE m_iPosition; + explicit CFGAS_FileReadStreamImp( + const CFX_RetainPtr& pFileRead); + ~CFGAS_FileReadStreamImp() override {} }; -class CFGAS_TextStream : public IFGAS_Stream { +class CFGAS_FileWriteStreamImp : public CFGAS_Stream { public: template friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); - // IFGAS_Stream - FX_FILESIZE GetLength() const override; - FX_FILESIZE GetPosition() override; - FX_STRSIZE GetBOMLength() const override; - void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; - bool IsEOF() const override; - FX_STRSIZE ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) override; - void WriteString(const CFX_WideStringC& str) override; - uint16_t GetCodePage() const override; - void SetCodePage(uint16_t wCodePage) override; + // CFGAS_Stream: + void WriteData(const CFX_WideStringC& str) override; private: - CFGAS_TextStream(std::unique_ptr imp, bool isWriteSteam); - ~CFGAS_TextStream() override; - - void InitStream(); - - uint16_t m_wCodePage; - FX_STRSIZE m_wBOMLength; - bool m_IsWriteStream; - std::unique_ptr m_pStreamImp; + explicit CFGAS_FileWriteStreamImp( + const CFX_RetainPtr& pFileWrite); + ~CFGAS_FileWriteStreamImp() override {} }; class CFGAS_WideStringReadStream : public IFGAS_Stream { @@ -116,16 +89,20 @@ class CFGAS_WideStringReadStream : public IFGAS_Stream { friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); // IFGAS_Stream - FX_FILESIZE GetLength() const override; - FX_FILESIZE GetPosition() override; + FX_FILESIZE GetLength() const override { + return m_wsBuffer.GetLength() * sizeof(wchar_t); + } + FX_FILESIZE GetPosition() override { return m_iPosition * sizeof(wchar_t); } FX_STRSIZE GetBOMLength() const override { return 0; } void Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) override; - bool IsEOF() const override; + bool IsEOF() const override { return m_iPosition >= m_wsBuffer.GetLength(); } FX_STRSIZE ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS) override; void WriteString(const CFX_WideStringC& str) override {} - uint16_t GetCodePage() const override; + uint16_t GetCodePage() const override { + return sizeof(wchar_t) == 2 ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; + } void SetCodePage(uint16_t wCodePage) override {} private: @@ -228,7 +205,7 @@ void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) { wch = (wch >> 8) | (wch << 8); wch &= 0x00FF; *pStr = wch; - pStr++; + ++pStr; } return; } @@ -237,117 +214,10 @@ void SwapByteOrder(wchar_t* pStr, FX_STRSIZE iLength) { wch = static_cast(*pStr); wch = (wch >> 8) | (wch << 8); *pStr = wch; - pStr++; + ++pStr; } } -IFGAS_StreamImp::IFGAS_StreamImp() {} - -CFGAS_FileReadStreamImp::CFGAS_FileReadStreamImp( - const CFX_RetainPtr& pFileRead) - : m_pFileRead(pFileRead), m_iPosition(0) { - ASSERT(m_pFileRead); -} - -FX_FILESIZE CFGAS_FileReadStreamImp::GetLength() const { - return m_pFileRead->GetSize(); -} - -void CFGAS_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) { - switch (eSeek) { - case FX_STREAMSEEK_Begin: - m_iPosition = iOffset; - break; - case FX_STREAMSEEK_Current: - m_iPosition += iOffset; - break; - } - m_iPosition = pdfium::clamp(m_iPosition, static_cast(0), - m_pFileRead->GetSize()); -} - -bool CFGAS_FileReadStreamImp::IsEOF() const { - return m_iPosition >= m_pFileRead->GetSize(); -} - -FX_STRSIZE CFGAS_FileReadStreamImp::ReadData(uint8_t* pBuffer, - FX_STRSIZE iBufferSize) { - ASSERT(pBuffer && iBufferSize > 0); - - iBufferSize = - std::min(iBufferSize, - static_cast(m_pFileRead->GetSize() - m_iPosition)); - if (iBufferSize <= 0) - return 0; - - if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { - pdfium::base::CheckedNumeric new_pos = m_iPosition; - new_pos += iBufferSize; - if (!new_pos.IsValid()) - return 0; - - m_iPosition = new_pos.ValueOrDie(); - return iBufferSize; - } - return 0; -} - -CFGAS_FileWriteStreamImp::CFGAS_FileWriteStreamImp( - const CFX_RetainPtr& pFileWrite) - : m_pFileWrite(pFileWrite), m_iPosition(m_pFileWrite->GetSize()) { - ASSERT(m_pFileWrite); -} - -FX_FILESIZE CFGAS_FileWriteStreamImp::GetLength() const { - return m_pFileWrite->GetSize(); -} - -void CFGAS_FileWriteStreamImp::Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) { - FX_FILESIZE iLength = GetLength(); - switch (eSeek) { - case FX_STREAMSEEK_Begin: - m_iPosition = iOffset; - break; - case FX_STREAMSEEK_Current: - m_iPosition += iOffset; - break; - } - m_iPosition = - pdfium::clamp(m_iPosition, static_cast(0), iLength); -} - -bool CFGAS_FileWriteStreamImp::IsEOF() const { - return m_iPosition >= GetLength(); -} - -void CFGAS_FileWriteStreamImp::WriteData(const CFX_WideStringC& str) { - if (str.GetLength() == 0) - return; - - if (m_pFileWrite->WriteBlock(str.c_str(), m_iPosition, - str.GetLength() * sizeof(wchar_t))) { - pdfium::base::CheckedNumeric new_pos = m_iPosition; - new_pos += str.GetLength() * sizeof(wchar_t); - // TODO(dsinclair): Not sure what to do if we over flow .... - if (!new_pos.IsValid()) - return; - - m_iPosition = new_pos.ValueOrDie(); - } -} - -CFGAS_TextStream::CFGAS_TextStream(std::unique_ptr imp, - bool isWriteStream) - : m_wCodePage(FX_CODEPAGE_DefANSI), - m_wBOMLength(0), - m_IsWriteStream(isWriteStream), - m_pStreamImp(std::move(imp)) { - ASSERT(m_pStreamImp); - InitStream(); -} - -CFGAS_TextStream::~CFGAS_TextStream() {} - #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ #define BOM_MASK 0x00FFFFFF #define BOM_UTF8 0x00BFBBEF @@ -362,12 +232,14 @@ CFGAS_TextStream::~CFGAS_TextStream() {} #define BOM_UTF16_LE 0xFFFE0000 #endif // _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ -void CFGAS_TextStream::InitStream() { - FX_FILESIZE iPosition = m_pStreamImp->GetPosition(); - m_pStreamImp->Seek(FX_STREAMSEEK_Begin, 0); +CFGAS_FileReadStreamImp::CFGAS_FileReadStreamImp( + const CFX_RetainPtr& pFileRead) + : CFGAS_Stream(pFileRead, false) { + FX_FILESIZE iPosition = GetPosition(); + Seek(FX_STREAMSEEK_Begin, 0); uint32_t bom; - m_pStreamImp->ReadData(reinterpret_cast(&bom), 3); + ReadData(reinterpret_cast(&bom), 3); bom &= BOM_MASK; if (bom == BOM_UTF8) { @@ -387,46 +259,88 @@ void CFGAS_TextStream::InitStream() { } } - m_pStreamImp->Seek( - FX_STREAMSEEK_Begin, - std::max(static_cast(m_wBOMLength), iPosition)); + Seek(FX_STREAMSEEK_Begin, + std::max(static_cast(m_wBOMLength), iPosition)); } -FX_FILESIZE CFGAS_TextStream::GetLength() const { - return m_pStreamImp->GetLength(); -} +FX_STRSIZE CFGAS_FileReadStreamImp::ReadData(uint8_t* pBuffer, + FX_STRSIZE iBufferSize) { + ASSERT(pBuffer && iBufferSize > 0); + + iBufferSize = std::min( + iBufferSize, static_cast(m_pStream->GetSize() - m_iPosition)); + if (iBufferSize <= 0) + return 0; -void CFGAS_TextStream::Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) { - m_pStreamImp->Seek(eSeek, iOffset); + if (m_pStream->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { + pdfium::base::CheckedNumeric new_pos = m_iPosition; + new_pos += iBufferSize; + if (!new_pos.IsValid()) + return 0; + + m_iPosition = new_pos.ValueOrDie(); + return iBufferSize; + } + return 0; } -FX_FILESIZE CFGAS_TextStream::GetPosition() { - return m_pStreamImp->GetPosition(); +CFGAS_FileWriteStreamImp::CFGAS_FileWriteStreamImp( + const CFX_RetainPtr& pFileWrite) + : CFGAS_Stream(pFileWrite, true) { + m_iPosition = m_pStream->GetSize(); } -bool CFGAS_TextStream::IsEOF() const { - return m_pStreamImp->IsEOF(); +void CFGAS_FileWriteStreamImp::WriteData(const CFX_WideStringC& str) { + if (str.GetLength() == 0) + return; + + if (!m_pStream->WriteBlock(str.c_str(), m_iPosition, + str.GetLength() * sizeof(wchar_t))) + return; + + pdfium::base::CheckedNumeric new_pos = m_iPosition; + new_pos += str.GetLength() * sizeof(wchar_t); + // TODO(dsinclair): Not sure what to do if we over flow .... + if (!new_pos.IsValid()) + return; + + m_iPosition = new_pos.ValueOrDie(); } -FX_STRSIZE CFGAS_TextStream::GetBOMLength() const { - if (m_wBOMLength < 1) - return 0; - return m_wBOMLength; +CFGAS_Stream::CFGAS_Stream(const CFX_RetainPtr& stream, + bool isWriteStream) + : m_wCodePage(FX_CODEPAGE_DefANSI), + m_wBOMLength(0), + m_IsWriteStream(isWriteStream), + m_iPosition(0), + m_pStream(stream) { + ASSERT(m_pStream); } -uint16_t CFGAS_TextStream::GetCodePage() const { - return m_wCodePage; +CFGAS_Stream::~CFGAS_Stream() {} + +void CFGAS_Stream::Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) { + switch (eSeek) { + case FX_STREAMSEEK_Begin: + m_iPosition = iOffset; + break; + case FX_STREAMSEEK_Current: + m_iPosition += iOffset; + break; + } + m_iPosition = + pdfium::clamp(m_iPosition, static_cast(0), GetLength()); } -void CFGAS_TextStream::SetCodePage(uint16_t wCodePage) { +void CFGAS_Stream::SetCodePage(uint16_t wCodePage) { if (m_wBOMLength > 0) return; m_wCodePage = wCodePage; } -FX_STRSIZE CFGAS_TextStream::ReadString(wchar_t* pStr, - FX_STRSIZE iMaxLength, - bool* bEOS) { +FX_STRSIZE CFGAS_Stream::ReadString(wchar_t* pStr, + FX_STRSIZE iMaxLength, + bool* bEOS) { ASSERT(pStr && iMaxLength > 0); if (m_IsWriteStream) @@ -435,8 +349,7 @@ FX_STRSIZE CFGAS_TextStream::ReadString(wchar_t* pStr, if (m_wCodePage == FX_CODEPAGE_UTF16LE || m_wCodePage == FX_CODEPAGE_UTF16BE) { FX_FILESIZE iBytes = iMaxLength * 2; - FX_STRSIZE iLen = - m_pStreamImp->ReadData(reinterpret_cast(pStr), iBytes); + FX_STRSIZE iLen = ReadData(reinterpret_cast(pStr), iBytes); iMaxLength = iLen / 2; if (sizeof(wchar_t) > 2) UTF16ToWChar(pStr, iMaxLength); @@ -450,31 +363,31 @@ FX_STRSIZE CFGAS_TextStream::ReadString(wchar_t* pStr, #endif } else { - FX_FILESIZE pos = m_pStreamImp->GetPosition(); - FX_STRSIZE iBytes = std::min( - iMaxLength, static_cast(m_pStreamImp->GetLength() - pos)); + FX_FILESIZE pos = GetPosition(); + FX_STRSIZE iBytes = + std::min(iMaxLength, static_cast(GetLength() - pos)); if (iBytes > 0) { std::vector buf(iBytes); - FX_STRSIZE iLen = m_pStreamImp->ReadData(buf.data(), iBytes); + FX_STRSIZE iLen = ReadData(buf.data(), iBytes); if (m_wCodePage != FX_CODEPAGE_UTF8) return -1; FX_STRSIZE iSrc = 0; std::tie(iSrc, iMaxLength) = UTF8Decode( reinterpret_cast(buf.data()), iLen, pStr, iMaxLength); - m_pStreamImp->Seek(FX_STREAMSEEK_Current, iSrc - iLen); + Seek(FX_STREAMSEEK_Current, iSrc - iLen); } else { iMaxLength = 0; } } - *bEOS = m_pStreamImp->IsEOF(); + *bEOS = IsEOF(); return iMaxLength; } -void CFGAS_TextStream::WriteString(const CFX_WideStringC& str) { +void CFGAS_Stream::WriteString(const CFX_WideStringC& str) { if (!m_IsWriteStream) return; if (str.GetLength() == 0) @@ -482,7 +395,7 @@ void CFGAS_TextStream::WriteString(const CFX_WideStringC& str) { if (m_wCodePage != FX_CODEPAGE_UTF8) return; - m_pStreamImp->WriteData(str); + WriteData(str); } CFGAS_WideStringReadStream::CFGAS_WideStringReadStream( @@ -491,10 +404,6 @@ CFGAS_WideStringReadStream::CFGAS_WideStringReadStream( CFGAS_WideStringReadStream::~CFGAS_WideStringReadStream() {} -FX_FILESIZE CFGAS_WideStringReadStream::GetLength() const { - return m_wsBuffer.GetLength() * sizeof(wchar_t); -} - void CFGAS_WideStringReadStream::Seek(FX_STREAMSEEK eSeek, FX_FILESIZE iOffset) { switch (eSeek) { @@ -509,14 +418,6 @@ void CFGAS_WideStringReadStream::Seek(FX_STREAMSEEK eSeek, static_cast(m_wsBuffer.GetLength())); } -FX_FILESIZE CFGAS_WideStringReadStream::GetPosition() { - return m_iPosition * sizeof(wchar_t); -} - -bool CFGAS_WideStringReadStream::IsEOF() const { - return m_iPosition >= m_wsBuffer.GetLength(); -} - FX_STRSIZE CFGAS_WideStringReadStream::ReadString(wchar_t* pStr, FX_STRSIZE iMaxLength, bool* bEOS) { @@ -532,30 +433,24 @@ FX_STRSIZE CFGAS_WideStringReadStream::ReadString(wchar_t* pStr, return iMaxLength; } -uint16_t CFGAS_WideStringReadStream::GetCodePage() const { - return (sizeof(wchar_t) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE; -} - } // namespace // static CFX_RetainPtr IFGAS_Stream::CreateReadStream( - const CFX_RetainPtr& pFileRead) { + const CFX_RetainPtr& pFileRead) { if (!pFileRead) return nullptr; - return pdfium::MakeRetain( - pdfium::MakeUnique(pFileRead), false); + return pdfium::MakeRetain(pFileRead); } // static CFX_RetainPtr IFGAS_Stream::CreateWriteStream( - const CFX_RetainPtr& pFileWrite) { + const CFX_RetainPtr& pFileWrite) { if (!pFileWrite) return nullptr; - return pdfium::MakeRetain( - pdfium::MakeUnique(pFileWrite), true); + return pdfium::MakeRetain(pFileWrite); } // static diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h index be42fe5ca3..620a023dd8 100644 --- a/xfa/fgas/crt/ifgas_stream.h +++ b/xfa/fgas/crt/ifgas_stream.h @@ -19,9 +19,9 @@ enum FX_STREAMSEEK { class IFGAS_Stream : public CFX_Retainable { public: static CFX_RetainPtr CreateReadStream( - const CFX_RetainPtr& pFileRead); + const CFX_RetainPtr& pFileRead); static CFX_RetainPtr CreateWriteStream( - const CFX_RetainPtr& pFileWrite); + const CFX_RetainPtr& pFileWrite); static CFX_RetainPtr CreateWideStringReadStream( const CFX_WideString& buffer); diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 2bbdfa1b9c..3565370bde 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -281,7 +281,7 @@ CXFA_FFDocView* CXFA_FFDoc::GetDocView() { return m_DocView.get(); } -bool CXFA_FFDoc::OpenDoc(const CFX_RetainPtr& pStream) { +bool CXFA_FFDoc::OpenDoc(const CFX_RetainPtr& pStream) { m_pStream = pStream; return true; } @@ -389,9 +389,8 @@ CFX_RetainPtr CXFA_FFDoc::GetPDFNamedImage( auto pAcc = pdfium::MakeRetain(pStream); pAcc->LoadAllData(); - CFX_RetainPtr pImageFileRead = - IFX_MemoryStream::Create(const_cast(pAcc->GetData()), - pAcc->GetSize()); + CFX_RetainPtr pImageFileRead = IFX_MemoryStream::Create( + const_cast(pAcc->GetData()), pAcc->GetSize()); CFX_RetainPtr pDibSource = XFA_LoadImageFromBuffer( pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); @@ -399,10 +398,9 @@ CFX_RetainPtr CXFA_FFDoc::GetPDFNamedImage( return pDibSource; } -bool CXFA_FFDoc::SavePackage( - XFA_HashCode code, - const CFX_RetainPtr& pFile, - CFX_ChecksumContext* pCSContext) { +bool CXFA_FFDoc::SavePackage(XFA_HashCode code, + const CFX_RetainPtr& pFile, + CFX_ChecksumContext* pCSContext) { CXFA_Document* doc = m_pDocumentParser->GetDocument(); auto pExport = pdfium::MakeUnique(doc); CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot() @@ -418,9 +416,8 @@ bool CXFA_FFDoc::SavePackage( pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); } -bool CXFA_FFDoc::ImportData( - const CFX_RetainPtr& pStream, - bool bXDP) { +bool CXFA_FFDoc::ImportData(const CFX_RetainPtr& pStream, + bool bXDP) { auto importer = pdfium::MakeUnique(m_pDocumentParser->GetDocument()); return importer->ImportData(pStream); diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h index 0bba956f14..c5822e3577 100644 --- a/xfa/fxfa/cxfa_ffdoc.h +++ b/xfa/fxfa/cxfa_ffdoc.h @@ -58,7 +58,7 @@ class CXFA_FFDoc { CXFA_FFDocView* CreateDocView(); - bool OpenDoc(const CFX_RetainPtr& pStream); + bool OpenDoc(const CFX_RetainPtr& pStream); bool OpenDoc(CPDF_Document* pPDFDoc); bool CloseDoc(); @@ -72,15 +72,15 @@ class CXFA_FFDoc { int32_t& iImageYDpi); bool SavePackage(XFA_HashCode code, - const CFX_RetainPtr& pFile, + const CFX_RetainPtr& pFile, CFX_ChecksumContext* pCSContext); - bool ImportData(const CFX_RetainPtr& pStream, + bool ImportData(const CFX_RetainPtr& pStream, bool bXDP = true); private: IXFA_DocEnvironment* const m_pDocEnvironment; std::unique_ptr m_pDocumentParser; - CFX_RetainPtr m_pStream; + CFX_RetainPtr m_pStream; CXFA_FFApp* m_pApp; std::unique_ptr m_pNotify; CPDF_Document* m_pPDFDoc; diff --git a/xfa/fxfa/cxfa_fileread.cpp b/xfa/fxfa/cxfa_fileread.cpp index e2ecad2e93..acd81a2232 100644 --- a/xfa/fxfa/cxfa_fileread.cpp +++ b/xfa/fxfa/cxfa_fileread.cpp @@ -54,3 +54,28 @@ bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { } return false; } + +size_t CXFA_FileRead::ReadBlock(void* buffer, size_t size) { + ASSERT(false); + return 0; +} + +FX_FILESIZE CXFA_FileRead::GetPosition() { + return 0; +} + +bool CXFA_FileRead::IsEOF() { + return false; +} + +bool CXFA_FileRead::Flush() { + ASSERT(false); + return false; +} + +bool CXFA_FileRead::WriteBlock(const void* pData, + FX_FILESIZE offset, + size_t size) { + ASSERT(false); + return false; +} diff --git a/xfa/fxfa/cxfa_fileread.h b/xfa/fxfa/cxfa_fileread.h index 0c3348b8d5..2dba4d23df 100644 --- a/xfa/fxfa/cxfa_fileread.h +++ b/xfa/fxfa/cxfa_fileread.h @@ -15,14 +15,19 @@ class CPDF_Stream; class CPDF_StreamAcc; -class CXFA_FileRead : public IFX_SeekableReadStream { +class CXFA_FileRead : public IFX_SeekableStream { public: explicit CXFA_FileRead(const std::vector& streams); ~CXFA_FileRead() override; // IFX_SeekableReadStream + FX_FILESIZE GetPosition() override; FX_FILESIZE GetSize() override; bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; + size_t ReadBlock(void* buffer, size_t size) override; + bool IsEOF() override; + bool Flush() override; + bool WriteBlock(const void* pData, FX_FILESIZE offset, size_t size) override; private: std::vector> m_Data; diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index 3976fd6912..4e3b0b3ffa 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -474,15 +474,14 @@ CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument) } bool CXFA_DataExporter::Export( - const CFX_RetainPtr& pWrite) { + const CFX_RetainPtr& pWrite) { return Export(pWrite, m_pDocument->GetRoot(), 0, nullptr); } -bool CXFA_DataExporter::Export( - const CFX_RetainPtr& pWrite, - CXFA_Node* pNode, - uint32_t dwFlag, - const char* pChecksum) { +bool CXFA_DataExporter::Export(const CFX_RetainPtr& pWrite, + CXFA_Node* pNode, + uint32_t dwFlag, + const char* pChecksum) { ASSERT(pWrite); if (!pWrite) return false; diff --git a/xfa/fxfa/parser/cxfa_dataexporter.h b/xfa/fxfa/parser/cxfa_dataexporter.h index ac441ca21d..8f405b188d 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.h +++ b/xfa/fxfa/parser/cxfa_dataexporter.h @@ -12,15 +12,15 @@ class CXFA_Document; class CXFA_Node; -class IFX_SeekableWriteStream; +class IFX_SeekableStream; class IFGAS_Stream; class CXFA_DataExporter { public: explicit CXFA_DataExporter(CXFA_Document* pDocument); - bool Export(const CFX_RetainPtr& pWrite); - bool Export(const CFX_RetainPtr& pWrite, + bool Export(const CFX_RetainPtr& pWrite); + bool Export(const CFX_RetainPtr& pWrite, CXFA_Node* pNode, uint32_t dwFlag, const char* pChecksum); diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp index 200841f5cb..d87d0914e4 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp @@ -23,7 +23,7 @@ CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) } bool CXFA_DataImporter::ImportData( - const CFX_RetainPtr& pDataDocument) { + const CFX_RetainPtr& pDataDocument) { auto pDataDocumentParser = pdfium::MakeUnique(m_pDocument, false); if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != diff --git a/xfa/fxfa/parser/cxfa_dataimporter.h b/xfa/fxfa/parser/cxfa_dataimporter.h index 4e8bdda314..e76475cd1e 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.h +++ b/xfa/fxfa/parser/cxfa_dataimporter.h @@ -11,13 +11,13 @@ #include "core/fxcrt/fx_system.h" class CXFA_Document; -class IFX_SeekableReadStream; +class IFX_SeekableStream; class CXFA_DataImporter { public: explicit CXFA_DataImporter(CXFA_Document* pDocument); - bool ImportData(const CFX_RetainPtr& pDataDocument); + bool ImportData(const CFX_RetainPtr& pDataDocument); private: CXFA_Document* const m_pDocument; diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index b855513f52..a6860d6b52 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -18,7 +18,7 @@ CXFA_DocumentParser::~CXFA_DocumentParser() { } int32_t CXFA_DocumentParser::StartParse( - const CFX_RetainPtr& pStream, + const CFX_RetainPtr& pStream, XFA_XDPPACKET ePacketID) { m_pDocument.reset(); m_nodeParser.CloseParser(); diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h index 9a219f74c1..90bd47f829 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.h +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -15,7 +15,7 @@ class CFDE_XMLDoc; class CXFA_Document; class CXFA_FFNotify; class CXFA_Notify; -class IFX_SeekableReadStream; +class IFX_SeekableStream; class IFX_Pause; class CXFA_DocumentParser { @@ -23,7 +23,7 @@ class CXFA_DocumentParser { explicit CXFA_DocumentParser(CXFA_FFNotify* pNotify); ~CXFA_DocumentParser(); - int32_t StartParse(const CFX_RetainPtr& pStream, + int32_t StartParse(const CFX_RetainPtr& pStream, XFA_XDPPACKET ePacketID); int32_t DoParse(IFX_Pause* pPause); diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index cce4b68a27..806e5445a0 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -273,7 +273,7 @@ void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { } int32_t CXFA_SimpleParser::StartParse( - const CFX_RetainPtr& pStream, + const CFX_RetainPtr& pStream, XFA_XDPPACKET ePacketID) { CloseParser(); m_pFileRead = pStream; diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index a9bcec2139..ccb258a7d4 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -17,7 +17,7 @@ class CFDE_XMLDoc; class CFDE_XMLInstruction; class CFDE_XMLNode; class CFDE_XMLParser; -class IFX_SeekableReadStream; +class IFX_SeekableStream; class IFX_Pause; class IFGAS_Stream; @@ -26,7 +26,7 @@ class CXFA_SimpleParser { CXFA_SimpleParser(CXFA_Document* pFactory, bool bDocumentParser); ~CXFA_SimpleParser(); - int32_t StartParse(const CFX_RetainPtr& pStream, + int32_t StartParse(const CFX_RetainPtr& pStream, XFA_XDPPACKET ePacketID); int32_t DoParse(IFX_Pause* pPause); int32_t ParseXMLData(const CFX_WideString& wsXML, @@ -81,7 +81,7 @@ class CXFA_SimpleParser { CFDE_XMLParser* m_pXMLParser; std::unique_ptr m_pXMLDoc; CFX_RetainPtr m_pStream; - CFX_RetainPtr m_pFileRead; + CFX_RetainPtr m_pFileRead; CXFA_Document* m_pFactory; CXFA_Node* m_pRootNode; XFA_XDPPACKET m_ePacketID; -- cgit v1.2.3