Chromium Code Reviews| Index: core/fpdfapi/parser/cpdf_linearized.cpp |
| diff --git a/core/fpdfapi/parser/cpdf_linearized.cpp b/core/fpdfapi/parser/cpdf_linearized.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..50c71399b4175453dd859dc637de338440c3d8eb |
| --- /dev/null |
| +++ b/core/fpdfapi/parser/cpdf_linearized.cpp |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2016 PDFium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| + |
| +#include "core/fpdfapi/parser/cpdf_linearized.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "core/fpdfapi/parser/cpdf_array.h" |
| +#include "core/fpdfapi/parser/cpdf_dictionary.h" |
| +#include "third_party/base/ptr_util.h" |
| + |
| +// static |
| +std::unique_ptr<CPDF_Linearized> CPDF_Linearized::CreateForObject( |
| + std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj) { |
| + UniqueDictionary pDict = ToDictionary(std::move(pObj)); |
| + if (!pDict || !pDict->GetObjectFor("Linearized")) |
| + return nullptr; |
| + auto result = pdfium::WrapUnique(new CPDF_Linearized(pDict.get())); |
| + if (result->IsValid()) |
| + return result; |
| + return nullptr; |
| +} |
| + |
| +CPDF_Linearized::CPDF_Linearized(const CPDF_Dictionary* pDict) { |
| + m_szFileSize = std::max(pDict->GetIntegerFor("L"), 0); |
| + m_dwFirstPageNo = std::max(pDict->GetIntegerFor("P"), 0); |
| + m_szLastXRefOffset = std::max(pDict->GetIntegerFor("T"), 0); |
| + m_PageCount = std::max(pDict->GetIntegerFor("N"), 0); |
| + m_szFirstPageEndOffset = std::max(pDict->GetIntegerFor("E"), 0); |
| + m_FirstPageObjNum = std::max(pDict->GetIntegerFor("O"), 0); |
| + const CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); |
| + const size_t nHintStreamSize = |
| + pHintStreamRange ? pHintStreamRange->GetCount() : 0; |
| + if (nHintStreamSize == 2 || nHintStreamSize == 4) { |
| + m_szHintStart = std::max(pHintStreamRange->GetIntegerAt(0), 0); |
| + m_szHintLength = std::max(pHintStreamRange->GetIntegerAt(1), 0); |
| + } |
| +} |
| + |
| +CPDF_Linearized::~CPDF_Linearized() {} |
| + |
| +bool CPDF_Linearized::IsValid() const { |
| + return GetFileSize() > 0 && GetFirstPageEndOffset() > 0 && |
| + GetPageCount() > 0 && (GetPageCount() == 1 || GetLastXRefOffset() > 0); |
|
Lei Zhang
2016/11/03 17:18:00
Why did you decide GetLastXRefOffset() can be 0 wh
snake
2016/11/03 17:50:34
LastXRefOffset is offset to MainXRefTable, but if
|
| +} |
| + |
| +bool CPDF_Linearized::HasHintTable() const { |
| + return GetPageCount() > 1 && GetHintStart() > 0 && GetHintLength() > 0; |
| +} |