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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_document.cpp

Issue 2253723002: Move parser pointer to CPDF_Document (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review feedback Created 4 years, 4 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 "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 count++; 475 count++;
476 } 476 }
477 } 477 }
478 pPages->SetAtInteger("Count", count); 478 pPages->SetAtInteger("Count", count);
479 return count; 479 return count;
480 } 480 }
481 481
482 } // namespace 482 } // namespace
483 483
484 CPDF_Document::CPDF_Document(CPDF_Parser* pParser) 484 CPDF_Document::CPDF_Document(CPDF_Parser* pParser)
485 : CPDF_IndirectObjectHolder(pParser), 485 : CPDF_IndirectObjectHolder(),
486 m_pParser(pParser),
486 m_pRootDict(nullptr), 487 m_pRootDict(nullptr),
487 m_pInfoDict(nullptr), 488 m_pInfoDict(nullptr),
488 m_bLinearized(false), 489 m_bLinearized(false),
489 m_iFirstPageNo(0), 490 m_iFirstPageNo(0),
490 m_dwFirstPageObjNum(0), 491 m_dwFirstPageObjNum(0),
491 m_pDocPage(new CPDF_DocPageData(this)), 492 m_pDocPage(new CPDF_DocPageData(this)),
492 m_pDocRender(new CPDF_DocRenderData(this)) {} 493 m_pDocRender(new CPDF_DocRenderData(this)) {
494 if (pParser)
495 SetLastObjNum(m_pParser->GetLastObjNum());
496 }
493 497
494 CPDF_Document::~CPDF_Document() { 498 CPDF_Document::~CPDF_Document() {
495 delete m_pDocPage; 499 delete m_pDocPage;
496 CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this); 500 CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this);
497 } 501 }
498 502
503 CPDF_Object* CPDF_Document::GetIndirectObjectIfValid(uint32_t objnum) {
504 CPDF_Object* pObj = GetIndirectObject(objnum);
505 if (pObj)
506 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr;
507
508 if (!m_pParser)
509 return nullptr;
510
511 pObj = m_pParser->ParseIndirectObject(this, objnum);
512 if (!pObj)
513 return nullptr;
514
515 pObj->m_ObjNum = objnum;
516 ReplaceIndirectObject(pObj);
517 return pObj;
518 }
519
499 void CPDF_Document::LoadDocInternal() { 520 void CPDF_Document::LoadDocInternal() {
500 m_LastObjNum = m_pParser->GetLastObjNum(); 521 SetLastObjNum(m_pParser->GetLastObjNum());
501 522
502 CPDF_Object* pRootObj = GetIndirectObject(m_pParser->GetRootObjNum()); 523 CPDF_Object* pRootObj = GetIndirectObjectIfValid(m_pParser->GetRootObjNum());
503 if (!pRootObj) 524 if (!pRootObj)
504 return; 525 return;
505 526
506 m_pRootDict = pRootObj->GetDict(); 527 m_pRootDict = pRootObj->GetDict();
507 if (!m_pRootDict) 528 if (!m_pRootDict)
508 return; 529 return;
509 530
510 CPDF_Object* pInfoObj = GetIndirectObject(m_pParser->GetInfoObjNum()); 531 CPDF_Object* pInfoObj = GetIndirectObjectIfValid(m_pParser->GetInfoObjNum());
511 if (pInfoObj) 532 if (pInfoObj)
512 m_pInfoDict = pInfoObj->GetDict(); 533 m_pInfoDict = pInfoObj->GetDict();
513 if (CPDF_Array* pIDArray = m_pParser->GetIDArray()) { 534 if (CPDF_Array* pIDArray = m_pParser->GetIDArray()) {
514 m_ID1 = pIDArray->GetStringAt(0); 535 m_ID1 = pIDArray->GetStringAt(0);
515 m_ID2 = pIDArray->GetStringAt(1); 536 m_ID2 = pIDArray->GetStringAt(1);
516 } 537 }
517 } 538 }
518 539
519 void CPDF_Document::LoadDoc() { 540 void CPDF_Document::LoadDoc() {
520 LoadDocInternal(); 541 LoadDocInternal();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 601 }
581 return nullptr; 602 return nullptr;
582 } 603 }
583 604
584 CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { 605 CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
585 if (iPage < 0 || iPage >= m_PageList.GetSize()) 606 if (iPage < 0 || iPage >= m_PageList.GetSize())
586 return nullptr; 607 return nullptr;
587 608
588 if (m_bLinearized && (iPage == m_iFirstPageNo)) { 609 if (m_bLinearized && (iPage == m_iFirstPageNo)) {
589 if (CPDF_Dictionary* pDict = 610 if (CPDF_Dictionary* pDict =
590 ToDictionary(GetIndirectObject(m_dwFirstPageObjNum))) { 611 ToDictionary(GetIndirectObjectIfValid(m_dwFirstPageObjNum))) {
591 return pDict; 612 return pDict;
592 } 613 }
593 } 614 }
594 615
595 int objnum = m_PageList.GetAt(iPage); 616 int objnum = m_PageList.GetAt(iPage);
596 if (objnum) { 617 if (objnum) {
597 if (CPDF_Dictionary* pDict = ToDictionary(GetIndirectObject(objnum))) 618 if (CPDF_Dictionary* pDict = ToDictionary(GetIndirectObjectIfValid(objnum)))
598 return pDict; 619 return pDict;
599 } 620 }
600 621
601 CPDF_Dictionary* pRoot = GetRoot(); 622 CPDF_Dictionary* pRoot = GetRoot();
602 if (!pRoot) 623 if (!pRoot)
603 return nullptr; 624 return nullptr;
604 625
605 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); 626 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages");
606 if (!pPages) 627 if (!pPages)
607 return nullptr; 628 return nullptr;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 #ifndef PDF_ENABLE_XFA 741 #ifndef PDF_ENABLE_XFA
721 return 0; 742 return 0;
722 #else // PDF_ENABLE_XFA 743 #else // PDF_ENABLE_XFA
723 return 0xFFFFFFFF; 744 return 0xFFFFFFFF;
724 #endif 745 #endif
725 } 746 }
726 return m_pParser->GetPermissions(); 747 return m_pParser->GetPermissions();
727 } 748 }
728 749
729 FX_BOOL CPDF_Document::IsFormStream(uint32_t objnum, FX_BOOL& bForm) const { 750 FX_BOOL CPDF_Document::IsFormStream(uint32_t objnum, FX_BOOL& bForm) const {
730 auto it = m_IndirectObjs.find(objnum); 751 if (CPDF_Object* pObj = GetIndirectObject(objnum)) {
731 if (it != m_IndirectObjs.end()) { 752 CPDF_Stream* pStream = pObj->AsStream();
732 CPDF_Stream* pStream = it->second->AsStream();
733 bForm = pStream && pStream->GetDict()->GetStringBy("Subtype") == "Form"; 753 bForm = pStream && pStream->GetDict()->GetStringBy("Subtype") == "Form";
734 return TRUE; 754 return TRUE;
735 } 755 }
736 if (!m_pParser) { 756 if (!m_pParser) {
737 bForm = FALSE; 757 bForm = FALSE;
738 return TRUE; 758 return TRUE;
739 } 759 }
740 return m_pParser->IsFormStream(objnum, bForm); 760 return m_pParser->IsFormStream(objnum, bForm);
741 } 761 }
742 762
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1461 }
1442 } 1462 }
1443 pFontDesc->SetAtInteger("StemV", fStemV); 1463 pFontDesc->SetAtInteger("StemV", fStemV);
1444 AddIndirectObject(pFontDesc); 1464 AddIndirectObject(pFontDesc);
1445 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); 1465 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc);
1446 CFRelease(traits); 1466 CFRelease(traits);
1447 CFRelease(languages); 1467 CFRelease(languages);
1448 return LoadFont(pBaseDict); 1468 return LoadFont(pBaseDict);
1449 } 1469 }
1450 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1470 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698