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

Side by Side Diff: fpdfsdk/src/fpdf_flatten.cpp

Issue 1089823004: Replace FX_NEW with new, remove tests from fpdfsdk (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebased Created 5 years, 8 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
« no previous file with comments | « fpdfsdk/src/fpdf_ext.cpp ('k') | fpdfsdk/src/fpdf_progressive.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "../include/fsdk_define.h" 7 #include "../include/fsdk_define.h"
8 #include "../include/fpdf_flatten.h" 8 #include "../include/fpdf_flatten.h"
9 9
10 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray; 10 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
(...skipping 22 matching lines...) Expand all
33 rect.bottom - rcPage.bottom < -10.000001f) 33 rect.bottom - rcPage.bottom < -10.000001f)
34 return FALSE; 34 return FALSE;
35 } 35 }
36 36
37 return TRUE; 37 return TRUE;
38 } 38 }
39 39
40 40
41 FX_BOOL GetContentsRect( CPDF_Document * pDoc, CPDF_Dictionary* pDict, CPDF_Rect Array * pRectArray ) 41 FX_BOOL GetContentsRect( CPDF_Document * pDoc, CPDF_Dictionary* pDict, CPDF_Rect Array * pRectArray )
42 { 42 {
43 » CPDF_Page* pPDFPage = FX_NEW CPDF_Page; 43 » CPDF_Page* pPDFPage = new CPDF_Page;
44 pPDFPage->Load( pDoc, pDict, FALSE ); 44 pPDFPage->Load( pDoc, pDict, FALSE );
45 pPDFPage->ParseContent(); 45 pPDFPage->ParseContent();
46 46
47 FX_POSITION pos = pPDFPage->GetFirstObjectPosition(); 47 FX_POSITION pos = pPDFPage->GetFirstObjectPosition();
48 48
49 while (pos) 49 while (pos)
50 { 50 {
51 CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos); 51 CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos);
52 if (!pPageObject)continue; 52 if (!pPageObject)continue;
53 53
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 if (!pContentsObj) 208 if (!pContentsObj)
209 { 209 {
210 pContentsObj = pPage->GetArray("Contents"); 210 pContentsObj = pPage->GetArray("Contents");
211 } 211 }
212 212
213 if (!pContentsObj) 213 if (!pContentsObj)
214 { 214 {
215 //Create a new contents dictionary 215 //Create a new contents dictionary
216 if (!key.IsEmpty()) 216 if (!key.IsEmpty())
217 { 217 {
218 » » » CPDF_Stream* pNewContents = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary); 218 » » » CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, FX_ NEW CPDF_Dictionary);
219 » » » if (!pNewContents)return;
220 pPage->SetAtReference("Contents", pDocument, pDocument-> AddIndirectObject(pNewContents)); 219 pPage->SetAtReference("Contents", pDocument, pDocument-> AddIndirectObject(pNewContents));
221 » » » 220
222 CFX_ByteString sStream; 221 CFX_ByteString sStream;
223 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()) ; 222 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()) ;
224 pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLe ngth(), FALSE, FALSE); 223 pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLe ngth(), FALSE, FALSE);
225 } 224 }
226 return; 225 return;
227 } 226 }
228 227
229 int iType = pContentsObj->GetType(); 228 int iType = pContentsObj->GetType();
230 CPDF_Array* pContentsArray = NULL; 229 CPDF_Array* pContentsArray = NULL;
231 230
232 switch(iType) 231 switch(iType)
233 { 232 {
234 case PDFOBJ_STREAM: 233 case PDFOBJ_STREAM:
235 { 234 {
236 » » » pContentsArray = FX_NEW CPDF_Array; 235 » » » pContentsArray = new CPDF_Array;
237 CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj; 236 CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj;
238 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pConten ts); 237 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pConten ts);
239 CPDF_StreamAcc acc; 238 CPDF_StreamAcc acc;
240 acc.LoadAllData(pContents); 239 acc.LoadAllData(pContents);
241 CFX_ByteString sStream = "q\n"; 240 CFX_ByteString sStream = "q\n";
242 CFX_ByteString sBody = CFX_ByteString((FX_LPCSTR)acc.Get Data(), acc.GetSize()); 241 CFX_ByteString sBody = CFX_ByteString((FX_LPCSTR)acc.Get Data(), acc.GetSize());
243 sStream = sStream + sBody + "\nQ"; 242 sStream = sStream + sBody + "\nQ";
244 pContents->SetData((FX_LPCBYTE)sStream, sStream.GetLengt h(), FALSE, FALSE); 243 pContents->SetData((FX_LPCBYTE)sStream, sStream.GetLengt h(), FALSE, FALSE);
245 pContentsArray->AddReference(pDocument, dwObjNum); 244 pContentsArray->AddReference(pDocument, dwObjNum);
246 break; 245 break;
247 } 246 }
248 247
249 case PDFOBJ_ARRAY: 248 case PDFOBJ_ARRAY:
250 { 249 {
251 pContentsArray = (CPDF_Array*)pContentsObj; 250 pContentsArray = (CPDF_Array*)pContentsObj;
252 break; 251 break;
253 } 252 }
254 default: 253 default:
255 break; 254 break;
256 } 255 }
257 256
258 if (!pContentsArray)return; 257 if (!pContentsArray)return;
259 258
260 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); 259 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray);
261 pPage->SetAtReference("Contents", pDocument, dwObjNum); 260 pPage->SetAtReference("Contents", pDocument, dwObjNum);
262 261
263 if (!key.IsEmpty()) 262 if (!key.IsEmpty())
264 { 263 {
265 » » CPDF_Stream* pNewContents = FX_NEW CPDF_Stream(NULL, 0, FX_NEW C PDF_Dictionary); 264 » » CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, FX_NEW CPDF _Dictionary);
266 dwObjNum = pDocument->AddIndirectObject(pNewContents); 265 dwObjNum = pDocument->AddIndirectObject(pNewContents);
267 pContentsArray->AddReference(pDocument, dwObjNum); 266 pContentsArray->AddReference(pDocument, dwObjNum);
268 267
269 CFX_ByteString sStream; 268 CFX_ByteString sStream;
270 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 269 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
271 pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE); 270 pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
272 } 271 }
273 } 272 }
274 273
275 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatr ix matrix) 274 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatr ix matrix)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 rcMerger.top = rcMerger.top > rcOriginalMB.top? rcOriginalMB.top : rcMer ger.top; 370 rcMerger.top = rcMerger.top > rcOriginalMB.top? rcOriginalMB.top : rcMer ger.top;
372 rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom? rcOriginalMB.bo ttom : rcMerger.bottom; 371 rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom? rcOriginalMB.bo ttom : rcMerger.bottom;
373 372
374 if (pPageDict->KeyExist("ArtBox")) 373 if (pPageDict->KeyExist("ArtBox"))
375 rcOriginalCB = pPageDict->GetRect("ArtBox"); 374 rcOriginalCB = pPageDict->GetRect("ArtBox");
376 else 375 else
377 rcOriginalCB = rcOriginalMB; 376 rcOriginalCB = rcOriginalMB;
378 377
379 if (!rcOriginalMB.IsEmpty()) 378 if (!rcOriginalMB.IsEmpty())
380 { 379 {
381 » » CPDF_Array* pMediaBox = FX_NEW CPDF_Array();» 380 » » CPDF_Array* pMediaBox = new CPDF_Array();
382 381 » » pMediaBox->Add(new CPDF_Number(rcOriginalMB.left));
383 » » pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.left)); 382 » » pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom));
384 » » pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.bottom)); 383 » » pMediaBox->Add(new CPDF_Number(rcOriginalMB.right));
385 » » pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.right)); 384 » » pMediaBox->Add(new CPDF_Number(rcOriginalMB.top));
386 » » pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.top));
387
388 pPageDict->SetAt("MediaBox",pMediaBox); 385 pPageDict->SetAt("MediaBox",pMediaBox);
389 } 386 }
390 » 387
391 if (!rcOriginalCB.IsEmpty()) 388 if (!rcOriginalCB.IsEmpty())
392 { 389 {
393 » » CPDF_Array* pCropBox = FX_NEW CPDF_Array(); 390 » » CPDF_Array* pCropBox = new CPDF_Array();
394 » » pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.left)); 391 » » pCropBox->Add(new CPDF_Number(rcOriginalCB.left));
395 » » pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.bottom)); 392 » » pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom));
396 » » pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.right)); 393 » » pCropBox->Add(new CPDF_Number(rcOriginalCB.right));
397 » » pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.top)); 394 » » pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
398 pPageDict->SetAt("ArtBox", pCropBox); 395 pPageDict->SetAt("ArtBox", pCropBox);
399 } 396 }
400 397
401 » CPDF_Dictionary* pRes = NULL; 398 » CPDF_Dictionary* pRes = pPageDict->GetDict("Resources");
402 » pRes = pPageDict->GetDict("Resources");
403 if (!pRes) 399 if (!pRes)
404 { 400 {
405 » » pRes = FX_NEW CPDF_Dictionary; 401 » » pRes = new CPDF_Dictionary;
406 » » pPageDict->SetAt( "Resources", pRes ); 402 » » pPageDict->SetAt("Resources", pRes);
407 } 403 }
408 404
409 » CPDF_Stream* pNewXObject = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dicti onary); 405 » CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictiona ry);
410 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject); 406 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
411 CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject"); 407 CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject");
412 if (!pPageXObject) 408 if (!pPageXObject)
413 { 409 {
414 » » pPageXObject = FX_NEW CPDF_Dictionary; 410 » » pPageXObject = new CPDF_Dictionary;
415 pRes->SetAt("XObject", pPageXObject); 411 pRes->SetAt("XObject", pPageXObject);
416 } 412 }
417 413
418 CFX_ByteString key = ""; 414 CFX_ByteString key = "";
419 int nStreams = ObjectArray.GetSize(); 415 int nStreams = ObjectArray.GetSize();
420 416
421 if (nStreams > 0) 417 if (nStreams > 0)
422 { 418 {
423 for (int iKey = 0; /*iKey < 100*/; iKey++) 419 for (int iKey = 0; /*iKey < 100*/; iKey++)
424 { 420 {
425 char sExtend[5] = {0}; 421 char sExtend[5] = {0};
426 FXSYS_itoa(iKey, sExtend, 10); 422 FXSYS_itoa(iKey, sExtend, 10);
427 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend); 423 key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
428 424
429 if (!pPageXObject->KeyExist(key)) 425 if (!pPageXObject->KeyExist(key))
430 break; 426 break;
431 } 427 }
432 } 428 }
433 429
434 SetPageContents(key, pPageDict, pDocument); 430 SetPageContents(key, pPageDict, pDocument);
435 431
436 CPDF_Dictionary* pNewXORes = NULL; 432 CPDF_Dictionary* pNewXORes = NULL;
437 433
438 if (!key.IsEmpty()) 434 if (!key.IsEmpty())
439 { 435 {
440 pPageXObject->SetAtReference(key, pDocument, dwObjNum); 436 pPageXObject->SetAtReference(key, pDocument, dwObjNum);
441 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); 437 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
442 » » pNewXORes = FX_NEW CPDF_Dictionary; 438 » » pNewXORes = new CPDF_Dictionary;
443 pNewOXbjectDic->SetAt("Resources", pNewXORes); 439 pNewOXbjectDic->SetAt("Resources", pNewXORes);
444 pNewOXbjectDic->SetAtName("Type", "XObject"); 440 pNewOXbjectDic->SetAtName("Type", "XObject");
445 pNewOXbjectDic->SetAtName("Subtype", "Form"); 441 pNewOXbjectDic->SetAtName("Subtype", "Form");
446 pNewOXbjectDic->SetAtInteger("FormType", 1); 442 pNewOXbjectDic->SetAtInteger("FormType", 1);
447 pNewOXbjectDic->SetAtName("Name", "FRM"); 443 pNewOXbjectDic->SetAtName("Name", "FRM");
448 » » CPDF_Rect rcBBox = pPageDict->GetRect("ArtBox"); 444 » » CPDF_Rect rcBBox = pPageDict->GetRect("ArtBox");
449 pNewOXbjectDic->SetAtRect("BBox", rcBBox); 445 pNewOXbjectDic->SetAtRect("BBox", rcBBox);
450 } 446 }
451 » 447
452 for (int i = 0; i < nStreams; i++) 448 for (int i = 0; i < nStreams; i++)
453 { 449 {
454 CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i); 450 CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i);
455 if (!pAnnotDic)continue; 451 if (!pAnnotDic)continue;
456 452
457 CPDF_Rect rcAnnot = pAnnotDic->GetRect("Rect"); 453 CPDF_Rect rcAnnot = pAnnotDic->GetRect("Rect");
458 rcAnnot.Normalize(); 454 rcAnnot.Normalize();
459 455
460 CFX_ByteString sAnnotState = pAnnotDic->GetString("AS"); 456 CFX_ByteString sAnnotState = pAnnotDic->GetString("AS");
461 CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDict("AP"); 457 CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDict("AP");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 if (pObjDic) 509 if (pObjDic)
514 { 510 {
515 pObjDic->SetAtName("Type", "XObject"); 511 pObjDic->SetAtName("Type", "XObject");
516 pObjDic->SetAtName("Subtype", "Form"); 512 pObjDic->SetAtName("Subtype", "Form");
517 } 513 }
518 } 514 }
519 515
520 CPDF_Dictionary* pXObject = pNewXORes->GetDict("XObject"); 516 CPDF_Dictionary* pXObject = pNewXORes->GetDict("XObject");
521 if (!pXObject) 517 if (!pXObject)
522 { 518 {
523 » » » pXObject = FX_NEW CPDF_Dictionary; 519 » » » pXObject = new CPDF_Dictionary;
524 pNewXORes->SetAt("XObject", pXObject); 520 pNewXORes->SetAt("XObject", pXObject);
525 } 521 }
526 522
527 CFX_ByteString sFormName; 523 CFX_ByteString sFormName;
528 sFormName.Format("F%d", i); 524 sFormName.Format("F%d", i);
529 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj); 525 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj);
530 pXObject->SetAtReference(sFormName, pDocument, dwObjNum); 526 pXObject->SetAtReference(sFormName, pDocument, dwObjNum);
531 527
532 CPDF_StreamAcc acc; 528 CPDF_StreamAcc acc;
533 acc.LoadAllData(pNewXObject); 529 acc.LoadAllData(pNewXObject);
(...skipping 18 matching lines...) Expand all
552 548
553 pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), F ALSE, FALSE); 549 pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), F ALSE, FALSE);
554 } 550 }
555 pPageDict->RemoveAt( "Annots" ); 551 pPageDict->RemoveAt( "Annots" );
556 552
557 ObjectArray.RemoveAll(); 553 ObjectArray.RemoveAll();
558 RectArray.RemoveAll(); 554 RectArray.RemoveAll();
559 555
560 return FLATTEN_SUCCESS; 556 return FLATTEN_SUCCESS;
561 } 557 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdf_ext.cpp ('k') | fpdfsdk/src/fpdf_progressive.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698