summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-03-15 09:33:58 -0700
committerTom Sepez <tsepez@chromium.org>2016-03-15 09:33:58 -0700
commit92bbb6fce88d1cb4d931da66adf690850ce62fd1 (patch)
tree5fa459547fd43200d341ef1849fad268e34743b5 /core
parent2df269c52741c12d63300cee806e96ae5d0b038f (diff)
downloadpdfium-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')
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp1
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_parser.cpp1
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_stream.cpp97
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp107
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp1
-rw-r--r--core/fxcodec/jbig2/JBig2_BitStream.cpp1
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp1
-rw-r--r--core/include/fpdfapi/cpdf_object.h8
-rw-r--r--core/include/fpdfapi/cpdf_stream.h40
-rw-r--r--core/include/fpdfapi/cpdf_stream_acc.h46
-rw-r--r--core/include/fpdfapi/fpdf_resource.h1
11 files changed, 169 insertions, 135 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"
diff --git a/core/fxcodec/jbig2/JBig2_BitStream.cpp b/core/fxcodec/jbig2/JBig2_BitStream.cpp
index 87451c2d72..3e042bc92b 100644
--- a/core/fxcodec/jbig2/JBig2_BitStream.cpp
+++ b/core/fxcodec/jbig2/JBig2_BitStream.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_stream_acc.h"
CJBig2_BitStream::CJBig2_BitStream(CPDF_StreamAcc* pSrcStream)
: m_pBuf(pSrcStream->GetData()),
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 0a17fff328..d5eeda081c 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -21,6 +21,7 @@
#include "core/fxcodec/jbig2/JBig2_SddProc.h"
#include "core/fxcodec/jbig2/JBig2_TrdProc.h"
#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_stream_acc.h"
#include "third_party/base/stl_util.h"
namespace {
diff --git a/core/include/fpdfapi/cpdf_object.h b/core/include/fpdfapi/cpdf_object.h
index 2add5524a8..97499d140c 100644
--- a/core/include/fpdfapi/cpdf_object.h
+++ b/core/include/fpdfapi/cpdf_object.h
@@ -150,4 +150,12 @@ inline const CPDF_Reference* ToReference(const CPDF_Object* obj) {
return obj ? obj->AsReference() : nullptr;
}
+inline CPDF_Stream* ToStream(CPDF_Object* obj) {
+ return obj ? obj->AsStream() : nullptr;
+}
+
+inline const CPDF_Stream* ToStream(const CPDF_Object* obj) {
+ return obj ? obj->AsStream() : nullptr;
+}
+
#endif // CORE_INCLUDE_FPDFAPI_CPDF_OBJECT_H_
diff --git a/core/include/fpdfapi/cpdf_stream.h b/core/include/fpdfapi/cpdf_stream.h
index fd3b8c0047..579a3a97be 100644
--- a/core/include/fpdfapi/cpdf_stream.h
+++ b/core/include/fpdfapi/cpdf_stream.h
@@ -7,6 +7,7 @@
#ifndef CORE_INCLUDE_FPDFAPI_CPDF_STREAM_H_
#define CORE_INCLUDE_FPDFAPI_CPDF_STREAM_H_
+#include "core/include/fpdfapi/cpdf_dictionary.h"
#include "core/include/fpdfapi/cpdf_object.h"
#include "core/include/fxcrt/fx_stream.h"
@@ -57,43 +58,4 @@ class CPDF_Stream : public CPDF_Object {
};
};
-inline CPDF_Stream* ToStream(CPDF_Object* obj) {
- return obj ? obj->AsStream() : nullptr;
-}
-
-inline const CPDF_Stream* ToStream(const CPDF_Object* obj) {
- return obj ? obj->AsStream() : nullptr;
-}
-
-class CPDF_StreamAcc {
- public:
- CPDF_StreamAcc();
- ~CPDF_StreamAcc();
-
- void LoadAllData(const CPDF_Stream* pStream,
- FX_BOOL bRawAccess = FALSE,
- FX_DWORD estimated_size = 0,
- FX_BOOL bImageAcc = FALSE);
-
- const CPDF_Stream* GetStream() const { return m_pStream; }
- CPDF_Dictionary* GetDict() const {
- return m_pStream ? m_pStream->GetDict() : nullptr;
- }
- const uint8_t* GetData() const;
- FX_DWORD GetSize() const;
- const CFX_ByteString& GetImageDecoder() const { return m_ImageDecoder; }
- const CPDF_Dictionary* GetImageParam() const { return m_pImageParam; }
-
- uint8_t* DetachData();
-
- protected:
- uint8_t* m_pData;
- FX_DWORD m_dwSize;
- FX_BOOL m_bNewBuf;
- CFX_ByteString m_ImageDecoder;
- CPDF_Dictionary* m_pImageParam;
- const CPDF_Stream* m_pStream;
- uint8_t* m_pSrcData;
-};
-
#endif // CORE_INCLUDE_FPDFAPI_CPDF_STREAM_H_
diff --git a/core/include/fpdfapi/cpdf_stream_acc.h b/core/include/fpdfapi/cpdf_stream_acc.h
new file mode 100644
index 0000000000..77ad272de3
--- /dev/null
+++ b/core/include/fpdfapi/cpdf_stream_acc.h
@@ -0,0 +1,46 @@
+// 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
+
+#ifndef CORE_INCLUDE_FPDFAPI_CPDF_STREAM_ACC_H_
+#define CORE_INCLUDE_FPDFAPI_CPDF_STREAM_ACC_H_
+
+#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_dictionary.h"
+#include "core/include/fxcrt/fx_string.h"
+#include "core/include/fxcrt/fx_system.h"
+
+class CPDF_StreamAcc {
+ public:
+ CPDF_StreamAcc();
+ ~CPDF_StreamAcc();
+
+ void LoadAllData(const CPDF_Stream* pStream,
+ FX_BOOL bRawAccess = FALSE,
+ FX_DWORD estimated_size = 0,
+ FX_BOOL bImageAcc = FALSE);
+
+ const CPDF_Stream* GetStream() const { return m_pStream; }
+ CPDF_Dictionary* GetDict() const {
+ return m_pStream ? m_pStream->GetDict() : nullptr;
+ }
+
+ const uint8_t* GetData() const;
+ FX_DWORD GetSize() const;
+ const CFX_ByteString& GetImageDecoder() const { return m_ImageDecoder; }
+ const CPDF_Dictionary* GetImageParam() const { return m_pImageParam; }
+ uint8_t* DetachData();
+
+ protected:
+ uint8_t* m_pData;
+ FX_DWORD m_dwSize;
+ FX_BOOL m_bNewBuf;
+ CFX_ByteString m_ImageDecoder;
+ CPDF_Dictionary* m_pImageParam;
+ const CPDF_Stream* m_pStream;
+ uint8_t* m_pSrcData;
+};
+
+#endif // CORE_INCLUDE_FPDFAPI_CPDF_STREAM_ACC_H_
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 06b1245b4b..7c19dd52c3 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -10,6 +10,7 @@
#include <map>
#include "core/include/fpdfapi/cpdf_stream.h"
+#include "core/include/fpdfapi/cpdf_stream_acc.h"
#include "core/include/fxcrt/fx_system.h"
#include "core/include/fxge/fx_font.h"