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

Unified 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 side-by-side diff with in-line comments
Download patch
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..3e371258ecbceb89b0f15332324c94a8bac43041
--- /dev/null
+++ b/core/fpdfapi/parser/cpdf_linearized.cpp
@@ -0,0 +1,42 @@
+// 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 "core/fpdfapi/parser/cpdf_array.h"
+#include "core/fpdfapi/parser/cpdf_dictionary.h"
+
+// static
+std::unique_ptr<CPDF_Linearized> CPDF_Linearized::CreateForObject(
+ std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj) {
+ if (!pObj)
Lei Zhang 2016/11/02 21:34:22 You can write this as: UniqueDictionary pDict = T
snake 2016/11/02 22:04:29 Done.
snake 2016/11/02 22:35:16 Do not compile with "UniqueDictionary pDict = ToD
Lei Zhang 2016/11/03 00:46:26 Err, UniqueDictionary pDict = ToDictionary(std::mo
snake 2016/11/03 01:39:27 Done.
+ return std::unique_ptr<CPDF_Linearized>();
Lei Zhang 2016/11/02 21:34:22 In https://codereview.chromium.org/2453163002 we c
snake 2016/11/02 22:04:28 Done.
+ CPDF_Dictionary* pDict = pObj->GetDict();
+ if (!pDict || !pDict->GetObjectFor("Linearized"))
+ return std::unique_ptr<CPDF_Linearized>();
+ return std::unique_ptr<CPDF_Linearized>(new CPDF_Linearized(pDict));
+}
+
+CPDF_Linearized::CPDF_Linearized(CPDF_Dictionary* pDict) {
+ m_szFileSize = pDict->GetIntegerFor("L");
+ m_dwFirstPageNo = pDict->GetIntegerFor("P");
+ m_szLastXRefOffset = pDict->GetIntegerFor("T");
+ m_PageCount = pDict->GetIntegerFor("N");
+ m_szFirstPageEndOffset = pDict->GetIntegerFor("E");
+ m_FirstPageObjNum = pDict->GetIntegerFor("O");
+ CPDF_Array* pHintStreamRange = pDict->GetArrayFor("H");
+ size_t nHintStreamSize = pHintStreamRange ? pHintStreamRange->GetCount() : 0;
+ if (nHintStreamSize == 2 || nHintStreamSize == 4) {
+ m_szHintStart = pHintStreamRange->GetIntegerAt(0);
+ m_szHintLength = pHintStreamRange->GetIntegerAt(1);
+ }
+}
+
+CPDF_Linearized::~CPDF_Linearized() {}
+
+bool CPDF_Linearized::HasHintTable() const {
+ return GetPageCount() > 1 && GetHintStart() > 0 && GetHintLength() > 0;
+}

Powered by Google App Engine
This is Rietveld 408576698