Chromium Code Reviews| Index: core/fpdfapi/parser/cpdf_parser.cpp |
| diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp |
| index c2748882cfde06fba94c4d0a550bbe0013e36e55..624ebf27dd1ab75e1cccf3bbc9a99b8fe912f68d 100644 |
| --- a/core/fpdfapi/parser/cpdf_parser.cpp |
| +++ b/core/fpdfapi/parser/cpdf_parser.cpp |
| @@ -12,6 +12,7 @@ |
| #include "core/fpdfapi/parser/cpdf_crypto_handler.h" |
| #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| #include "core/fpdfapi/parser/cpdf_document.h" |
| +#include "core/fpdfapi/parser/cpdf_linearized.h" |
| #include "core/fpdfapi/parser/cpdf_number.h" |
| #include "core/fpdfapi/parser/cpdf_reference.h" |
| #include "core/fpdfapi/parser/cpdf_security_handler.h" |
| @@ -54,8 +55,6 @@ CPDF_Parser::CPDF_Parser() |
| m_pTrailer(nullptr), |
| m_pEncryptDict(nullptr), |
| m_bVersionUpdated(false), |
| - m_pLinearized(nullptr), |
| - m_dwFirstPageNo(0), |
| m_dwXrefStartObjNum(0) { |
| m_pSyntax.reset(new CPDF_SyntaxParser); |
| } |
| @@ -76,9 +75,6 @@ CPDF_Parser::~CPDF_Parser() { |
| if (trailer) |
| trailer->Release(); |
| } |
| - |
| - if (m_pLinearized) |
| - m_pLinearized->Release(); |
| } |
| uint32_t CPDF_Parser::GetLastObjNum() const { |
| @@ -1414,6 +1410,10 @@ CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( |
| return pObj; |
| } |
| +uint32_t CPDF_Parser::GetFirstPageNo() const { |
| + return m_pLinearized ? m_pLinearized->GetFirstPageNo() : 0; |
| +} |
| + |
| CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { |
| if (m_pSyntax->GetKeyword() != "trailer") |
| return nullptr; |
| @@ -1460,35 +1460,13 @@ FX_BOOL CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, |
| return FALSE; |
| } |
| - m_pLinearized = m_pSyntax->GetObject(nullptr, objnum, gennum, true); |
| - if (!m_pLinearized) |
| + auto pLinearized = CPDF_Linearized::CreateForObject( |
|
Lei Zhang
2016/11/03 00:46:26
Do we want to directly assign to |m_pLinearized| h
snake
2016/11/03 01:39:27
What do you mean?
If we have not valid CPDF_Linear
Lei Zhang
2016/11/03 01:59:31
But with the IsValid() check that we just added, C
snake
2016/11/03 02:36:52
Done.
|
| + UniqueObject(m_pSyntax->GetObject(nullptr, objnum, gennum, true))); |
| + if (!pLinearized || !pLinearized->IsValid()) |
| return FALSE; |
| - |
| - CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
| - if (pDict && pDict->GetObjectFor("Linearized")) { |
| - m_pSyntax->GetNextWord(nullptr); |
| - |
| - CPDF_Object* pLen = pDict->GetObjectFor("L"); |
| - if (!pLen) { |
| - m_pLinearized->Release(); |
| - m_pLinearized = nullptr; |
| - return FALSE; |
| - } |
| - |
| - if (pLen->GetInteger() != (int)pFileAccess->GetSize()) |
| - return FALSE; |
| - |
| - if (CPDF_Number* pNo = ToNumber(pDict->GetObjectFor("P"))) |
| - m_dwFirstPageNo = pNo->GetInteger(); |
| - |
| - if (CPDF_Number* pTable = ToNumber(pDict->GetObjectFor("T"))) |
| - m_LastXRefOffset = pTable->GetInteger(); |
| - |
| - return TRUE; |
| - } |
| - m_pLinearized->Release(); |
| - m_pLinearized = nullptr; |
| - return FALSE; |
| + m_pLinearized = std::move(pLinearized); |
| + m_LastXRefOffset = m_pLinearized->GetLastXRefOffset(); |
| + return TRUE; |
| } |
| CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( |
| @@ -1511,6 +1489,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( |
| m_bHasParsed = true; |
| m_pDocument = pDocument; |
| + m_pSyntax->GetNextWord(nullptr); |
| FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos(); |
| FX_BOOL bXRefRebuilt = FALSE; |
| @@ -1537,7 +1516,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( |
| if (eRet != SUCCESS) |
| return eRet; |
| - m_pDocument->LoadLinearizedDoc(m_pLinearized->GetDict()); |
| + m_pDocument->LoadLinearizedDoc(m_pLinearized.get()); |
| if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { |
| if (bXRefRebuilt) |
| return FORMAT_ERROR; |
| @@ -1550,7 +1529,7 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse( |
| if (eRet != SUCCESS) |
| return eRet; |
| - m_pDocument->LoadLinearizedDoc(m_pLinearized->GetDict()); |
| + m_pDocument->LoadLinearizedDoc(m_pLinearized.get()); |
| if (!m_pDocument->GetRoot()) |
| return FORMAT_ERROR; |
| } |