summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfdoc/cpdf_viewerpreferences.cpp30
-rw-r--r--core/fpdfdoc/cpdf_viewerpreferences.h15
2 files changed, 21 insertions, 24 deletions
diff --git a/core/fpdfdoc/cpdf_viewerpreferences.cpp b/core/fpdfdoc/cpdf_viewerpreferences.cpp
index e7fb1416a8..3359d6344f 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.cpp
+++ b/core/fpdfdoc/cpdf_viewerpreferences.cpp
@@ -9,52 +9,50 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_name.h"
-CPDF_ViewerPreferences::CPDF_ViewerPreferences(CPDF_Document* pDoc)
+CPDF_ViewerPreferences::CPDF_ViewerPreferences(const CPDF_Document* pDoc)
: m_pDoc(pDoc) {}
CPDF_ViewerPreferences::~CPDF_ViewerPreferences() {}
bool CPDF_ViewerPreferences::IsDirectionR2L() const {
- CPDF_Dictionary* pDict = GetViewerPreferences();
+ const CPDF_Dictionary* pDict = GetViewerPreferences();
return pDict ? pDict->GetStringFor("Direction") == "R2L" : false;
}
bool CPDF_ViewerPreferences::PrintScaling() const {
- CPDF_Dictionary* pDict = GetViewerPreferences();
+ const CPDF_Dictionary* pDict = GetViewerPreferences();
return pDict ? pDict->GetStringFor("PrintScaling") != "None" : true;
}
int32_t CPDF_ViewerPreferences::NumCopies() const {
- CPDF_Dictionary* pDict = GetViewerPreferences();
+ const CPDF_Dictionary* pDict = GetViewerPreferences();
return pDict ? pDict->GetIntegerFor("NumCopies") : 1;
}
-CPDF_Array* CPDF_ViewerPreferences::PrintPageRange() const {
- CPDF_Dictionary* pDict = GetViewerPreferences();
+const CPDF_Array* CPDF_ViewerPreferences::PrintPageRange() const {
+ const CPDF_Dictionary* pDict = GetViewerPreferences();
return pDict ? pDict->GetArrayFor("PrintPageRange") : nullptr;
}
ByteString CPDF_ViewerPreferences::Duplex() const {
- CPDF_Dictionary* pDict = GetViewerPreferences();
+ const CPDF_Dictionary* pDict = GetViewerPreferences();
return pDict ? pDict->GetStringFor("Duplex") : ByteString("None");
}
-bool CPDF_ViewerPreferences::GenericName(const ByteString& bsKey,
- ByteString* bsVal) const {
- ASSERT(bsVal);
- CPDF_Dictionary* pDict = GetViewerPreferences();
+Optional<ByteString> CPDF_ViewerPreferences::GenericName(
+ const ByteString& bsKey) const {
+ const CPDF_Dictionary* pDict = GetViewerPreferences();
if (!pDict)
- return false;
+ return {};
const CPDF_Name* pName = ToName(pDict->GetObjectFor(bsKey));
if (!pName)
- return false;
+ return {};
- *bsVal = pName->GetString();
- return true;
+ return pName->GetString();
}
-CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const {
+const CPDF_Dictionary* CPDF_ViewerPreferences::GetViewerPreferences() const {
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 a1884748e4..45e4390065 100644
--- a/core/fpdfdoc/cpdf_viewerpreferences.h
+++ b/core/fpdfdoc/cpdf_viewerpreferences.h
@@ -10,6 +10,7 @@
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/optional.h"
class CPDF_Array;
class CPDF_Dictionary;
@@ -17,24 +18,22 @@ class CPDF_Document;
class CPDF_ViewerPreferences {
public:
- explicit CPDF_ViewerPreferences(CPDF_Document* pDoc);
+ explicit CPDF_ViewerPreferences(const CPDF_Document* pDoc);
~CPDF_ViewerPreferences();
bool IsDirectionR2L() const;
bool PrintScaling() const;
int32_t NumCopies() const;
- CPDF_Array* PrintPageRange() const;
+ const CPDF_Array* PrintPageRange() const;
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 ByteString& bsKey, ByteString* bsVal) const;
+ // Gets the entry for |bsKey|.
+ Optional<ByteString> GenericName(const ByteString& bsKey) const;
private:
- CPDF_Dictionary* GetViewerPreferences() const;
+ const CPDF_Dictionary* GetViewerPreferences() const;
- UnownedPtr<CPDF_Document> const m_pDoc;
+ UnownedPtr<const CPDF_Document> const m_pDoc;
};
#endif // CORE_FPDFDOC_CPDF_VIEWERPREFERENCES_H_