From 55bbb0a2e7a95bf2c08cbd1d7f1563aec7e5b97d Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 8 May 2018 19:26:37 +0000 Subject: Mark CPDF_Object pointers as const in CPDF_ViewerPreferences. Work up the short call stack and mark FPDF_PAGERANGE as an opaque const pointer. Also fix CPDF_ViewerPreferences::GenericName() to return an optional string. Change-Id: I2356d38888fcff8d4da37dd3efc17b284ff90485 Reviewed-on: https://pdfium-review.googlesource.com/32174 Commit-Queue: Lei Zhang Reviewed-by: dsinclair --- fpdfsdk/cpdfsdk_helpers.h | 6 +++--- fpdfsdk/fpdf_view.cpp | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'fpdfsdk') 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(mark); } -inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(CPDF_Array* range) { +inline FPDF_PAGERANGE FPDFPageRangeFromCPDFArray(const CPDF_Array* range) { return reinterpret_cast(range); } -inline CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) { - return reinterpret_cast(range); +inline const CPDF_Array* CPDFArrayFromFPDFPageRange(FPDF_PAGERANGE range) { + return reinterpret_cast(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 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 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; -- cgit v1.2.3