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/fpdf_parser/include/cpdf_stream.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" |
11 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 11 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
12 #include "third_party/base/stl_util.h" | |
12 | 13 |
13 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) | 14 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) |
14 : m_pDict(pDict), | 15 : m_pDict(pDict), |
15 m_dwSize(size), | 16 m_dwSize(size), |
16 m_GenNum(kMemoryBasedGenNum), | 17 m_GenNum(kMemoryBasedGenNum), |
17 m_pDataBuf(pData) {} | 18 m_pDataBuf(pData) {} |
18 | 19 |
19 CPDF_Stream::~CPDF_Stream() { | 20 CPDF_Stream::~CPDF_Stream() { |
20 if (IsMemoryBased()) | 21 if (IsMemoryBased()) |
21 FX_Free(m_pDataBuf); | 22 FX_Free(m_pDataBuf); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 m_GenNum = kMemoryBasedGenNum; | 65 m_GenNum = kMemoryBasedGenNum; |
65 m_pDataBuf = FX_Alloc(uint8_t, size); | 66 m_pDataBuf = FX_Alloc(uint8_t, size); |
66 if (pData) | 67 if (pData) |
67 FXSYS_memcpy(m_pDataBuf, pData, size); | 68 FXSYS_memcpy(m_pDataBuf, pData, size); |
68 | 69 |
69 m_dwSize = size; | 70 m_dwSize = size; |
70 if (m_pDict) | 71 if (m_pDict) |
71 m_pDict->SetAtInteger("Length", size); | 72 m_pDict->SetAtInteger("Length", size); |
72 } | 73 } |
73 | 74 |
74 CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const { | 75 CPDF_Object* CPDF_Stream::Clone() const { |
76 return CloneDeRef(false); | |
77 } | |
78 | |
79 CPDF_Object* CPDF_Stream::CloneWithCheck( | |
80 bool bDirect, | |
81 std::set<const CPDF_Object*>* pVisited) const { | |
82 pVisited->insert(this); | |
75 CPDF_StreamAcc acc; | 83 CPDF_StreamAcc acc; |
76 acc.LoadAllData(this, TRUE); | 84 acc.LoadAllData(this, TRUE); |
77 uint32_t streamSize = acc.GetSize(); | 85 uint32_t streamSize = acc.GetSize(); |
78 CPDF_Dictionary* pDict = GetDict(); | 86 CPDF_Dictionary* pDict = GetDict(); |
79 if (pDict) | 87 if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) |
dsinclair
2016/08/18 14:04:31
nit: {}'s
Wei Li
2016/08/18 22:02:30
Done.
| |
80 pDict = ToDictionary(pDict->Clone(bDirect)); | 88 pDict = ToDictionary(static_cast<const CPDF_Object*>(pDict)->CloneWithCheck( |
dsinclair
2016/08/18 14:04:31
Why static_cast to Object?
Wei Li
2016/08/18 22:02:30
Original, I only expose CPDF_Object::CloneWithChec
| |
89 bDirect, pVisited)); | |
81 | 90 |
82 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); | 91 return new CPDF_Stream(acc.DetachData(), streamSize, pDict); |
83 } | 92 } |
84 | 93 |
85 void CPDF_Stream::SetData(const uint8_t* pData, | 94 void CPDF_Stream::SetData(const uint8_t* pData, |
86 uint32_t size, | 95 uint32_t size, |
87 FX_BOOL bCompressed, | 96 FX_BOOL bCompressed, |
88 FX_BOOL bKeepBuf) { | 97 FX_BOOL bKeepBuf) { |
89 if (IsMemoryBased()) | 98 if (IsMemoryBased()) |
90 FX_Free(m_pDataBuf); | 99 FX_Free(m_pDataBuf); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 if (m_pDict) | 137 if (m_pDict) |
129 m_pDict->SetAtInteger("Length", m_dwSize); | 138 m_pDict->SetAtInteger("Length", m_dwSize); |
130 } | 139 } |
131 | 140 |
132 CFX_WideString CPDF_Stream::GetUnicodeText() const { | 141 CFX_WideString CPDF_Stream::GetUnicodeText() const { |
133 CPDF_StreamAcc stream; | 142 CPDF_StreamAcc stream; |
134 stream.LoadAllData(this, FALSE); | 143 stream.LoadAllData(this, FALSE); |
135 return PDF_DecodeText(stream.GetData(), stream.GetSize()); | 144 return PDF_DecodeText(stream.GetData(), stream.GetSize()); |
136 } | 145 } |
137 | 146 |
OLD | NEW |