From 04bebfe590d6d27a825b881fd234e31501843edc Mon Sep 17 00:00:00 2001 From: thestig Date: Fri, 4 Nov 2016 16:07:25 -0700 Subject: Implement FPDF_VIEWERREF_GetName() API. This is a generic API function to retrieve any viewer preference of type name. BUG=pdfium:414 Review-Url: https://codereview.chromium.org/2475923003 --- core/fpdfdoc/cpdf_viewerpreferences.cpp | 16 ++++++++++++++++ core/fpdfdoc/cpdf_viewerpreferences.h | 5 +++++ 2 files changed, 21 insertions(+) (limited to 'core') diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp index 799f2d5814..f1fc4b0347 100644 --- a/core/fpdfdoc/cpdf_viewerpreferences.cpp +++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp @@ -7,6 +7,7 @@ #include "core/fpdfdoc/cpdf_viewerpreferences.h" #include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_name.h" CPDF_ViewerPreferences::CPDF_ViewerPreferences(CPDF_Document* pDoc) : m_pDoc(pDoc) {} @@ -38,6 +39,21 @@ CFX_ByteString CPDF_ViewerPreferences::Duplex() const { return pDict ? pDict->GetStringFor("Duplex") : CFX_ByteString("None"); } +bool CPDF_ViewerPreferences::GenericName(const CFX_ByteString& bsKey, + CFX_ByteString* bsVal) const { + ASSERT(bsVal); + CPDF_Dictionary* pDict = GetViewerPreferences(); + if (!pDict) + return false; + + const CPDF_Name* pName = ToName(pDict->GetObjectFor(bsKey)); + if (!pName) + return false; + + *bsVal = pName->GetString(); + return true; +} + CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const { CPDF_Dictionary* pDict = m_pDoc->GetRoot(); return pDict ? pDict->GetDictFor("ViewerPreferences") : nullptr; diff --git a/core/fpdfdoc/cpdf_viewerpreferences.h b/core/fpdfdoc/cpdf_viewerpreferences.h index c64292d9f9..c7e9112380 100644 --- a/core/fpdfdoc/cpdf_viewerpreferences.h +++ b/core/fpdfdoc/cpdf_viewerpreferences.h @@ -25,6 +25,11 @@ class CPDF_ViewerPreferences { CPDF_Array* PrintPageRange() const; CFX_ByteString Duplex() const; + // Gets the entry for |bsKey|. If the entry exists and it is of type name, + // then this method writes the value into |bsVal| and returns true. Otherwise + // returns false and |bsVal| is untouched. |bsVal| must not be NULL. + bool GenericName(const CFX_ByteString& bsKey, CFX_ByteString* bsVal) const; + private: CPDF_Dictionary* GetViewerPreferences() const; -- cgit v1.2.3