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

Side by Side Diff: fpdfsdk/fpdf_flatten.cpp

Issue 2347993002: Clean up CPDF_Stream. (Closed)
Patch Set: ctor Created 4 years, 3 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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "public/fpdf_flatten.h" 7 #include "public/fpdf_flatten.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (!pContentsObj) { 193 if (!pContentsObj) {
194 // Create a new contents dictionary 194 // Create a new contents dictionary
195 if (!key.IsEmpty()) { 195 if (!key.IsEmpty()) {
196 CPDF_Stream* pNewContents = 196 CPDF_Stream* pNewContents =
197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 197 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary);
198 pPage->SetReferenceFor("Contents", pDocument, 198 pPage->SetReferenceFor("Contents", pDocument,
199 pDocument->AddIndirectObject(pNewContents)); 199 pDocument->AddIndirectObject(pNewContents));
200 200
201 CFX_ByteString sStream; 201 CFX_ByteString sStream;
202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 202 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, 203 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
204 FALSE);
205 } 204 }
206 return; 205 return;
207 } 206 }
208 207
209 CPDF_Array* pContentsArray = nullptr; 208 CPDF_Array* pContentsArray = nullptr;
210 209
211 switch (pContentsObj->GetType()) { 210 switch (pContentsObj->GetType()) {
212 case CPDF_Object::STREAM: { 211 case CPDF_Object::STREAM: {
213 pContentsArray = new CPDF_Array; 212 pContentsArray = new CPDF_Array;
214 CPDF_Stream* pContents = pContentsObj->AsStream(); 213 CPDF_Stream* pContents = pContentsObj->AsStream();
215 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents); 214 uint32_t dwObjNum = pDocument->AddIndirectObject(pContents);
216 CPDF_StreamAcc acc; 215 CPDF_StreamAcc acc;
217 acc.LoadAllData(pContents); 216 acc.LoadAllData(pContents);
218 CFX_ByteString sStream = "q\n"; 217 CFX_ByteString sStream = "q\n";
219 CFX_ByteString sBody = 218 CFX_ByteString sBody =
220 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); 219 CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
221 sStream = sStream + sBody + "\nQ"; 220 sStream = sStream + sBody + "\nQ";
222 pContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); 221 pContents->SetData(sStream.raw_str(), sStream.GetLength());
223 pContentsArray->AddReference(pDocument, dwObjNum); 222 pContentsArray->AddReference(pDocument, dwObjNum);
224 break; 223 break;
225 } 224 }
226 225
227 case CPDF_Object::ARRAY: { 226 case CPDF_Object::ARRAY: {
228 pContentsArray = pContentsObj->AsArray(); 227 pContentsArray = pContentsObj->AsArray();
229 break; 228 break;
230 } 229 }
231 default: 230 default:
232 break; 231 break;
233 } 232 }
234 233
235 if (!pContentsArray) 234 if (!pContentsArray)
236 return; 235 return;
237 236
238 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray); 237 uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray);
239 pPage->SetReferenceFor("Contents", pDocument, dwObjNum); 238 pPage->SetReferenceFor("Contents", pDocument, dwObjNum);
240 239
241 if (!key.IsEmpty()) { 240 if (!key.IsEmpty()) {
242 CPDF_Stream* pNewContents = 241 CPDF_Stream* pNewContents =
243 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary); 242 new CPDF_Stream(nullptr, 0, new CPDF_Dictionary);
244 dwObjNum = pDocument->AddIndirectObject(pNewContents); 243 dwObjNum = pDocument->AddIndirectObject(pNewContents);
245 pContentsArray->AddReference(pDocument, dwObjNum); 244 pContentsArray->AddReference(pDocument, dwObjNum);
246 245
247 CFX_ByteString sStream; 246 CFX_ByteString sStream;
248 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 247 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
249 pNewContents->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); 248 pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
250 } 249 }
251 } 250 }
252 251
253 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot, 252 CFX_Matrix GetMatrix(CFX_FloatRect rcAnnot,
254 CFX_FloatRect rcStream, 253 CFX_FloatRect rcStream,
255 const CFX_Matrix& matrix) { 254 const CFX_Matrix& matrix) {
256 if (rcStream.IsEmpty()) 255 if (rcStream.IsEmpty())
257 return CFX_Matrix(); 256 return CFX_Matrix();
258 257
259 matrix.TransformRect(rcStream); 258 matrix.TransformRect(rcStream);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 matrix.c = 0.0f; 498 matrix.c = 0.0f;
500 matrix.d = 1.0f; 499 matrix.d = 1.0f;
501 matrix.e = 0.0f; 500 matrix.e = 0.0f;
502 matrix.f = 0.0f; 501 matrix.f = 0.0f;
503 } 502 }
504 503
505 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); 504 CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
506 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, 505 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
507 sFormName.c_str()); 506 sFormName.c_str());
508 sStream += sTemp; 507 sStream += sTemp;
509 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength(), FALSE, FALSE); 508 pNewXObject->SetData(sStream.raw_str(), sStream.GetLength());
510 } 509 }
511 pPageDict->RemoveFor("Annots"); 510 pPageDict->RemoveFor("Annots");
512 511
513 ObjectArray.RemoveAll(); 512 ObjectArray.RemoveAll();
514 RectArray.RemoveAll(); 513 RectArray.RemoveAll();
515 514
516 return FLATTEN_SUCCESS; 515 return FLATTEN_SUCCESS;
517 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698