summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-02-01 17:07:13 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-01 17:07:13 +0000
commit71a7d377ff36a0be1af1848d5cac0ccb83ae725d (patch)
treec7f26301bbfcd45126900f7bbc0dc88f5e8a8946 /core/fpdfdoc
parent1fc533150a27257de4830559a14499f2e903dce9 (diff)
downloadpdfium-71a7d377ff36a0be1af1848d5cac0ccb83ae725d.tar.xz
Deprecate FPDFDest_GetPageIndex and create a fixed version.
FPDFDest_GetDestPageIndex() has a well defined return value for errors (-1). Keeping FPDFDest_GetPageIndex() to avoid changing behavior of the old API for whoever relies on it. Bug: pdfium:938 Change-Id: Iad528923cb156e957a419540c262a65f45cb777d Reviewed-on: https://pdfium-review.googlesource.com/24811 Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_dest.cpp23
-rw-r--r--core/fpdfdoc/cpdf_dest.h8
2 files changed, 29 insertions, 2 deletions
diff --git a/core/fpdfdoc/cpdf_dest.cpp b/core/fpdfdoc/cpdf_dest.cpp
index 0098f73f66..015cdcbc09 100644
--- a/core/fpdfdoc/cpdf_dest.cpp
+++ b/core/fpdfdoc/cpdf_dest.cpp
@@ -38,7 +38,7 @@ CPDF_Dest::CPDF_Dest(CPDF_Object* pObj) : m_pObj(pObj) {}
CPDF_Dest::~CPDF_Dest() {}
-int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) const {
+int CPDF_Dest::GetPageIndexDeprecated(CPDF_Document* pDoc) const {
CPDF_Array* pArray = ToArray(m_pObj.Get());
if (!pArray)
return 0;
@@ -46,10 +46,31 @@ int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) const {
CPDF_Object* pPage = pArray->GetDirectObjectAt(0);
if (!pPage)
return 0;
+
if (pPage->IsNumber())
return pPage->GetInteger();
+
if (!pPage->IsDictionary())
return 0;
+
+ return pDoc->GetPageIndex(pPage->GetObjNum());
+}
+
+int CPDF_Dest::GetDestPageIndex(CPDF_Document* pDoc) const {
+ CPDF_Array* pArray = ToArray(m_pObj.Get());
+ if (!pArray)
+ return -1;
+
+ CPDF_Object* pPage = pArray->GetDirectObjectAt(0);
+ if (!pPage)
+ return -1;
+
+ if (pPage->IsNumber())
+ return pPage->GetInteger();
+
+ if (!pPage->IsDictionary())
+ return -1;
+
return pDoc->GetPageIndex(pPage->GetObjNum());
}
diff --git a/core/fpdfdoc/cpdf_dest.h b/core/fpdfdoc/cpdf_dest.h
index 584669a82d..709a2470c5 100644
--- a/core/fpdfdoc/cpdf_dest.h
+++ b/core/fpdfdoc/cpdf_dest.h
@@ -23,7 +23,13 @@ class CPDF_Dest {
CPDF_Object* GetObject() const { return m_pObj.Get(); }
ByteString GetRemoteName() const;
- int GetPageIndex(CPDF_Document* pDoc) const;
+
+ // Deprecated. Use GetDestPageIndex instead.
+ // This method is wrong. It returns 0 for errors, when it could mean the first
+ // page as well. Keeping it avoids changing the behavior of
+ // FPDFDest_GetPageIndex().
+ int GetPageIndexDeprecated(CPDF_Document* pDoc) const;
+ int GetDestPageIndex(CPDF_Document* pDoc) const;
uint32_t GetPageObjNum() const;
// Returns the zoom mode, as one of the PDFDEST_VIEW_* values in fpdf_doc.h.