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/stl_util.h" | 17 #include "third_party/base/stl_util.h" |
17 | 18 |
18 CPDF_Stream::CPDF_Stream() {} | 19 CPDF_Stream::CPDF_Stream() {} |
19 | 20 |
20 CPDF_Stream::CPDF_Stream(uint8_t* pData, | 21 CPDF_Stream::CPDF_Stream(uint8_t* pData, |
21 uint32_t size, | 22 uint32_t size, |
22 std::unique_ptr<CPDF_Dictionary> pDict) | 23 std::unique_ptr<CPDF_Dictionary> pDict) |
23 : m_dwSize(size), m_pDict(std::move(pDict)), m_pDataBuf(pData) {} | 24 : m_dwSize(size), m_pDict(std::move(pDict)), m_pDataBuf(pData) {} |
24 | 25 |
25 CPDF_Stream::~CPDF_Stream() { | 26 CPDF_Stream::~CPDF_Stream() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 std::move(pNewDict)); | 97 std::move(pNewDict)); |
97 } | 98 } |
98 | 99 |
99 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { | 100 void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) { |
100 m_bMemoryBased = true; | 101 m_bMemoryBased = true; |
101 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); | 102 m_pDataBuf.reset(FX_Alloc(uint8_t, size)); |
102 if (pData) | 103 if (pData) |
103 FXSYS_memcpy(m_pDataBuf.get(), pData, size); | 104 FXSYS_memcpy(m_pDataBuf.get(), pData, size); |
104 m_dwSize = size; | 105 m_dwSize = size; |
105 if (!m_pDict) | 106 if (!m_pDict) |
106 m_pDict.reset(new CPDF_Dictionary()); | 107 m_pDict = pdfium::MakeUnique<CPDF_Dictionary>(); |
107 m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size)); | 108 m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size)); |
108 m_pDict->RemoveFor("Filter"); | 109 m_pDict->RemoveFor("Filter"); |
109 m_pDict->RemoveFor("DecodeParms"); | 110 m_pDict->RemoveFor("DecodeParms"); |
110 } | 111 } |
111 | 112 |
112 bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, | 113 bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, |
113 uint8_t* buf, | 114 uint8_t* buf, |
114 uint32_t size) const { | 115 uint32_t size) const { |
115 if (m_bMemoryBased && m_pFile) | 116 if (m_bMemoryBased && m_pFile) |
116 return m_pFile->ReadBlock(buf, offset, size); | 117 return m_pFile->ReadBlock(buf, offset, size); |
117 | 118 |
118 if (m_pDataBuf) | 119 if (m_pDataBuf) |
119 FXSYS_memcpy(buf, m_pDataBuf.get() + offset, size); | 120 FXSYS_memcpy(buf, m_pDataBuf.get() + offset, size); |
120 | 121 |
121 return true; | 122 return true; |
122 } | 123 } |
123 | 124 |
124 bool CPDF_Stream::HasFilter() const { | 125 bool CPDF_Stream::HasFilter() const { |
125 return m_pDict && m_pDict->KeyExist("Filter"); | 126 return m_pDict && m_pDict->KeyExist("Filter"); |
126 } | 127 } |
127 | 128 |
128 CFX_WideString CPDF_Stream::GetUnicodeText() const { | 129 CFX_WideString CPDF_Stream::GetUnicodeText() const { |
129 CPDF_StreamAcc stream; | 130 CPDF_StreamAcc stream; |
130 stream.LoadAllData(this, false); | 131 stream.LoadAllData(this, false); |
131 return PDF_DecodeText(stream.GetData(), stream.GetSize()); | 132 return PDF_DecodeText(stream.GetData(), stream.GetSize()); |
132 } | 133 } |
OLD | NEW |