Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: core/src/fpdfapi/fpdf_parser/cpdf_stream.cpp

Issue 1783933003: Split CPDF_Stream/CPDF_StreamAcc into separate files (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/include/fpdfapi/cpdf_stream.h" 7 #include "core/include/fpdfapi/cpdf_stream.h"
8 8
9 #include "core/include/fpdfapi/cpdf_dictionary.h" 9 #include "core/include/fpdfapi/cpdf_dictionary.h"
10 #include "core/include/fpdfapi/cpdf_stream_acc.h"
10 #include "core/include/fpdfapi/fpdf_parser_decode.h" 11 #include "core/include/fpdfapi/fpdf_parser_decode.h"
11 12
12 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict) 13 CPDF_Stream::CPDF_Stream(uint8_t* pData, FX_DWORD size, CPDF_Dictionary* pDict)
13 : m_pDict(pDict), 14 : m_pDict(pDict),
14 m_dwSize(size), 15 m_dwSize(size),
15 m_GenNum(kMemoryBasedGenNum), 16 m_GenNum(kMemoryBasedGenNum),
16 m_pDataBuf(pData) {} 17 m_pDataBuf(pData) {}
17 18
18 CPDF_Stream::~CPDF_Stream() { 19 CPDF_Stream::~CPDF_Stream() {
19 if (IsMemoryBased()) 20 if (IsMemoryBased())
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 if (m_pDict) 128 if (m_pDict)
128 m_pDict->SetAtInteger("Length", m_dwSize); 129 m_pDict->SetAtInteger("Length", m_dwSize);
129 } 130 }
130 131
131 CFX_WideString CPDF_Stream::GetUnicodeText() const { 132 CFX_WideString CPDF_Stream::GetUnicodeText() const {
132 CPDF_StreamAcc stream; 133 CPDF_StreamAcc stream;
133 stream.LoadAllData(this, FALSE); 134 stream.LoadAllData(this, FALSE);
134 return PDF_DecodeText(stream.GetData(), stream.GetSize()); 135 return PDF_DecodeText(stream.GetData(), stream.GetSize());
135 } 136 }
136 137
137 CPDF_StreamAcc::CPDF_StreamAcc()
138 : m_pData(nullptr),
139 m_dwSize(0),
140 m_bNewBuf(FALSE),
141 m_pImageParam(nullptr),
142 m_pStream(nullptr),
143 m_pSrcData(nullptr) {}
144
145 void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream,
146 FX_BOOL bRawAccess,
147 FX_DWORD estimated_size,
148 FX_BOOL bImageAcc) {
149 if (!pStream)
150 return;
151
152 m_pStream = pStream;
153 if (pStream->IsMemoryBased() &&
154 (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) {
155 m_dwSize = pStream->GetRawSize();
156 m_pData = pStream->GetRawData();
157 return;
158 }
159 uint8_t* pSrcData;
160 FX_DWORD dwSrcSize = pStream->GetRawSize();
161 if (dwSrcSize == 0)
162 return;
163
164 if (!pStream->IsMemoryBased()) {
165 pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
166 if (!pStream->ReadRawData(0, pSrcData, dwSrcSize))
167 return;
168 } else {
169 pSrcData = pStream->GetRawData();
170 }
171 uint8_t* pDecryptedData = pSrcData;
172 FX_DWORD dwDecryptedSize = dwSrcSize;
173 if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) {
174 m_pData = pDecryptedData;
175 m_dwSize = dwDecryptedSize;
176 } else {
177 FX_BOOL bRet = PDF_DataDecode(
178 pDecryptedData, dwDecryptedSize, m_pStream->GetDict(), m_pData,
179 m_dwSize, m_ImageDecoder, m_pImageParam, estimated_size, bImageAcc);
180 if (!bRet) {
181 m_pData = pDecryptedData;
182 m_dwSize = dwDecryptedSize;
183 }
184 }
185 if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) {
186 FX_Free(pSrcData);
187 }
188 if (pDecryptedData != pSrcData && pDecryptedData != m_pData) {
189 FX_Free(pDecryptedData);
190 }
191 m_pSrcData = nullptr;
192 m_bNewBuf = m_pData != pStream->GetRawData();
193 }
194
195 CPDF_StreamAcc::~CPDF_StreamAcc() {
196 if (m_bNewBuf) {
197 FX_Free(m_pData);
198 }
199 FX_Free(m_pSrcData);
200 }
201
202 const uint8_t* CPDF_StreamAcc::GetData() const {
203 if (m_bNewBuf) {
204 return m_pData;
205 }
206 if (!m_pStream) {
207 return nullptr;
208 }
209 return m_pStream->GetRawData();
210 }
211
212 FX_DWORD CPDF_StreamAcc::GetSize() const {
213 if (m_bNewBuf) {
214 return m_dwSize;
215 }
216 if (!m_pStream) {
217 return 0;
218 }
219 return m_pStream->GetRawSize();
220 }
221
222 uint8_t* CPDF_StreamAcc::DetachData() {
223 if (m_bNewBuf) {
224 uint8_t* p = m_pData;
225 m_pData = nullptr;
226 m_dwSize = 0;
227 return p;
228 }
229 uint8_t* p = FX_Alloc(uint8_t, m_dwSize);
230 FXSYS_memcpy(p, m_pData, m_dwSize);
231 return p;
232 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/cpdf_parser.cpp ('k') | core/src/fpdfapi/fpdf_parser/cpdf_stream_acc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698