diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-03-15 09:33:58 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-03-15 09:33:58 -0700 |
commit | 92bbb6fce88d1cb4d931da66adf690850ce62fd1 (patch) | |
tree | 5fa459547fd43200d341ef1849fad268e34743b5 /core/fpdfapi | |
parent | 2df269c52741c12d63300cee806e96ae5d0b038f (diff) | |
download | pdfium-92bbb6fce88d1cb4d931da66adf690850ce62fd1.tar.xz |
Split CPDF_Stream/CPDF_StreamAcc into separate files
R=dsinclair@chromium.org
Review URL: https://codereview.chromium.org/1783933003 .
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_parser.cpp | 1 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_stream.cpp | 97 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp | 107 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp | 1 |
5 files changed, 111 insertions, 96 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp index 012b152498..1dc015f34f 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp @@ -10,6 +10,7 @@ #include "core/include/fpdfapi/cpdf_array.h" #include "core/include/fpdfapi/cpdf_dictionary.h" #include "core/include/fpdfapi/cpdf_stream.h" +#include "core/include/fpdfapi/cpdf_stream_acc.h" #include "core/include/fxcrt/fx_safe_types.h" namespace { diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp index a39dbc031b..b57405f092 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp @@ -17,6 +17,7 @@ #include "core/include/fpdfapi/cpdf_number.h" #include "core/include/fpdfapi/cpdf_reference.h" #include "core/include/fpdfapi/cpdf_stream.h" +#include "core/include/fpdfapi/cpdf_stream_acc.h" #include "core/include/fpdfapi/ipdf_crypto_handler.h" #include "core/include/fxcrt/fx_ext.h" #include "core/include/fxcrt/fx_safe_types.h" diff --git a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp index 45c946ab5f..7faf9ddd44 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp @@ -7,6 +7,7 @@ #include "core/include/fpdfapi/cpdf_stream.h" #include "core/include/fpdfapi/cpdf_dictionary.h" +#include "core/include/fpdfapi/cpdf_stream_acc.h" #include "core/include/fpdfapi/fpdf_parser_decode.h" CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) @@ -134,99 +135,3 @@ CFX_WideString CPDF_Stream::GetUnicodeText() const { return PDF_DecodeText(stream.GetData(), stream.GetSize()); } -CPDF_StreamAcc::CPDF_StreamAcc() - : m_pData(nullptr), - m_dwSize(0), - m_bNewBuf(FALSE), - m_pImageParam(nullptr), - m_pStream(nullptr), - m_pSrcData(nullptr) {} - -void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, - FX_BOOL bRawAccess, - FX_DWORD estimated_size, - FX_BOOL bImageAcc) { - if (!pStream) - return; - - m_pStream = pStream; - if (pStream->IsMemoryBased() && - (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) { - m_dwSize = pStream->GetRawSize(); - m_pData = pStream->GetRawData(); - return; - } - uint8_t* pSrcData; - FX_DWORD dwSrcSize = pStream->GetRawSize(); - if (dwSrcSize == 0) - return; - - if (!pStream->IsMemoryBased()) { - pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); - if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) - return; - } else { - pSrcData = pStream->GetRawData(); - } - uint8_t* pDecryptedData = pSrcData; - FX_DWORD dwDecryptedSize = dwSrcSize; - if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) { - m_pData = pDecryptedData; - m_dwSize = dwDecryptedSize; - } else { - FX_BOOL bRet = PDF_DataDecode( - pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData, - m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc); - if (!bRet) { - m_pData = pDecryptedData; - m_dwSize = dwDecryptedSize; - } - } - if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) { - FX_Free(pSrcData); - } - if (pDecryptedData != pSrcData && pDecryptedData != m_pData) { - FX_Free(pDecryptedData); - } - m_pSrcData = nullptr; - m_bNewBuf = m_pData != pStream->GetRawData(); -} - -CPDF_StreamAcc::~CPDF_StreamAcc() { - if (m_bNewBuf) { - FX_Free(m_pData); - } - FX_Free(m_pSrcData); -} - -const uint8_t* CPDF_StreamAcc::GetData() const { - if (m_bNewBuf) { - return m_pData; - } - if (!m_pStream) { - return nullptr; - } - return m_pStream->GetRawData(); -} - -FX_DWORD CPDF_StreamAcc::GetSize() const { - if (m_bNewBuf) { - return m_dwSize; - } - if (!m_pStream) { - return 0; - } - return m_pStream->GetRawSize(); -} - -uint8_t* CPDF_StreamAcc::DetachData() { - if (m_bNewBuf) { - uint8_t* p = m_pData; - m_pData = nullptr; - m_dwSize = 0; - return p; - } - uint8_t* p = FX_Alloc(uint8_t, m_dwSize); - FXSYS_memcpy(p, m_pData, m_dwSize); - return p; -} diff --git a/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp b/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp new file mode 100644 index 0000000000..51ab1c0134 --- /dev/null +++ b/core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp @@ -0,0 +1,107 @@ +// 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. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/include/fpdfapi/cpdf_stream_acc.h" + +#include "core/include/fpdfapi/cpdf_dictionary.h" +#include "core/include/fpdfapi/fpdf_parser_decode.h" + +CPDF_StreamAcc::CPDF_StreamAcc() + : m_pData(nullptr), + m_dwSize(0), + m_bNewBuf(FALSE), + m_pImageParam(nullptr), + m_pStream(nullptr), + m_pSrcData(nullptr) {} + +void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, + FX_BOOL bRawAccess, + FX_DWORD estimated_size, + FX_BOOL bImageAcc) { + if (!pStream) + return; + + m_pStream = pStream; + if (pStream->IsMemoryBased() && + (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) { + m_dwSize = pStream->GetRawSize(); + m_pData = pStream->GetRawData(); + return; + } + uint8_t* pSrcData; + FX_DWORD dwSrcSize = pStream->GetRawSize(); + if (dwSrcSize == 0) + return; + + if (!pStream->IsMemoryBased()) { + pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); + if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) + return; + } else { + pSrcData = pStream->GetRawData(); + } + uint8_t* pDecryptedData = pSrcData; + FX_DWORD dwDecryptedSize = dwSrcSize; + if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) { + m_pData = pDecryptedData; + m_dwSize = dwDecryptedSize; + } else { + FX_BOOL bRet = PDF_DataDecode( + pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData, + m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc); + if (!bRet) { + m_pData = pDecryptedData; + m_dwSize = dwDecryptedSize; + } + } + if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) { + FX_Free(pSrcData); + } + if (pDecryptedData != pSrcData && pDecryptedData != m_pData) { + FX_Free(pDecryptedData); + } + m_pSrcData = nullptr; + m_bNewBuf = m_pData != pStream->GetRawData(); +} + +CPDF_StreamAcc::~CPDF_StreamAcc() { + if (m_bNewBuf) { + FX_Free(m_pData); + } + FX_Free(m_pSrcData); +} + +const uint8_t* CPDF_StreamAcc::GetData() const { + if (m_bNewBuf) { + return m_pData; + } + if (!m_pStream) { + return nullptr; + } + return m_pStream->GetRawData(); +} + +FX_DWORD CPDF_StreamAcc::GetSize() const { + if (m_bNewBuf) { + return m_dwSize; + } + if (!m_pStream) { + return 0; + } + return m_pStream->GetRawSize(); +} + +uint8_t* CPDF_StreamAcc::DetachData() { + if (m_bNewBuf) { + uint8_t* p = m_pData; + m_pData = nullptr; + m_dwSize = 0; + return p; + } + uint8_t* p = FX_Alloc(uint8_t, m_dwSize); + FXSYS_memcpy(p, m_pData, m_dwSize); + return p; +} diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp index 1f0ab5f876..3df220b79e 100644 --- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp +++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp @@ -11,6 +11,7 @@ #include "core/include/fpdfapi/cpdf_number.h" #include "core/include/fpdfapi/cpdf_reference.h" #include "core/include/fpdfapi/cpdf_stream.h" +#include "core/include/fpdfapi/cpdf_stream_acc.h" #include "core/include/fpdfapi/cpdf_string.h" #include "core/include/fpdfapi/fpdf_parser_decode.h" #include "core/include/fxcrt/fx_ext.h" |