OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/fpdfapi/parser/cpdf_stream.h" | 7 #include "core/fpdfapi/parser/cpdf_stream.h" |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 11 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
12 #include "core/fpdfapi/parser/cpdf_number.h" | 12 #include "core/fpdfapi/parser/cpdf_number.h" |
13 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 13 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
14 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 14 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
15 #include "third_party/base/numerics/safe_conversions.h" | 15 #include "third_party/base/numerics/safe_conversions.h" |
16 #include "third_party/base/ptr_util.h" | 16 #include "third_party/base/ptr_util.h" |
17 #include "third_party/base/stl_util.h" | 17 #include "third_party/base/stl_util.h" |
18 | 18 |
19 CPDF_Stream::CPDF_Stream() {} | 19 CPDF_Stream::CPDF_Stream() {} |
20 | 20 |
21 CPDF_Stream::CPDF_Stream(uint8_t* pData, | 21 CPDF_Stream::CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData, |
22 uint32_t size, | 22 uint32_t size, |
23 std::unique_ptr<CPDF_Dictionary> pDict) | 23 std::unique_ptr<CPDF_Dictionary> pDict) |
24 : m_dwSize(size), m_pDict(std::move(pDict)), m_pDataBuf(pData) {} | 24 : m_dwSize(size), m_pDict(std::move(pDict)), m_pDataBuf(std::move(pData)) {} |
25 | 25 |
26 CPDF_Stream::~CPDF_Stream() { | 26 CPDF_Stream::~CPDF_Stream() { |
27 m_ObjNum = kInvalidObjNum; | 27 m_ObjNum = kInvalidObjNum; |
28 if (m_pDict && m_pDict->GetObjNum() == kInvalidObjNum) | 28 if (m_pDict && m_pDict->GetObjNum() == kInvalidObjNum) |
29 m_pDict.release(); // lowercase release, release ownership. | 29 m_pDict.release(); // lowercase release, release ownership. |
30 } | 30 } |
31 | 31 |
32 CPDF_Object::Type CPDF_Stream::GetType() const { | 32 CPDF_Object::Type CPDF_Stream::GetType() const { |
33 return STREAM; | 33 return STREAM; |
34 } | 34 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 CPDF_StreamAcc acc; | 86 CPDF_StreamAcc acc; |
87 acc.LoadAllData(this, true); | 87 acc.LoadAllData(this, true); |
88 | 88 |
89 uint32_t streamSize = acc.GetSize(); | 89 uint32_t streamSize = acc.GetSize(); |
90 CPDF_Dictionary* pDict = GetDict(); | 90 CPDF_Dictionary* pDict = GetDict(); |
91 std::unique_ptr<CPDF_Dictionary> pNewDict; | 91 std::unique_ptr<CPDF_Dictionary> pNewDict; |
92 if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) { | 92 if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) { |
93 pNewDict = ToDictionary( | 93 pNewDict = ToDictionary( |
94 static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited)); | 94 static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited)); |
95 } | 95 } |
96 return pdfium::MakeUnique<CPDF_Stream>(acc.DetachData().release(), streamSize, | 96 return pdfium::MakeUnique<CPDF_Stream>(acc.DetachData(), streamSize, |
97 std::move(pNewDict)); | 97 std::move(pNewDict)); |
98 } | 98 } |
99 | 99 |
100 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { | 100 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { |
101 m_bMemoryBased = true; | 101 m_bMemoryBased = true; |
102 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); | 102 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); |
103 if (pData) | 103 if (pData) |
104 FXSYS_memcpy(m_pDataBuf.get(), pData, size); | 104 FXSYS_memcpy(m_pDataBuf.get(), pData, size); |
105 m_dwSize = size; | 105 m_dwSize = size; |
106 if (!m_pDict) | 106 if (!m_pDict) |
(...skipping 17 matching lines...) Expand all Loading... |
124 | 124 |
125 bool CPDF_Stream::HasFilter() const { | 125 bool CPDF_Stream::HasFilter() const { |
126 return m_pDict && m_pDict->KeyExist("Filter"); | 126 return m_pDict && m_pDict->KeyExist("Filter"); |
127 } | 127 } |
128 | 128 |
129 CFX_WideString CPDF_Stream::GetUnicodeText() const { | 129 CFX_WideString CPDF_Stream::GetUnicodeText() const { |
130 CPDF_StreamAcc stream; | 130 CPDF_StreamAcc stream; |
131 stream.LoadAllData(this, false); | 131 stream.LoadAllData(this, false); |
132 return PDF_DecodeText(stream.GetData(), stream.GetSize()); | 132 return PDF_DecodeText(stream.GetData(), stream.GetSize()); |
133 } | 133 } |
OLD | NEW |