summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/fpdfview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/fpdfview.cpp')
-rw-r--r--fpdfsdk/src/fpdfview.cpp79
1 files changed, 40 insertions, 39 deletions
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 84dabe6864..a1d84732af 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -218,13 +218,18 @@ FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess,
DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
int* fileVersion) {
- if (!doc || !fileVersion)
+ if (!fileVersion)
return FALSE;
+
*fileVersion = 0;
- CPDF_Document* pDoc = (CPDF_Document*)doc;
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(doc);
+ if (!pDoc)
+ return FALSE;
+
CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
if (!pParser)
return FALSE;
+
*fileVersion = pParser->GetFileVersion();
return TRUE;
}
@@ -232,45 +237,39 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
// jabdelmalek: changed return type from FX_DWORD to build on Linux (and match
// header).
DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) {
- if (document == NULL)
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
return 0;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+
CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
CPDF_Dictionary* pDict = pParser->GetEncryptDict();
- if (pDict == NULL)
- return (FX_DWORD)-1;
-
- return pDict->GetInteger("P");
+ return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
}
DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
- if (document == NULL)
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
return -1;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+
CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
CPDF_Dictionary* pDict = pParser->GetEncryptDict();
- if (pDict == NULL)
- return -1;
-
- return pDict->GetInteger("R");
+ return pDict ? pDict->GetInteger("R") : -1;
}
DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
- if (document == NULL)
- return 0;
- return ((CPDF_Document*)document)->GetPageCount();
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ return pDoc ? pDoc->GetPageCount() : 0;
}
DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
int page_index) {
- if (document == NULL)
- return NULL;
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
+
if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
- return NULL;
+ return nullptr;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (pDoc == NULL)
- return NULL;
CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
if (pDict == NULL)
return NULL;
@@ -513,11 +512,12 @@ DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
}
DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
- if (!document)
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
return;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+
CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
- if (pParser == NULL) {
+ if (!pParser) {
delete pDoc;
return;
}
@@ -745,12 +745,12 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
int page_index,
double* width,
double* height) {
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (pDoc == NULL)
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
return FALSE;
CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
- if (pDict == NULL)
+ if (!pDict)
return FALSE;
CPDF_Page page;
@@ -763,7 +763,7 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
DLLEXPORT FPDF_BOOL STDCALL
FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
if (!pDoc)
return TRUE;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -771,7 +771,7 @@ FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
}
DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
if (!pDoc)
return 1;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -780,7 +780,7 @@ DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
DLLEXPORT FPDF_PAGERANGE STDCALL
FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
if (!pDoc)
return NULL;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -789,7 +789,7 @@ FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
DLLEXPORT FPDF_DUPLEXTYPE STDCALL
FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
if (!pDoc)
return DuplexUndefined;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -804,9 +804,9 @@ FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
}
DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
- if (!document)
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
return 0;
- CPDF_Document* pDoc = (CPDF_Document*)document;
CPDF_Dictionary* pRoot = pDoc->GetRoot();
if (!pRoot)
@@ -822,12 +822,13 @@ DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
FPDF_BYTESTRING name) {
- if (!document)
- return NULL;
if (!name || name[0] == 0)
- return NULL;
+ return nullptr;
+
+ CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
- CPDF_Document* pDoc = (CPDF_Document*)document;
CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
return name_tree.LookupNamedDest(pDoc, name);
}