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

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

Issue 1644633003: Member function name refactoring (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 10 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_transformpage.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 "public/fpdf_flatten.h" 7 #include "public/fpdf_flatten.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos); 47 CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos);
48 if (!pPageObject) 48 if (!pPageObject)
49 continue; 49 continue;
50 50
51 CPDF_Rect rc; 51 CPDF_Rect rc;
52 rc.left = pPageObject->m_Left; 52 rc.left = pPageObject->m_Left;
53 rc.right = pPageObject->m_Right; 53 rc.right = pPageObject->m_Right;
54 rc.bottom = pPageObject->m_Bottom; 54 rc.bottom = pPageObject->m_Bottom;
55 rc.top = pPageObject->m_Top; 55 rc.top = pPageObject->m_Top;
56 56
57 if (IsValiableRect(rc, pDict->GetRect("MediaBox"))) { 57 if (IsValiableRect(rc, pDict->GetRectBy("MediaBox"))) {
58 pRectArray->Add(rc); 58 pRectArray->Add(rc);
59 } 59 }
60 } 60 }
61 61
62 delete pPDFPage; 62 delete pPDFPage;
63 return TRUE; 63 return TRUE;
64 } 64 }
65 65
66 void ParserStream(CPDF_Dictionary* pPageDic, 66 void ParserStream(CPDF_Dictionary* pPageDic,
67 CPDF_Dictionary* pStream, 67 CPDF_Dictionary* pStream,
68 CPDF_RectArray* pRectArray, 68 CPDF_RectArray* pRectArray,
69 CPDF_ObjectArray* pObjectArray) { 69 CPDF_ObjectArray* pObjectArray) {
70 if (!pStream) 70 if (!pStream)
71 return; 71 return;
72 CPDF_Rect rect; 72 CPDF_Rect rect;
73 if (pStream->KeyExist("Rect")) 73 if (pStream->KeyExist("Rect"))
74 rect = pStream->GetRect("Rect"); 74 rect = pStream->GetRectBy("Rect");
75 else if (pStream->KeyExist("BBox")) 75 else if (pStream->KeyExist("BBox"))
76 rect = pStream->GetRect("BBox"); 76 rect = pStream->GetRectBy("BBox");
77 77
78 if (IsValiableRect(rect, pPageDic->GetRect("MediaBox"))) 78 if (IsValiableRect(rect, pPageDic->GetRectBy("MediaBox")))
79 pRectArray->Add(rect); 79 pRectArray->Add(rect);
80 80
81 pObjectArray->Add(pStream); 81 pObjectArray->Add(pStream);
82 } 82 }
83 83
84 int ParserAnnots(CPDF_Document* pSourceDoc, 84 int ParserAnnots(CPDF_Document* pSourceDoc,
85 CPDF_Dictionary* pPageDic, 85 CPDF_Dictionary* pPageDic,
86 CPDF_RectArray* pRectArray, 86 CPDF_RectArray* pRectArray,
87 CPDF_ObjectArray* pObjectArray, 87 CPDF_ObjectArray* pObjectArray,
88 int nUsage) { 88 int nUsage) {
89 if (!pSourceDoc || !pPageDic) 89 if (!pSourceDoc || !pPageDic)
90 return FLATTEN_FAIL; 90 return FLATTEN_FAIL;
91 91
92 GetContentsRect(pSourceDoc, pPageDic, pRectArray); 92 GetContentsRect(pSourceDoc, pPageDic, pRectArray);
93 CPDF_Array* pAnnots = pPageDic->GetArray("Annots"); 93 CPDF_Array* pAnnots = pPageDic->GetArrayBy("Annots");
94 if (!pAnnots) 94 if (!pAnnots)
95 return FLATTEN_NOTHINGTODO; 95 return FLATTEN_NOTHINGTODO;
96 96
97 FX_DWORD dwSize = pAnnots->GetCount(); 97 FX_DWORD dwSize = pAnnots->GetCount();
98 for (int i = 0; i < (int)dwSize; i++) { 98 for (int i = 0; i < (int)dwSize; i++) {
99 CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetElementValue(i)); 99 CPDF_Dictionary* pAnnotDic = ToDictionary(pAnnots->GetElementValue(i));
100 if (!pAnnotDic) 100 if (!pAnnotDic)
101 continue; 101 continue;
102 102
103 CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype"); 103 CFX_ByteString sSubtype = pAnnotDic->GetStringBy("Subtype");
104 if (sSubtype == "Popup") 104 if (sSubtype == "Popup")
105 continue; 105 continue;
106 106
107 int nAnnotFlag = pAnnotDic->GetInteger("F"); 107 int nAnnotFlag = pAnnotDic->GetIntegerBy("F");
108 if (nAnnotFlag & ANNOTFLAG_HIDDEN) 108 if (nAnnotFlag & ANNOTFLAG_HIDDEN)
109 continue; 109 continue;
110 110
111 if (nUsage == FLAT_NORMALDISPLAY) { 111 if (nUsage == FLAT_NORMALDISPLAY) {
112 if (nAnnotFlag & ANNOTFLAG_INVISIBLE) 112 if (nAnnotFlag & ANNOTFLAG_INVISIBLE)
113 continue; 113 continue;
114 114
115 ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray); 115 ParserStream(pPageDic, pAnnotDic, pRectArray, pObjectArray);
116 } else { 116 } else {
117 if (nAnnotFlag & ANNOTFLAG_PRINT) 117 if (nAnnotFlag & ANNOTFLAG_PRINT)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP); 180 rcRet.top = GetMinMaxValue(*pRectArray, MAX, TOP);
181 rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT); 181 rcRet.right = GetMinMaxValue(*pRectArray, MAX, RIGHT);
182 rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM); 182 rcRet.bottom = GetMinMaxValue(*pRectArray, MIN, BOTTOM);
183 183
184 return rcRet; 184 return rcRet;
185 } 185 }
186 186
187 void SetPageContents(CFX_ByteString key, 187 void SetPageContents(CFX_ByteString key,
188 CPDF_Dictionary* pPage, 188 CPDF_Dictionary* pPage,
189 CPDF_Document* pDocument) { 189 CPDF_Document* pDocument) {
190 CPDF_Object* pContentsObj = pPage->GetStream("Contents"); 190 CPDF_Object* pContentsObj = pPage->GetStreamBy("Contents");
191 if (!pContentsObj) { 191 if (!pContentsObj) {
192 pContentsObj = pPage->GetArray("Contents"); 192 pContentsObj = pPage->GetArrayBy("Contents");
193 } 193 }
194 194
195 if (!pContentsObj) { 195 if (!pContentsObj) {
196 // Create a new contents dictionary 196 // Create a new contents dictionary
197 if (!key.IsEmpty()) { 197 if (!key.IsEmpty()) {
198 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); 198 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary);
199 pPage->SetAtReference("Contents", pDocument, 199 pPage->SetAtReference("Contents", pDocument,
200 pDocument->AddIndirectObject(pNewContents)); 200 pDocument->AddIndirectObject(pNewContents));
201 201
202 CFX_ByteString sStream; 202 CFX_ByteString sStream;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 CPDF_ObjectArray ObjectArray; 325 CPDF_ObjectArray ObjectArray;
326 CPDF_RectArray RectArray; 326 CPDF_RectArray RectArray;
327 327
328 int iRet = FLATTEN_FAIL; 328 int iRet = FLATTEN_FAIL;
329 iRet = ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag); 329 iRet = ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
330 if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) 330 if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL)
331 return iRet; 331 return iRet;
332 332
333 CPDF_Rect rcOriginalCB; 333 CPDF_Rect rcOriginalCB;
334 CPDF_Rect rcMerger = CalculateRect(&RectArray); 334 CPDF_Rect rcMerger = CalculateRect(&RectArray);
335 CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox"); 335 CPDF_Rect rcOriginalMB = pPageDict->GetRectBy("MediaBox");
336 336
337 if (pPageDict->KeyExist("CropBox")) 337 if (pPageDict->KeyExist("CropBox"))
338 rcOriginalMB = pPageDict->GetRect("CropBox"); 338 rcOriginalMB = pPageDict->GetRectBy("CropBox");
339 339
340 if (rcOriginalMB.IsEmpty()) { 340 if (rcOriginalMB.IsEmpty()) {
341 rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f); 341 rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f);
342 } 342 }
343 343
344 rcMerger.left = 344 rcMerger.left =
345 rcMerger.left < rcOriginalMB.left ? rcOriginalMB.left : rcMerger.left; 345 rcMerger.left < rcOriginalMB.left ? rcOriginalMB.left : rcMerger.left;
346 rcMerger.right = 346 rcMerger.right =
347 rcMerger.right > rcOriginalMB.right ? rcOriginalMB.right : rcMerger.right; 347 rcMerger.right > rcOriginalMB.right ? rcOriginalMB.right : rcMerger.right;
348 rcMerger.top = 348 rcMerger.top =
349 rcMerger.top > rcOriginalMB.top ? rcOriginalMB.top : rcMerger.top; 349 rcMerger.top > rcOriginalMB.top ? rcOriginalMB.top : rcMerger.top;
350 rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom ? rcOriginalMB.bottom 350 rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom ? rcOriginalMB.bottom
351 : rcMerger.bottom; 351 : rcMerger.bottom;
352 352
353 if (pPageDict->KeyExist("ArtBox")) 353 if (pPageDict->KeyExist("ArtBox"))
354 rcOriginalCB = pPageDict->GetRect("ArtBox"); 354 rcOriginalCB = pPageDict->GetRectBy("ArtBox");
355 else 355 else
356 rcOriginalCB = rcOriginalMB; 356 rcOriginalCB = rcOriginalMB;
357 357
358 if (!rcOriginalMB.IsEmpty()) { 358 if (!rcOriginalMB.IsEmpty()) {
359 CPDF_Array* pMediaBox = new CPDF_Array(); 359 CPDF_Array* pMediaBox = new CPDF_Array();
360 pMediaBox->Add(new CPDF_Number(rcOriginalMB.left)); 360 pMediaBox->Add(new CPDF_Number(rcOriginalMB.left));
361 pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom)); 361 pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom));
362 pMediaBox->Add(new CPDF_Number(rcOriginalMB.right)); 362 pMediaBox->Add(new CPDF_Number(rcOriginalMB.right));
363 pMediaBox->Add(new CPDF_Number(rcOriginalMB.top)); 363 pMediaBox->Add(new CPDF_Number(rcOriginalMB.top));
364 pPageDict->SetAt("MediaBox", pMediaBox); 364 pPageDict->SetAt("MediaBox", pMediaBox);
365 } 365 }
366 366
367 if (!rcOriginalCB.IsEmpty()) { 367 if (!rcOriginalCB.IsEmpty()) {
368 CPDF_Array* pCropBox = new CPDF_Array(); 368 CPDF_Array* pCropBox = new CPDF_Array();
369 pCropBox->Add(new CPDF_Number(rcOriginalCB.left)); 369 pCropBox->Add(new CPDF_Number(rcOriginalCB.left));
370 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom)); 370 pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom));
371 pCropBox->Add(new CPDF_Number(rcOriginalCB.right)); 371 pCropBox->Add(new CPDF_Number(rcOriginalCB.right));
372 pCropBox->Add(new CPDF_Number(rcOriginalCB.top)); 372 pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
373 pPageDict->SetAt("ArtBox", pCropBox); 373 pPageDict->SetAt("ArtBox", pCropBox);
374 } 374 }
375 375
376 CPDF_Dictionary* pRes = pPageDict->GetDict("Resources"); 376 CPDF_Dictionary* pRes = pPageDict->GetDictBy("Resources");
377 if (!pRes) { 377 if (!pRes) {
378 pRes = new CPDF_Dictionary; 378 pRes = new CPDF_Dictionary;
379 pPageDict->SetAt("Resources", pRes); 379 pPageDict->SetAt("Resources", pRes);
380 } 380 }
381 381
382 CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); 382 CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary);
383 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject); 383 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
384 CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject"); 384 CPDF_Dictionary* pPageXObject = pRes->GetDictBy("XObject");
385 if (!pPageXObject) { 385 if (!pPageXObject) {
386 pPageXObject = new CPDF_Dictionary; 386 pPageXObject = new CPDF_Dictionary;
387 pRes->SetAt("XObject", pPageXObject); 387 pRes->SetAt("XObject", pPageXObject);
388 } 388 }
389 389
390 CFX_ByteString key = ""; 390 CFX_ByteString key = "";
391 int nStreams = ObjectArray.GetSize(); 391 int nStreams = ObjectArray.GetSize();
392 392
393 if (nStreams > 0) { 393 if (nStreams > 0) {
394 for (int iKey = 0; /*iKey < 100*/; iKey++) { 394 for (int iKey = 0; /*iKey < 100*/; iKey++) {
(...skipping 12 matching lines...) Expand all
407 407
408 if (!key.IsEmpty()) { 408 if (!key.IsEmpty()) {
409 pPageXObject->SetAtReference(key, pDocument, dwObjNum); 409 pPageXObject->SetAtReference(key, pDocument, dwObjNum);
410 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict(); 410 CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
411 pNewXORes = new CPDF_Dictionary; 411 pNewXORes = new CPDF_Dictionary;
412 pNewOXbjectDic->SetAt("Resources", pNewXORes); 412 pNewOXbjectDic->SetAt("Resources", pNewXORes);
413 pNewOXbjectDic->SetAtName("Type", "XObject"); 413 pNewOXbjectDic->SetAtName("Type", "XObject");
414 pNewOXbjectDic->SetAtName("Subtype", "Form"); 414 pNewOXbjectDic->SetAtName("Subtype", "Form");
415 pNewOXbjectDic->SetAtInteger("FormType", 1); 415 pNewOXbjectDic->SetAtInteger("FormType", 1);
416 pNewOXbjectDic->SetAtName("Name", "FRM"); 416 pNewOXbjectDic->SetAtName("Name", "FRM");
417 CPDF_Rect rcBBox = pPageDict->GetRect("ArtBox"); 417 CPDF_Rect rcBBox = pPageDict->GetRectBy("ArtBox");
418 pNewOXbjectDic->SetAtRect("BBox", rcBBox); 418 pNewOXbjectDic->SetAtRect("BBox", rcBBox);
419 } 419 }
420 420
421 for (int i = 0; i < nStreams; i++) { 421 for (int i = 0; i < nStreams; i++) {
422 CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i); 422 CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i);
423 if (!pAnnotDic) 423 if (!pAnnotDic)
424 continue; 424 continue;
425 425
426 CPDF_Rect rcAnnot = pAnnotDic->GetRect("Rect"); 426 CPDF_Rect rcAnnot = pAnnotDic->GetRectBy("Rect");
427 rcAnnot.Normalize(); 427 rcAnnot.Normalize();
428 428
429 CFX_ByteString sAnnotState = pAnnotDic->GetString("AS"); 429 CFX_ByteString sAnnotState = pAnnotDic->GetStringBy("AS");
430 CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDict("AP"); 430 CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDictBy("AP");
431 if (!pAnnotAP) 431 if (!pAnnotAP)
432 continue; 432 continue;
433 433
434 CPDF_Stream* pAPStream = pAnnotAP->GetStream("N"); 434 CPDF_Stream* pAPStream = pAnnotAP->GetStreamBy("N");
435 if (!pAPStream) { 435 if (!pAPStream) {
436 CPDF_Dictionary* pAPDic = pAnnotAP->GetDict("N"); 436 CPDF_Dictionary* pAPDic = pAnnotAP->GetDictBy("N");
437 if (!pAPDic) 437 if (!pAPDic)
438 continue; 438 continue;
439 439
440 if (!sAnnotState.IsEmpty()) { 440 if (!sAnnotState.IsEmpty()) {
441 pAPStream = pAPDic->GetStream(sAnnotState); 441 pAPStream = pAPDic->GetStreamBy(sAnnotState);
442 } else { 442 } else {
443 auto it = pAPDic->begin(); 443 auto it = pAPDic->begin();
444 if (it != pAPDic->end()) { 444 if (it != pAPDic->end()) {
445 CPDF_Object* pFirstObj = it->second; 445 CPDF_Object* pFirstObj = it->second;
446 if (pFirstObj) { 446 if (pFirstObj) {
447 if (pFirstObj->IsReference()) 447 if (pFirstObj->IsReference())
448 pFirstObj = pFirstObj->GetDirect(); 448 pFirstObj = pFirstObj->GetDirect();
449 if (!pFirstObj->IsStream()) 449 if (!pFirstObj->IsStream())
450 continue; 450 continue;
451 pAPStream = pFirstObj->AsStream(); 451 pAPStream = pFirstObj->AsStream();
452 } 452 }
453 } 453 }
454 } 454 }
455 } 455 }
456 if (!pAPStream) 456 if (!pAPStream)
457 continue; 457 continue;
458 458
459 CPDF_Dictionary* pAPDic = pAPStream->GetDict(); 459 CPDF_Dictionary* pAPDic = pAPStream->GetDict();
460 CFX_Matrix matrix = pAPDic->GetMatrix("Matrix"); 460 CFX_Matrix matrix = pAPDic->GetMatrixBy("Matrix");
461 461
462 CPDF_Rect rcStream; 462 CPDF_Rect rcStream;
463 if (pAPDic->KeyExist("Rect")) 463 if (pAPDic->KeyExist("Rect"))
464 rcStream = pAPDic->GetRect("Rect"); 464 rcStream = pAPDic->GetRectBy("Rect");
465 else if (pAPDic->KeyExist("BBox")) 465 else if (pAPDic->KeyExist("BBox"))
466 rcStream = pAPDic->GetRect("BBox"); 466 rcStream = pAPDic->GetRectBy("BBox");
467 467
468 if (rcStream.IsEmpty()) 468 if (rcStream.IsEmpty())
469 continue; 469 continue;
470 470
471 CPDF_Object* pObj = pAPStream; 471 CPDF_Object* pObj = pAPStream;
472 472
473 if (pObj) { 473 if (pObj) {
474 CPDF_Dictionary* pObjDic = pObj->GetDict(); 474 CPDF_Dictionary* pObjDic = pObj->GetDict();
475 if (pObjDic) { 475 if (pObjDic) {
476 pObjDic->SetAtName("Type", "XObject"); 476 pObjDic->SetAtName("Type", "XObject");
477 pObjDic->SetAtName("Subtype", "Form"); 477 pObjDic->SetAtName("Subtype", "Form");
478 } 478 }
479 } 479 }
480 480
481 CPDF_Dictionary* pXObject = pNewXORes->GetDict("XObject"); 481 CPDF_Dictionary* pXObject = pNewXORes->GetDictBy("XObject");
482 if (!pXObject) { 482 if (!pXObject) {
483 pXObject = new CPDF_Dictionary; 483 pXObject = new CPDF_Dictionary;
484 pNewXORes->SetAt("XObject", pXObject); 484 pNewXORes->SetAt("XObject", pXObject);
485 } 485 }
486 486
487 CFX_ByteString sFormName; 487 CFX_ByteString sFormName;
488 sFormName.Format("F%d", i); 488 sFormName.Format("F%d", i);
489 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj); 489 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj);
490 pXObject->SetAtReference(sFormName, pDocument, dwObjNum); 490 pXObject->SetAtReference(sFormName, pDocument, dwObjNum);
491 491
(...skipping 21 matching lines...) Expand all
513 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, 513 pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE,
514 FALSE); 514 FALSE);
515 } 515 }
516 pPageDict->RemoveAt("Annots"); 516 pPageDict->RemoveAt("Annots");
517 517
518 ObjectArray.RemoveAll(); 518 ObjectArray.RemoveAll();
519 RectArray.RemoveAll(); 519 RectArray.RemoveAll();
520 520
521 return FLATTEN_SUCCESS; 521 return FLATTEN_SUCCESS;
522 } 522 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdf_ext.cpp ('k') | fpdfsdk/src/fpdf_transformpage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698