summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-15 16:17:18 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-15 16:17:18 -0700
commit471a1034e70ddcfc93ce2a93b28a8385109e83de (patch)
treec845fb1b73b936023be1fc2e7699ff4768aec652 /fpdfsdk
parentdfbf8e7ba55695c4e6cb30eadbe9c6a2955815ba (diff)
downloadpdfium-471a1034e70ddcfc93ce2a93b28a8385109e83de.tar.xz
Merge to XFA: Introduce CPDF_DocumentFromFPDFDocument().
Manual merges everywhere. Original Review URL: https://codereview.chromium.org/1395493007 . (cherry picked from commit bb51c4fb6bc6095984c303c95e5336f83e66bc67) Original Review URL: https://codereview.chromium.org/1396283006 . (cherry picked from commit 86adb658843658969041a13bf6cf0cc950ffe8ed) R=thestig@chromium.org Review URL: https://codereview.chromium.org/1395353004 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/include/fsdk_define.h3
-rw-r--r--fpdfsdk/src/fpdf_dataavail.cpp6
-rw-r--r--fpdfsdk/src/fpdf_ext.cpp6
-rw-r--r--fpdfsdk/src/fpdfdoc.cpp67
-rw-r--r--fpdfsdk/src/fpdfeditimg.cpp7
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp15
-rw-r--r--fpdfsdk/src/fpdfppo.cpp41
-rw-r--r--fpdfsdk/src/fpdfview.cpp101
8 files changed, 118 insertions, 128 deletions
diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h
index 8bf64bbe8d..c2aa0d9f32 100644
--- a/fpdfsdk/include/fsdk_define.h
+++ b/fpdfsdk/include/fsdk_define.h
@@ -91,6 +91,9 @@ class CFPDF_FileStream : public IFX_FileStream {
FX_FILESIZE m_nCurPos;
};
+// Conversions from FPDF_ types.
+CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc);
+
void DropContext(void* data);
void FSDK_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable);
FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy);
diff --git a/fpdfsdk/src/fpdf_dataavail.cpp b/fpdfsdk/src/fpdf_dataavail.cpp
index d3b44160a8..f09b173208 100644
--- a/fpdfsdk/src/fpdf_dataavail.cpp
+++ b/fpdfsdk/src/fpdf_dataavail.cpp
@@ -119,10 +119,8 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) {
}
DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc) {
- if (doc == NULL)
- return 0;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc();
- return ((CPDF_Parser*)pDoc->GetParser())->GetFirstPageNo();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
+ return pDoc ? pDoc->GetParser()->GetFirstPageNo() : 0;
}
DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail,
diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp
index f68a45f119..196ac99967 100644
--- a/fpdfsdk/src/fpdf_ext.cpp
+++ b/fpdfsdk/src/fpdf_ext.cpp
@@ -177,11 +177,11 @@ void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code) {
}
DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document) {
- if (!document)
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return PAGEMODE_UNKNOWN;
- CPDF_Dictionary* pRoot =
- (((CPDFXFA_Document*)document)->GetPDFDoc())->GetRoot();
+ CPDF_Dictionary* pRoot = pDoc->GetRoot();
if (!pRoot)
return PAGEMODE_UNKNOWN;
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index 568622b842..d4b6b08ff3 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -54,9 +54,9 @@ CPDF_LinkList* GetLinkList(CPDF_Page* page) {
DLLEXPORT FPDF_BOOKMARK STDCALL
FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
- if (!document)
- return NULL;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
CPDF_BookmarkTree tree(pDoc);
CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict);
return tree.GetFirstChild(bookmark).GetDict();
@@ -64,9 +64,11 @@ FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
DLLEXPORT FPDF_BOOKMARK STDCALL
FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) {
- if (!document || !pDict)
- return NULL;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ if (!pDict)
+ return nullptr;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
CPDF_BookmarkTree tree(pDoc);
CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict);
return tree.GetNextSibling(bookmark).GetDict();
@@ -89,11 +91,11 @@ DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict,
DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document,
FPDF_WIDESTRING title) {
- if (!document)
- return NULL;
if (!title || title[0] == 0)
- return NULL;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ return nullptr;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
CPDF_BookmarkTree tree(pDoc);
FX_STRSIZE len = CFX_WideString::WStringLength(title);
CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len);
@@ -102,12 +104,12 @@ DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document,
DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
FPDF_BOOKMARK pDict) {
- if (!document)
- return NULL;
if (!pDict)
- return NULL;
+ return nullptr;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict);
- CPDF_Document* pDoc = (CPDF_Document*)document;
CPDF_Dest dest = bookmark.GetDest(pDoc);
if (dest)
return dest.GetObject();
@@ -115,7 +117,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document,
// action
CPDF_Action action = bookmark.GetAction();
if (!action)
- return NULL;
+ return nullptr;
return action.GetDest(pDoc).GetObject();
}
@@ -148,10 +150,11 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetType(FPDF_ACTION pDict) {
DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document,
FPDF_ACTION pDict) {
- if (!document || !pDict)
+ if (!pDict)
+ return nullptr;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return nullptr;
-
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Action action((CPDF_Dictionary*)pDict);
return action.GetDest(pDoc).GetObject();
}
@@ -174,10 +177,11 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document,
FPDF_ACTION pDict,
void* buffer,
unsigned long buflen) {
- if (!document || !pDict)
+ if (!pDict)
+ return 0;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return 0;
-
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Action action((CPDF_Dictionary*)pDict);
CFX_ByteString path = action.GetURI(pDoc);
unsigned long len = path.GetLength() + 1;
@@ -188,10 +192,11 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document,
DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document,
FPDF_DEST pDict) {
- if (!document || !pDict)
+ if (!pDict)
+ return 0;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return 0;
-
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Dest dest((CPDF_Array*)pDict);
return dest.GetPageIndex(pDoc);
}
@@ -229,10 +234,11 @@ FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page, double x, double y) {
DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document,
FPDF_LINK pDict) {
- if (!document || !pDict)
+ if (!pDict)
+ return nullptr;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return nullptr;
-
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Link link((CPDF_Dictionary*)pDict);
FPDF_DEST dest = link.GetDest(pDoc).GetObject();
if (dest)
@@ -327,10 +333,11 @@ DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc,
FPDF_BYTESTRING tag,
void* buffer,
unsigned long buflen) {
- if (!doc || !tag)
+ if (!tag)
+ return 0;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
+ if (!pDoc)
return 0;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc();
- // Get info dictionary
CPDF_Dictionary* pInfo = pDoc->GetInfo();
if (!pInfo)
return 0;
diff --git a/fpdfsdk/src/fpdfeditimg.cpp b/fpdfsdk/src/fpdfeditimg.cpp
index 269b382d89..09295aa3c4 100644
--- a/fpdfsdk/src/fpdfeditimg.cpp
+++ b/fpdfsdk/src/fpdfeditimg.cpp
@@ -11,10 +11,11 @@
DLLEXPORT FPDF_PAGEOBJECT STDCALL
FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
- if (!document)
- return NULL;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
- CPDF_Image* pImg = new CPDF_Image(((CPDFXFA_Document*)document)->GetPDFDoc());
+ CPDF_Image* pImg = new CPDF_Image(pDoc);
pImageObj->m_pImage = pImg;
return pImageObj;
}
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index 145d8ca5c3..e7bbf05f4a 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -48,10 +48,8 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
}
DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) {
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
- if (pDoc == NULL)
- return;
- if (page_index < 0 || page_index >= pDoc->GetPageCount())
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc || page_index < 0 || page_index >= pDoc->GetPageCount())
return;
pDoc->DeletePage(page_index);
@@ -61,17 +59,14 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
int page_index,
double width,
double height) {
- if (!document)
- return NULL;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
- // CPDF_Parser* pParser = (CPDF_Parser*)document;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
if (page_index < 0)
page_index = 0;
if (pDoc->GetPageCount() < page_index)
page_index = pDoc->GetPageCount();
- // if (page_index < 0 || page_index >= pDoc->GetPageCount())
- // return NULL;
CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index);
if (!pPageDict)
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index d3899156a2..ed2446471e 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -380,12 +380,15 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,
FPDF_DOCUMENT src_doc,
FPDF_BYTESTRING pagerange,
int index) {
- if (dest_doc == NULL || src_doc == NULL)
+ CPDF_Document* pDestDoc = CPDFDocumentFromFPDFDocument(dest_doc);
+ if (!dest_doc)
+ return FALSE;
+
+ CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc);
+ if (!pSrcDoc)
return FALSE;
CFX_WordArray pageArray;
- CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
- CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
- int nCount = pSrcPDFDoc->GetPageCount();
+ int nCount = pSrcDoc->GetPageCount();
if (pagerange) {
if (ParserPageRangeString(pagerange, &pageArray, nCount) == FALSE)
return FALSE;
@@ -395,32 +398,30 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,
}
}
- CPDFXFA_Document* pDestDoc = (CPDFXFA_Document*)dest_doc;
- CPDF_Document* pDestPDFDoc = pDestDoc->GetPDFDoc();
CPDF_PageOrganizer pageOrg;
-
- pageOrg.PDFDocInit(pDestPDFDoc, pSrcPDFDoc);
-
- if (pageOrg.ExportPage(pSrcPDFDoc, &pageArray, pDestPDFDoc, index))
- return TRUE;
- return FALSE;
+ pageOrg.PDFDocInit(pDestDoc, pSrcDoc);
+ return pageOrg.ExportPage(pSrcDoc, &pageArray, pDestDoc, index);
}
DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc,
FPDF_DOCUMENT src_doc) {
- if (src_doc == NULL || dest_doc == NULL)
- return false;
- CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
- CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
- CPDF_Dictionary* pSrcDict = pSrcPDFDoc->GetRoot();
+ CPDF_Document* pDstDoc = CPDFDocumentFromFPDFDocument(dest_doc);
+ if (!pDstDoc)
+ return FALSE;
+
+ CPDF_Document* pSrcDoc = CPDFDocumentFromFPDFDocument(src_doc);
+ if (!pSrcDoc)
+ return FALSE;
+
+ CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot();
pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));
if (!pSrcDict)
return FALSE;
- CPDFXFA_Document* pDstDoc = (CPDFXFA_Document*)dest_doc;
- CPDF_Document* pDstPDFDoc = pDstDoc->GetPDFDoc();
- CPDF_Dictionary* pDstDict = pDstPDFDoc->GetRoot();
+
+ CPDF_Dictionary* pDstDict = pDstDoc->GetRoot();
if (!pDstDict)
return FALSE;
+
pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
return TRUE;
}
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index fc16147cfa..5d9bf4b252 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -22,6 +22,10 @@
#include "../include/fpdfxfa/fpdfxfa_util.h"
#include "../include/javascript/IJavaScript.h"
+CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
+ return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr;
+}
+
CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) {
m_pFS = pFS;
m_nCurPos = 0;
@@ -375,17 +379,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;
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)doc;
- CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
- if (!pPDFDoc)
- return (FX_DWORD)-1;
- CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc);
+ if (!pDoc)
+ return FALSE;
+ CPDF_Parser* pParser = pDoc->GetParser();
if (!pParser)
return FALSE;
+
*fileVersion = pParser->GetFileVersion();
return TRUE;
}
@@ -393,48 +398,37 @@ 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)
- return 0;
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
- CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
- if (!pPDFDoc)
- return (FX_DWORD)-1;
- CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser();
- CPDF_Dictionary* pDict = pParser->GetEncryptDict();
- if (pDict == NULL)
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return (FX_DWORD)-1;
- return pDict->GetInteger("P");
+ CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
+ return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1;
}
DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) {
- if (document == NULL)
- return -1;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
- CPDF_Dictionary* pDict = pParser->GetEncryptDict();
- if (pDict == NULL)
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return -1;
- return pDict->GetInteger("R");
+ CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict();
+ return pDict ? pDict->GetInteger("R") : -1;
}
DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) {
- if (document == NULL)
- return 0;
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
- return pDoc->GetPageCount();
- // return ((CPDF_Document*)document)->GetPageCount();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ return pDoc ? pDoc->GetPageCount() : 0;
}
DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
int page_index) {
- if (document == NULL)
- return NULL;
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
- if (page_index < 0 || page_index >= pDoc->GetPageCount())
- return NULL;
- // CPDF_Parser* pParser = (CPDF_Parser*)document;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
+
+ if (page_index < 0 || page_index >= FPDF_GetPageCount(document))
+ return nullptr;
+
return pDoc->GetPage(page_index);
}
@@ -673,11 +667,7 @@ DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) {
}
DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) {
- if (!document)
- return;
-
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
- delete pDoc;
+ delete CPDFDocumentFromFPDFDocument(document);
}
DLLEXPORT unsigned long STDCALL FPDF_GetLastError() {
@@ -899,18 +889,15 @@ DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
DLLEXPORT FPDF_BOOL STDCALL
FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) {
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return TRUE;
- CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
- if (!pPDFDoc)
- return TRUE;
- CPDF_ViewerPreferences viewRef(pPDFDoc);
+ CPDF_ViewerPreferences viewRef(pDoc);
return viewRef.PrintScaling();
}
DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return 1;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -919,7 +906,7 @@ DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) {
DLLEXPORT FPDF_PAGERANGE STDCALL
FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return NULL;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -928,7 +915,7 @@ FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) {
DLLEXPORT FPDF_DUPLEXTYPE STDCALL
FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
if (!pDoc)
return DuplexUndefined;
CPDF_ViewerPreferences viewRef(pDoc);
@@ -943,9 +930,9 @@ FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) {
}
DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) {
- if (!document)
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
return 0;
- CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Dictionary* pRoot = pDoc->GetRoot();
if (!pRoot)
@@ -961,17 +948,15 @@ 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;
- CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
- CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
- if (!pPDFDoc)
- return NULL;
- CPDF_NameTree name_tree(pPDFDoc, FX_BSTRC("Dests"));
- return name_tree.LookupNamedDest(pPDFDoc, name);
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return nullptr;
+
+ CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
+ return name_tree.LookupNamedDest(pDoc, name);
}
FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str) {