diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2018-06-27 18:15:10 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-27 18:15:10 +0000 |
commit | 20eca1e383b7dce69cd791d42bda3558a3966301 (patch) | |
tree | d3fded7303e8326d3883ca51b6bed2ad2438b6da /core/fpdfapi/parser/cpdf_document.cpp | |
parent | 00ba8bbea0ff57d6f11257736408e530e54ef642 (diff) | |
download | pdfium-20eca1e383b7dce69cd791d42bda3558a3966301.tar.xz |
Rework of loading of CPDF_Document.
Improve CPDF_Document interface.
Fix relationship between CPDF_Document and CPDF_Parser.
This CL changes CPDF_Document to internally create the CPDF_Parser
and removes the need for the CPDF_Parser to know about the CPDF_Document.
Change-Id: Iec7aef19575c90f30b9a6c919dfd4f4417e4caf2
Reviewed-on: https://pdfium-review.googlesource.com/35630
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_document.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_document.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 8f727ed14a..91c6b9c6f9 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -22,6 +22,7 @@ #include "core/fpdfapi/parser/cpdf_name.h" #include "core/fpdfapi/parser/cpdf_number.h" #include "core/fpdfapi/parser/cpdf_parser.h" +#include "core/fpdfapi/parser/cpdf_read_validator.h" #include "core/fpdfapi/parser/cpdf_reference.h" #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_string.h" @@ -185,17 +186,13 @@ std::unique_ptr<CPDF_Dictionary> CalculateFontDesc( } // namespace -CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) - : CPDF_IndirectObjectHolder(), - m_pParser(std::move(pParser)), +CPDF_Document::CPDF_Document() + : ParsedObjectsHolder(), m_pRootDict(nullptr), m_iNextPageToTraverse(0), m_bReachedMaxPageLevel(false), m_pDocPage(pdfium::MakeUnique<CPDF_DocPageData>(this)), - m_pDocRender(pdfium::MakeUnique<CPDF_DocRenderData>(this)) { - if (pParser) - SetLastObjNum(m_pParser->GetLastObjNum()); -} + m_pDocRender(pdfium::MakeUnique<CPDF_DocRenderData>(this)) {} CPDF_Document::~CPDF_Document() { CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this); @@ -203,7 +200,7 @@ CPDF_Document::~CPDF_Document() { std::unique_ptr<CPDF_Object> CPDF_Document::ParseIndirectObject( uint32_t objnum) { - return m_pParser ? m_pParser->ParseIndirectObject(this, objnum) : nullptr; + return m_pParser ? m_pParser->ParseIndirectObject(objnum) : nullptr; } void CPDF_Document::LoadDocInternal() { @@ -218,9 +215,28 @@ void CPDF_Document::LoadDocInternal() { return; } -void CPDF_Document::LoadDoc() { +bool CPDF_Document::TryInit() { LoadDocInternal(); LoadPages(); + return GetRoot() && (GetPageCount() > 0); +} + +CPDF_Parser::Error CPDF_Document::LoadDoc( + const RetainPtr<IFX_SeekableReadStream>& pFileAccess, + const char* password) { + if (!m_pParser) + SetParser(pdfium::MakeUnique<CPDF_Parser>(this)); + + return m_pParser->StartParse(pFileAccess, password); +} + +CPDF_Parser::Error CPDF_Document::LoadLinearizedDoc( + const RetainPtr<CPDF_ReadValidator>& validator, + const char* password) { + if (!m_pParser) + SetParser(pdfium::MakeUnique<CPDF_Parser>(this)); + + return m_pParser->StartLinearizedParse(validator, password); } void CPDF_Document::LoadPages() { @@ -309,6 +325,11 @@ void CPDF_Document::ResetTraversal() { m_pTreeTraversal.clear(); } +void CPDF_Document::SetParser(std::unique_ptr<CPDF_Parser> pParser) { + DCHECK(!m_pParser); + m_pParser = std::move(pParser); +} + const CPDF_Dictionary* CPDF_Document::GetPagesDict() const { const CPDF_Dictionary* pRoot = GetRoot(); return pRoot ? pRoot->GetDictFor("Pages") : nullptr; |