summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfdoc/cpdf_viewerpreferences.cpp30
-rw-r--r--core/fpdfdoc/cpdf_viewerpreferences.h15
-rw-r--r--fpdfsdk/cpdfsdk_helpers.h6
-rw-r--r--fpdfsdk/fpdf_view.cpp26
-rw-r--r--public/fpdfview.h2
5 files changed, 38 insertions, 41 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_
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index 0cd2617412..214fa72ab1 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -154,11 +154,11 @@ inline const CPDF_ContentMarkItem* CPDFContentMarkItemFromFPDFPageObjectMark(
return reinterpret_cast<const CPDF_ContentMarkItem*>(mark);
}
-inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(CPDF_Array* range) {
+inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(const CPDF_Array* range) {
return reinterpret_cast<FPDF_PAGERANGE>(range);
}
-inline CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) {
- return reinterpret_cast<CPDF_Array*>(range);
+inline const CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) {
+ return reinterpret_cast<const CPDF_Array*>(range);
}
inline FPDF_PATHSEGMENT FPDFPathSegmentFromFXPathPoint(
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 22cb62ea6e..6c4ad6020e 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -243,11 +243,11 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetFormType(FPDF_DOCUMENT document) {
if (!pRoot)
return FORMTYPE_NONE;
- CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
+ const CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm");
if (!pAcroForm)
return FORMTYPE_NONE;
- CPDF_Object* pXFA = pAcroForm->GetObjectFor("XFA");
+ const CPDF_Object* pXFA = pAcroForm->GetObjectFor("XFA");
if (!pXFA)
return FORMTYPE_ACRO_FORM;
@@ -978,7 +978,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return true;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -987,7 +987,7 @@ FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
FPDF_EXPORT int FPDF_CALLCONV
FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 1;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -996,7 +996,7 @@ FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV
FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return nullptr;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -1020,7 +1020,7 @@ FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange,
FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV
FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return DuplexUndefined;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -1039,18 +1039,18 @@ FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document,
FPDF_BYTESTRING key,
char* buffer,
unsigned long length) {
- CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ const CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 0;
CPDF_ViewerPreferences viewRef(pDoc);
- ByteString bsVal;
- if (!viewRef.GenericName(key, &bsVal))
+ Optional<ByteString> bsVal = viewRef.GenericName(key);
+ if (!bsVal)
return 0;
- unsigned long dwStringLen = bsVal.GetLength() + 1;
+ unsigned long dwStringLen = bsVal->GetLength() + 1;
if (buffer && length >= dwStringLen)
- memcpy(buffer, bsVal.c_str(), dwStringLen);
+ memcpy(buffer, bsVal->c_str(), dwStringLen);
return dwStringLen;
}
@@ -1066,7 +1066,7 @@ FPDF_CountNamedDests(FPDF_DOCUMENT document) {
CPDF_NameTree nameTree(pDoc, "Dests");
pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount();
- CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests");
+ const CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests");
if (pDest)
count += pDest->GetCount();
@@ -1161,7 +1161,7 @@ FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDest(FPDF_DOCUMENT document,
CPDF_NameTree nameTree(pDoc, "Dests");
int count = nameTree.GetCount();
if (index >= count) {
- CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests");
+ const CPDF_Dictionary* pDest = pRoot->GetDictFor("Dests");
if (!pDest)
return nullptr;
diff --git a/public/fpdfview.h b/public/fpdfview.h
index 7758facc39..66813d8bb4 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -49,7 +49,7 @@ typedef struct fpdf_page_t__* FPDF_PAGE;
typedef struct fpdf_pagelink_t__* FPDF_PAGELINK;
typedef struct fpdf_pageobject_t__* FPDF_PAGEOBJECT; // (text, path, etc.)
typedef const struct fpdf_pageobjectmark_t__* FPDF_PAGEOBJECTMARK;
-typedef struct fpdf_pagerange_t__* FPDF_PAGERANGE;
+typedef const struct fpdf_pagerange_t__* FPDF_PAGERANGE;
typedef const struct fpdf_pathsegment_t* FPDF_PATHSEGMENT;
typedef void* FPDF_RECORDER; // Passed into skia.
typedef struct fpdf_schhandle_t__* FPDF_SCHHANDLE;