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

Unified Diff: core/fpdfapi/parser/cpdf_linearized.cpp

Issue 2466023002: Unify some code (Closed)
Patch Set: Fix compilation 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..b8331e60154898fd4cd2a2c1ca497671fb79610c
--- /dev/null
+++ b/core/fpdfapi/parser/cpdf_linearized.cpp
@@ -0,0 +1,46 @@
+// 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"
+#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) {
+ CPDF_Dictionary* pDict = ToDictionary(pObj.get());
+ if (!pDict || !pDict->GetObjectFor("Linearized"))
+ return nullptr;
+ return pdfium::WrapUnique(new CPDF_Linearized(pDict));
+}
+
+CPDF_Linearized::CPDF_Linearized(const CPDF_Dictionary* pDict) {
+ m_szFileSize = pDict->GetIntegerFor("L");
+ m_dwFirstPageNo = pDict->GetIntegerFor("P");
Lei Zhang 2016/11/03 00:46:26 I'm still worried about some of these signed/unsig
snake 2016/11/03 01:39:27 If it contains "-1" , that pdf file is corruped.
Lei Zhang 2016/11/03 01:59:31 Oh, but I worry about this a lot. If you look at P
snake 2016/11/03 02:36:52 "N" 1) It is already casted to unsigned. Check, th
+ 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::IsValid() const {
+ return GetFileSize() > 0 && GetFirstPageEndOffset() > 0 &&
+ GetPageCount() > 0 && (GetPageCount() == 1 || GetLastXRefOffset() > 0);
+}
+
+bool CPDF_Linearized::HasHintTable() const {
+ return GetPageCount() > 1 && GetHintStart() > 0 && GetHintLength() > 0;
+}

Powered by Google App Engine
This is Rietveld 408576698