From ccf206a7731e0df773a4c5941736953446ec4d9d Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Tue, 14 Nov 2017 16:05:53 +0000 Subject: Move CXFA_FileRead out of XFA and rename This code doesn't depend on XFA, but is only used by it. Moving it out, so it will be easier for me to write some tools for extracting data out of PDFs. Bug: Change-Id: Ic18613b46abed5124c47f539833b01b12c1c6e56 Reviewed-on: https://pdfium-review.googlesource.com/18410 Reviewed-by: dsinclair Commit-Queue: Ryan Harrison --- xfa/fxfa/cxfa_ffapp_unittest.cpp | 86 ---------------------------------------- xfa/fxfa/cxfa_ffdoc.cpp | 4 +- xfa/fxfa/cxfa_fileread.cpp | 82 -------------------------------------- xfa/fxfa/cxfa_fileread.h | 36 ----------------- 4 files changed, 2 insertions(+), 206 deletions(-) delete mode 100644 xfa/fxfa/cxfa_ffapp_unittest.cpp delete mode 100644 xfa/fxfa/cxfa_fileread.cpp delete mode 100644 xfa/fxfa/cxfa_fileread.h (limited to 'xfa') 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 -#include - -#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 streams; - auto fileread = pdfium::MakeRetain(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 streams; - auto stream1 = pdfium::MakeUnique(); - streams.push_back(stream1.get()); - auto fileread = pdfium::MakeRetain(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 streams; - auto stream1 = pdfium::MakeUnique(); - auto stream2 = pdfium::MakeUnique(); - auto stream3 = pdfium::MakeUnique(); - - // 16 chars total. - stream1->InitStream(reinterpret_cast("one t"), 5, - pdfium::MakeUnique()); - stream2->InitStream(reinterpret_cast("wo "), 3, - pdfium::MakeUnique()); - stream3->InitStream(reinterpret_cast("three!!!"), 8, - pdfium::MakeUnique()); - - streams.push_back(stream1.get()); - streams.push_back(stream2.get()); - streams.push_back(stream3.get()); - auto fileread = pdfium::MakeRetain(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(xfaStreams); + m_pStream = pdfium::MakeRetain(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 - -#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& streams) { - for (CPDF_Stream* pStream : streams) { - m_Data.push_back(pdfium::MakeRetain(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(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(dwSize - offset)); - memcpy(buffer, acc->GetData() + offset, dwRead); - size -= dwRead; - if (size == 0) - return true; - - buffer = static_cast(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 - -#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& 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; -}; - -#endif // XFA_FXFA_CXFA_FILEREAD_H_ -- cgit v1.2.3