| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 CPDF_Object* CPDF_Stream::Clone() const { | 71 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 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( |
| 85 static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited)); | 85 static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 return new 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()); |
| 99 m_pDict->SetIntegerFor("Length", size); | 99 m_pDict->SetIntegerFor("Length", size); |
| 100 m_pDict->RemoveFor("Filter"); | 100 m_pDict->RemoveFor("Filter"); |
| 101 m_pDict->RemoveFor("DecodeParms"); | 101 m_pDict->RemoveFor("DecodeParms"); |
| 102 } | 102 } |
| 103 | 103 |
| 104 FX_BOOL CPDF_Stream::ReadRawData(FX_FILESIZE offset, | 104 bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, |
| 105 uint8_t* buf, | 105 uint8_t* buf, |
| 106 uint32_t size) const { | 106 uint32_t size) const { |
| 107 if (m_bMemoryBased && m_pFile) | 107 if (m_bMemoryBased && m_pFile) |
| 108 return m_pFile->ReadBlock(buf, offset, size); | 108 return m_pFile->ReadBlock(buf, offset, size); |
| 109 | 109 |
| 110 if (m_pDataBuf) | 110 if (m_pDataBuf) |
| 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 |