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 "core/fpdfapi/parser/cpdf_dictionary.h" | 9 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
10 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 10 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 CPDF_Dictionary* pDict) { | 61 CPDF_Dictionary* pDict) { |
62 m_pDict.reset(pDict); | 62 m_pDict.reset(pDict); |
63 m_bMemoryBased = false; | 63 m_bMemoryBased = false; |
64 m_pDataBuf.reset(); | 64 m_pDataBuf.reset(); |
65 m_pFile = pFile; | 65 m_pFile = pFile; |
66 m_dwSize = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); | 66 m_dwSize = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); |
67 if (m_pDict) | 67 if (m_pDict) |
68 m_pDict->SetIntegerFor("Length", m_dwSize); | 68 m_pDict->SetIntegerFor("Length", m_dwSize); |
69 } | 69 } |
70 | 70 |
71 CPDF_Object* CPDF_Stream::Clone() const { | 71 std::unique_ptr<CPDF_Object> CPDF_Stream::Clone() const { |
72 return CloneObjectNonCyclic(false); | 72 return CloneObjectNonCyclic(false); |
73 } | 73 } |
74 | 74 |
75 CPDF_Object* CPDF_Stream::CloneNonCyclic( | 75 std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic( |
76 bool bDirect, | 76 bool bDirect, |
77 std::set<const CPDF_Object*>* pVisited) const { | 77 std::set<const CPDF_Object*>* pVisited) const { |
78 pVisited->insert(this); | 78 pVisited->insert(this); |
79 CPDF_StreamAcc acc; | 79 CPDF_StreamAcc acc; |
80 acc.LoadAllData(this, true); | 80 acc.LoadAllData(this, true); |
81 uint32_t streamSize = acc.GetSize(); | 81 uint32_t streamSize = acc.GetSize(); |
82 CPDF_Dictionary* pDict = GetDict(); | 82 CPDF_Dictionary* pDict = GetDict(); |
83 if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) { | 83 if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) { |
84 pDict = ToDictionary( | 84 pDict = ToDictionary(static_cast<CPDF_Object*>(pDict) |
85 static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited)); | 85 ->CloneNonCyclic(bDirect, pVisited) |
| 86 .release()); |
86 } | 87 } |
87 | 88 return pdfium::MakeUnique<CPDF_Stream>(acc.DetachData(), streamSize, pDict); |
88 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); | |
89 } | 89 } |
90 | 90 |
91 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { | 91 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { |
92 m_bMemoryBased = true; | 92 m_bMemoryBased = true; |
93 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); | 93 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); |
94 if (pData) | 94 if (pData) |
95 FXSYS_memcpy(m_pDataBuf.get(), pData, size); | 95 FXSYS_memcpy(m_pDataBuf.get(), pData, size); |
96 m_dwSize = size; | 96 m_dwSize = size; |
97 if (!m_pDict) | 97 if (!m_pDict) |
98 m_pDict.reset(new CPDF_Dictionary()); | 98 m_pDict.reset(new CPDF_Dictionary()); |
(...skipping 12 matching lines...) Expand all Loading... |
111 FXSYS_memcpy(buf, m_pDataBuf.get() + offset, size); | 111 FXSYS_memcpy(buf, m_pDataBuf.get() + offset, size); |
112 | 112 |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 CFX_WideString CPDF_Stream::GetUnicodeText() const { | 116 CFX_WideString CPDF_Stream::GetUnicodeText() const { |
117 CPDF_StreamAcc stream; | 117 CPDF_StreamAcc stream; |
118 stream.LoadAllData(this, false); | 118 stream.LoadAllData(this, false); |
119 return PDF_DecodeText(stream.GetData(), stream.GetSize()); | 119 return PDF_DecodeText(stream.GetData(), stream.GetSize()); |
120 } | 120 } |
OLD | NEW |