diff options
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fxfa/cxfa_ffapp_unittest.cpp | 86 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdoc.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fileread.cpp | 82 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fileread.h | 36 |
4 files changed, 2 insertions, 206 deletions
diff --git a/xfa/fxfa/cxfa_ffapp_unittest.cpp b/xfa/fxfa/cxfa_ffapp_unittest.cpp deleted file mode 100644 index bd35956c39..0000000000 --- a/xfa/fxfa/cxfa_ffapp_unittest.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "xfa/fxfa/cxfa_ffapp.h" - -#include <memory> -#include <vector> - -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_stream.h" -#include "core/fxcrt/fx_memory.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/test_support.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxfa/cxfa_fileread.h" - -TEST(CXFAFileReadTest, NoStreams) { - std::vector<CPDF_Stream*> streams; - auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams); - - uint8_t output_buffer[16]; - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); -} - -TEST(CXFAFileReadTest, EmptyStreams) { - std::vector<CPDF_Stream*> streams; - auto stream1 = pdfium::MakeUnique<CPDF_Stream>(); - streams.push_back(stream1.get()); - auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams); - - uint8_t output_buffer[16]; - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); -} - -TEST(CXFAFileReadTest, NormalStreams) { - std::vector<CPDF_Stream*> streams; - auto stream1 = pdfium::MakeUnique<CPDF_Stream>(); - auto stream2 = pdfium::MakeUnique<CPDF_Stream>(); - auto stream3 = pdfium::MakeUnique<CPDF_Stream>(); - - // 16 chars total. - stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5, - pdfium::MakeUnique<CPDF_Dictionary>()); - stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3, - pdfium::MakeUnique<CPDF_Dictionary>()); - stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8, - pdfium::MakeUnique<CPDF_Dictionary>()); - - streams.push_back(stream1.get()); - streams.push_back(stream2.get()); - streams.push_back(stream3.get()); - auto fileread = pdfium::MakeRetain<CXFA_FileRead>(streams); - - uint8_t output_buffer[16]; - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 1, 0)); - EXPECT_EQ(0xbd, output_buffer[0]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 1)); - EXPECT_EQ(0, memcmp(output_buffer, "o", 1)); - EXPECT_EQ(0xbd, output_buffer[1]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, sizeof(output_buffer))); - EXPECT_EQ(0, memcmp(output_buffer, "one two three!!!", 16)); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_TRUE(fileread->ReadBlock(output_buffer, 2, 10)); - EXPECT_EQ(0, memcmp(output_buffer, "e two thre", 10)); - EXPECT_EQ(0xbd, output_buffer[11]); - - memset(output_buffer, 0xbd, sizeof(output_buffer)); - EXPECT_FALSE(fileread->ReadBlock(output_buffer, 1, sizeof(output_buffer))); - EXPECT_EQ(0, memcmp(output_buffer, "ne two three!!!", 15)); - EXPECT_EQ(0xbd, output_buffer[15]); -} diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 640ac39178..d53f1b2ad7 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -16,6 +16,7 @@ #include "core/fpdfdoc/cpdf_nametree.h" #include "core/fxcrt/cfx_checksumcontext.h" #include "core/fxcrt/cfx_memorystream.h" +#include "core/fxcrt/cfx_seekablemultistream.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/xml/cfx_xmlelement.h" @@ -26,7 +27,6 @@ #include "xfa/fxfa/cxfa_ffdocview.h" #include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidget.h" -#include "xfa/fxfa/cxfa_fileread.h" #include "xfa/fxfa/cxfa_fontmgr.h" #include "xfa/fxfa/parser/cxfa_dataexporter.h" #include "xfa/fxfa/parser/cxfa_dataimporter.h" @@ -316,7 +316,7 @@ bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { return false; m_pPDFDoc = pPDFDoc; - m_pStream = pdfium::MakeRetain<CXFA_FileRead>(xfaStreams); + m_pStream = pdfium::MakeRetain<CFX_SeekableMultiStream>(xfaStreams); return true; } diff --git a/xfa/fxfa/cxfa_fileread.cpp b/xfa/fxfa/cxfa_fileread.cpp deleted file mode 100644 index 12e23646d1..0000000000 --- a/xfa/fxfa/cxfa_fileread.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/cxfa_fileread.h" - -#include <algorithm> - -#include "core/fpdfapi/parser/cpdf_stream_acc.h" -#include "third_party/base/logging.h" -#include "third_party/base/stl_util.h" - -CXFA_FileRead::CXFA_FileRead(const std::vector<CPDF_Stream*>& streams) { - for (CPDF_Stream* pStream : streams) { - m_Data.push_back(pdfium::MakeRetain<CPDF_StreamAcc>(pStream)); - m_Data.back()->LoadAllData(); - } -} - -CXFA_FileRead::~CXFA_FileRead() {} - -FX_FILESIZE CXFA_FileRead::GetSize() { - uint32_t dwSize = 0; - for (const auto& acc : m_Data) - dwSize += acc->GetSize(); - return dwSize; -} - -bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { - int32_t iCount = pdfium::CollectionSize<int32_t>(m_Data); - int32_t index = 0; - while (index < iCount) { - const auto& acc = m_Data[index]; - FX_FILESIZE dwSize = acc->GetSize(); - if (offset < dwSize) - break; - - offset -= dwSize; - index++; - } - while (index < iCount) { - const auto& acc = m_Data[index]; - uint32_t dwSize = acc->GetSize(); - size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset)); - memcpy(buffer, acc->GetData() + offset, dwRead); - size -= dwRead; - if (size == 0) - return true; - - buffer = static_cast<uint8_t*>(buffer) + dwRead; - offset = 0; - index++; - } - return false; -} - -size_t CXFA_FileRead::ReadBlock(void* buffer, size_t size) { - NOTREACHED(); - return 0; -} - -FX_FILESIZE CXFA_FileRead::GetPosition() { - return 0; -} - -bool CXFA_FileRead::IsEOF() { - return false; -} - -bool CXFA_FileRead::Flush() { - NOTREACHED(); - return false; -} - -bool CXFA_FileRead::WriteBlock(const void* pData, - FX_FILESIZE offset, - size_t size) { - NOTREACHED(); - return false; -} diff --git a/xfa/fxfa/cxfa_fileread.h b/xfa/fxfa/cxfa_fileread.h deleted file mode 100644 index 62fa4c67bb..0000000000 --- a/xfa/fxfa/cxfa_fileread.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_CXFA_FILEREAD_H_ -#define XFA_FXFA_CXFA_FILEREAD_H_ - -#include <vector> - -#include "core/fxcrt/fx_stream.h" -#include "core/fxcrt/retain_ptr.h" - -class CPDF_Stream; -class CPDF_StreamAcc; - -class CXFA_FileRead : public IFX_SeekableStream { - public: - explicit CXFA_FileRead(const std::vector<CPDF_Stream*>& 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<RetainPtr<CPDF_StreamAcc>> m_Data; -}; - -#endif // XFA_FXFA_CXFA_FILEREAD_H_ |