OLD | NEW |
---|---|
(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 "core/fpdfapi/parser/cpdf_array.h" | |
10 #include "core/fpdfapi/parser/cpdf_dictionary.h" | |
11 #include "core/fpdfapi/parser/cpdf_number.h" | |
12 #include "third_party/base/ptr_util.h" | |
13 | |
14 namespace { | |
15 | |
16 template <class T> | |
17 bool IsValidNumericDictionaryValue(const CPDF_Dictionary* pDict, | |
18 const char* key, | |
19 T min_value, | |
20 bool must_be_exists = true) { | |
Lei Zhang
2016/11/04 23:02:15
must_exist
snake
2016/11/04 23:27:36
Done.
| |
21 const CPDF_Object* pNum = pDict->GetObjectFor(key); | |
Lei Zhang
2016/11/04 23:02:15
You can write:
const CPDF_Number* pNum = ToNumber
snake
2016/11/04 23:27:36
Done.
| |
22 if (!pNum || !pNum->IsNumber()) | |
Lei Zhang
2016/11/04 23:02:15
Also check IsInteger() ?
snake
2016/11/04 23:27:36
Done.
| |
23 return !must_be_exists; | |
24 const int raw_value = pNum->AsNumber()->GetInteger(); | |
25 if (!pdfium::base::IsValueInRangeForNumericType<T>(raw_value)) | |
26 return false; | |
27 return static_cast<T>(raw_value) >= min_value; | |
28 } | |
29 } // namespace | |
Lei Zhang
2016/11/04 23:02:15
nit: blank line above
snake
2016/11/04 23:27:36
Done.
| |
30 | |
31 // static | |
32 std::unique_ptr<CPDF_Linearized> CPDF_Linearized::CreateForObject( | |
33 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj) { | |
34 UniqueDictionary pDict = ToDictionary(std::move(pObj)); | |
35 if (!pDict || !pDict->GetObjectFor("Linearized") || | |
Lei Zhang
2016/11/04 23:02:15
Use KeyExist() instead of GetObjectFor() since you
snake
2016/11/04 23:27:36
Done.
| |
36 !IsValidNumericDictionaryValue<FX_FILESIZE>(pDict.get(), "L", 1) || | |
37 !IsValidNumericDictionaryValue<uint32_t>(pDict.get(), "P", 0, false) || | |
38 !IsValidNumericDictionaryValue<FX_FILESIZE>(pDict.get(), "T", 1) || | |
39 !IsValidNumericDictionaryValue<uint32_t>(pDict.get(), "N", 0) || | |
40 !IsValidNumericDictionaryValue<FX_FILESIZE>(pDict.get(), "E", 1) || | |
41 !IsValidNumericDictionaryValue<uint32_t>(pDict.get(), "O", 1)) | |
42 return nullptr; | |
43 return pdfium::WrapUnique(new CPDF_Linearized(pDict.get())); | |
44 } | |
45 | |
46 CPDF_Linearized::CPDF_Linearized(const CPDF_Dictionary* pDict) { | |
47 m_szFileSize = pDict->GetIntegerFor("L"); | |
48 m_dwFirstPageNo = pDict->GetIntegerFor("P"); | |
49 m_szLastXRefOffset = pDict->GetIntegerFor("T"); | |
50 m_PageCount = pDict->GetIntegerFor("N"); | |
51 m_szFirstPageEndOffset = pDict->GetIntegerFor("E"); | |
52 m_FirstPageObjNum = pDict->GetIntegerFor("O"); | |
53 const CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H"); | |
54 const size_t nHintStreamSize = | |
55 pHintStreamRange ? pHintStreamRange->GetCount() : 0; | |
56 if (nHintStreamSize == 2 || nHintStreamSize == 4) { | |
57 m_szHintStart = std::max(pHintStreamRange->GetIntegerAt(0), 0); | |
58 m_szHintLength = std::max(pHintStreamRange->GetIntegerAt(1), 0); | |
59 } | |
60 } | |
61 | |
62 CPDF_Linearized::~CPDF_Linearized() {} | |
63 | |
64 bool CPDF_Linearized::HasHintTable() const { | |
65 return GetPageCount() > 1 && GetHintStart() > 0 && GetHintLength() > 0; | |
66 } | |
OLD | NEW |