| 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_number.h" |
| 10 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 11 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
| 11 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 12 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 12 #include "third_party/base/numerics/safe_conversions.h" | 13 #include "third_party/base/numerics/safe_conversions.h" |
| 13 #include "third_party/base/stl_util.h" | 14 #include "third_party/base/stl_util.h" |
| 14 | 15 |
| 15 CPDF_Stream::CPDF_Stream() {} | 16 CPDF_Stream::CPDF_Stream() {} |
| 16 | 17 |
| 17 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) | 18 CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict) |
| 18 : m_dwSize(size), m_pDict(pDict), m_pDataBuf(pData) {} | 19 : m_dwSize(size), m_pDict(pDict), m_pDataBuf(pData) {} |
| 19 | 20 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 47 uint32_t size, | 48 uint32_t size, |
| 48 CPDF_Dictionary* pDict) { | 49 CPDF_Dictionary* pDict) { |
| 49 m_pDict.reset(pDict); | 50 m_pDict.reset(pDict); |
| 50 m_bMemoryBased = true; | 51 m_bMemoryBased = true; |
| 51 m_pFile = nullptr; | 52 m_pFile = nullptr; |
| 52 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); | 53 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); |
| 53 if (pData) | 54 if (pData) |
| 54 FXSYS_memcpy(m_pDataBuf.get(), pData, size); | 55 FXSYS_memcpy(m_pDataBuf.get(), pData, size); |
| 55 m_dwSize = size; | 56 m_dwSize = size; |
| 56 if (m_pDict) | 57 if (m_pDict) |
| 57 m_pDict->SetIntegerFor("Length", m_dwSize); | 58 m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize)); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void CPDF_Stream::InitStreamFromFile(IFX_SeekableReadStream* pFile, | 61 void CPDF_Stream::InitStreamFromFile(IFX_SeekableReadStream* pFile, |
| 61 CPDF_Dictionary* pDict) { | 62 CPDF_Dictionary* pDict) { |
| 62 m_pDict.reset(pDict); | 63 m_pDict.reset(pDict); |
| 63 m_bMemoryBased = false; | 64 m_bMemoryBased = false; |
| 64 m_pDataBuf.reset(); | 65 m_pDataBuf.reset(); |
| 65 m_pFile = pFile; | 66 m_pFile = pFile; |
| 66 m_dwSize = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); | 67 m_dwSize = pdfium::base::checked_cast<uint32_t>(pFile->GetSize()); |
| 67 if (m_pDict) | 68 if (m_pDict) |
| 68 m_pDict->SetIntegerFor("Length", m_dwSize); | 69 m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 std::unique_ptr<CPDF_Object> CPDF_Stream::Clone() const { | 72 std::unique_ptr<CPDF_Object> CPDF_Stream::Clone() const { |
| 72 return CloneObjectNonCyclic(false); | 73 return CloneObjectNonCyclic(false); |
| 73 } | 74 } |
| 74 | 75 |
| 75 std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic( | 76 std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic( |
| 76 bool bDirect, | 77 bool bDirect, |
| 77 std::set<const CPDF_Object*>* pVisited) const { | 78 std::set<const CPDF_Object*>* pVisited) const { |
| 78 pVisited->insert(this); | 79 pVisited->insert(this); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 89 } | 90 } |
| 90 | 91 |
| 91 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { | 92 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { |
| 92 m_bMemoryBased = true; | 93 m_bMemoryBased = true; |
| 93 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); | 94 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); |
| 94 if (pData) | 95 if (pData) |
| 95 FXSYS_memcpy(m_pDataBuf.get(), pData, size); | 96 FXSYS_memcpy(m_pDataBuf.get(), pData, size); |
| 96 m_dwSize = size; | 97 m_dwSize = size; |
| 97 if (!m_pDict) | 98 if (!m_pDict) |
| 98 m_pDict.reset(new CPDF_Dictionary()); | 99 m_pDict.reset(new CPDF_Dictionary()); |
| 99 m_pDict->SetIntegerFor("Length", size); | 100 m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size)); |
| 100 m_pDict->RemoveFor("Filter"); | 101 m_pDict->RemoveFor("Filter"); |
| 101 m_pDict->RemoveFor("DecodeParms"); | 102 m_pDict->RemoveFor("DecodeParms"); |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, | 105 bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, |
| 105 uint8_t* buf, | 106 uint8_t* buf, |
| 106 uint32_t size) const { | 107 uint32_t size) const { |
| 107 if (m_bMemoryBased && m_pFile) | 108 if (m_bMemoryBased && m_pFile) |
| 108 return m_pFile->ReadBlock(buf, offset, size); | 109 return m_pFile->ReadBlock(buf, offset, size); |
| 109 | 110 |
| 110 if (m_pDataBuf) | 111 if (m_pDataBuf) |
| 111 FXSYS_memcpy(buf, m_pDataBuf.get() + offset, size); | 112 FXSYS_memcpy(buf, m_pDataBuf.get() + offset, size); |
| 112 | 113 |
| 113 return true; | 114 return true; |
| 114 } | 115 } |
| 115 | 116 |
| 116 CFX_WideString CPDF_Stream::GetUnicodeText() const { | 117 CFX_WideString CPDF_Stream::GetUnicodeText() const { |
| 117 CPDF_StreamAcc stream; | 118 CPDF_StreamAcc stream; |
| 118 stream.LoadAllData(this, false); | 119 stream.LoadAllData(this, false); |
| 119 return PDF_DecodeText(stream.GetData(), stream.GetSize()); | 120 return PDF_DecodeText(stream.GetData(), stream.GetSize()); |
| 120 } | 121 } |
| OLD | NEW |