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

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 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::ParseIndirectObject(uint32_t objnum) {
504 return m_pParser ? m_pParser->ParseIndirectObject(this, objnum) : nullptr;
505 }
506
499 void CPDF_Document::LoadDocInternal() { 507 void CPDF_Document::LoadDocInternal() {
500 m_LastObjNum = m_pParser->GetLastObjNum(); 508 SetLastObjNum(m_pParser->GetLastObjNum());
501 509
502 CPDF_Object* pRootObj = GetIndirectObject(m_pParser->GetRootObjNum()); 510 CPDF_Object* pRootObj = GetOrParseIndirectObject(m_pParser->GetRootObjNum());
503 if (!pRootObj) 511 if (!pRootObj)
504 return; 512 return;
505 513
506 m_pRootDict = pRootObj->GetDict(); 514 m_pRootDict = pRootObj->GetDict();
507 if (!m_pRootDict) 515 if (!m_pRootDict)
508 return; 516 return;
509 517
510 CPDF_Object* pInfoObj = GetIndirectObject(m_pParser->GetInfoObjNum()); 518 CPDF_Object* pInfoObj = GetOrParseIndirectObject(m_pParser->GetInfoObjNum());
511 if (pInfoObj) 519 if (pInfoObj)
512 m_pInfoDict = pInfoObj->GetDict(); 520 m_pInfoDict = pInfoObj->GetDict();
513 if (CPDF_Array* pIDArray = m_pParser->GetIDArray()) { 521 if (CPDF_Array* pIDArray = m_pParser->GetIDArray()) {
514 m_ID1 = pIDArray->GetStringAt(0); 522 m_ID1 = pIDArray->GetStringAt(0);
515 m_ID2 = pIDArray->GetStringAt(1); 523 m_ID2 = pIDArray->GetStringAt(1);
516 } 524 }
517 } 525 }
518 526
519 void CPDF_Document::LoadDoc() { 527 void CPDF_Document::LoadDoc() {
520 LoadDocInternal(); 528 LoadDocInternal();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 588 }
581 return nullptr; 589 return nullptr;
582 } 590 }
583 591
584 CPDF_Dictionary* CPDF_Document::GetPage(int iPage) { 592 CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
585 if (iPage < 0 || iPage >= m_PageList.GetSize()) 593 if (iPage < 0 || iPage >= m_PageList.GetSize())
586 return nullptr; 594 return nullptr;
587 595
588 if (m_bLinearized && (iPage == m_iFirstPageNo)) { 596 if (m_bLinearized && (iPage == m_iFirstPageNo)) {
589 if (CPDF_Dictionary* pDict = 597 if (CPDF_Dictionary* pDict =
590 ToDictionary(GetIndirectObject(m_dwFirstPageObjNum))) { 598 ToDictionary(GetOrParseIndirectObject(m_dwFirstPageObjNum))) {
591 return pDict; 599 return pDict;
592 } 600 }
593 } 601 }
594 602
595 int objnum = m_PageList.GetAt(iPage); 603 int objnum = m_PageList.GetAt(iPage);
596 if (objnum) { 604 if (objnum) {
597 if (CPDF_Dictionary* pDict = ToDictionary(GetIndirectObject(objnum))) 605 if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum)))
598 return pDict; 606 return pDict;
599 } 607 }
600 608
601 CPDF_Dictionary* pRoot = GetRoot(); 609 CPDF_Dictionary* pRoot = GetRoot();
602 if (!pRoot) 610 if (!pRoot)
603 return nullptr; 611 return nullptr;
604 612
605 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages"); 613 CPDF_Dictionary* pPages = pRoot->GetDictBy("Pages");
606 if (!pPages) 614 if (!pPages)
607 return nullptr; 615 return nullptr;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 #ifndef PDF_ENABLE_XFA 728 #ifndef PDF_ENABLE_XFA
721 return 0; 729 return 0;
722 #else // PDF_ENABLE_XFA 730 #else // PDF_ENABLE_XFA
723 return 0xFFFFFFFF; 731 return 0xFFFFFFFF;
724 #endif 732 #endif
725 } 733 }
726 return m_pParser->GetPermissions(); 734 return m_pParser->GetPermissions();
727 } 735 }
728 736
729 FX_BOOL CPDF_Document::IsFormStream(uint32_t objnum, FX_BOOL& bForm) const { 737 FX_BOOL CPDF_Document::IsFormStream(uint32_t objnum, FX_BOOL& bForm) const {
730 auto it = m_IndirectObjs.find(objnum); 738 if (CPDF_Object* pObj = GetIndirectObject(objnum)) {
731 if (it != m_IndirectObjs.end()) { 739 CPDF_Stream* pStream = pObj->AsStream();
732 CPDF_Stream* pStream = it->second->AsStream();
733 bForm = pStream && pStream->GetDict()->GetStringBy("Subtype") == "Form"; 740 bForm = pStream && pStream->GetDict()->GetStringBy("Subtype") == "Form";
734 return TRUE; 741 return TRUE;
735 } 742 }
736 if (!m_pParser) { 743 if (!m_pParser) {
737 bForm = FALSE; 744 bForm = FALSE;
738 return TRUE; 745 return TRUE;
739 } 746 }
740 return m_pParser->IsFormStream(objnum, bForm); 747 return m_pParser->IsFormStream(objnum, bForm);
741 } 748 }
742 749
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1448 }
1442 } 1449 }
1443 pFontDesc->SetAtInteger("StemV", fStemV); 1450 pFontDesc->SetAtInteger("StemV", fStemV);
1444 AddIndirectObject(pFontDesc); 1451 AddIndirectObject(pFontDesc);
1445 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); 1452 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc);
1446 CFRelease(traits); 1453 CFRelease(traits);
1447 CFRelease(languages); 1454 CFRelease(languages);
1448 return LoadFont(pBaseDict); 1455 return LoadFont(pBaseDict);
1449 } 1456 }
1450 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 1457 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698