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

Side by Side Diff: core/fpdfapi/parser/cpdf_linearized.cpp

Issue 2466023002: Unify some code (Closed)
Patch Set: Fix review issues. Created 4 years, 1 month 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
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fpdfapi/parser/cpdf_linearized.h"
8
9 #include <algorithm>
10
11 #include "core/fpdfapi/parser/cpdf_array.h"
12 #include "core/fpdfapi/parser/cpdf_dictionary.h"
13 #include "third_party/base/ptr_util.h"
14
15 // static
16 std::unique_ptr<CPDF_Linearized> CPDF_Linearized::CreateForObject(
17 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj) {
18 UniqueDictionary pDict = ToDictionary(std::move(pObj));
19 if (!pDict || !pDict->GetObjectFor("Linearized"))
20 return nullptr;
21 auto result = pdfium::WrapUnique(new CPDF_Linearized(pDict.get()));
22 if (result->IsValid())
23 return result;
24 return nullptr;
25 }
26
27 CPDF_Linearized::CPDF_Linearized(const CPDF_Dictionary* pDict) {
28 m_szFileSize = std::max(pDict->GetIntegerFor("L"), 0);
29 m_dwFirstPageNo = std::max(pDict->GetIntegerFor("P"), 0);
30 m_szLastXRefOffset = std::max(pDict->GetIntegerFor("T"), 0);
31 m_PageCount = std::max(pDict->GetIntegerFor("N"), 0);
32 m_szFirstPageEndOffset = std::max(pDict->GetIntegerFor("E"), 0);
33 m_FirstPageObjNum = std::max(pDict->GetIntegerFor("O"), 0);
34 const CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H");
35 const size_t nHintStreamSize =
36 pHintStreamRange ? pHintStreamRange->GetCount() : 0;
37 if (nHintStreamSize == 2 || nHintStreamSize == 4) {
38 m_szHintStart = std::max(pHintStreamRange->GetIntegerAt(0), 0);
39 m_szHintLength = std::max(pHintStreamRange->GetIntegerAt(1), 0);
40 }
41 }
42
43 CPDF_Linearized::~CPDF_Linearized() {}
44
45 bool CPDF_Linearized::IsValid() const {
46 return GetFileSize() > 0 && GetFirstPageEndOffset() > 0 &&
47 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
48 }
49
50 bool CPDF_Linearized::HasHintTable() const {
51 return GetPageCount() > 1 && GetHintStart() > 0 && GetHintLength() > 0;
52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698