diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-10-14 16:34:46 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-10-14 16:34:46 -0700 |
commit | bb51c4fb6bc6095984c303c95e5336f83e66bc67 (patch) | |
tree | aa95c7948b60a9935c0d83e449d2aef5658e1ff2 | |
parent | eca866c64ec0319d4723798290a3155957fa733e (diff) | |
download | pdfium-bb51c4fb6bc6095984c303c95e5336f83e66bc67.tar.xz |
Introduce CPDF_Document::FromFPDFDocument().
This will be used to abstract one major difference between master
and XFA, namely that the CPDF_Document is not a direct cast in XFA.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1395493007 .
-rw-r--r-- | core/include/fpdfapi/fpdf_parser.h | 3 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_dataavail.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/src/fpdf_ext.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfdoc.cpp | 67 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfeditimg.cpp | 7 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfeditpage.cpp | 15 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfformfill.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfppo.cpp | 24 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfsave.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview.cpp | 79 |
11 files changed, 118 insertions, 99 deletions
diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index 04c7d90f6f..b58cf14974 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -7,6 +7,7 @@ #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ +#include "../../../public/fpdfview.h" #include "../fxcrt/fx_system.h" #include "fpdf_objects.h" @@ -56,6 +57,8 @@ extern const FX_WORD PDFDocEncoding[256]; class CPDF_Document : public CFX_PrivateData, public CPDF_IndirectObjects { public: + static CPDF_Document* FromFPDFDocument(FPDF_DOCUMENT document); + CPDF_Document(); explicit CPDF_Document(CPDF_Parser* pParser); diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp index 5b78013694..b93cadd266 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_document.cpp @@ -7,6 +7,11 @@ #include "../../../include/fpdfapi/fpdf_parser.h" #include "../../../include/fpdfapi/fpdf_module.h" +// static +CPDF_Document* CPDF_Document::FromFPDFDocument(FPDF_DOCUMENT document) { + return static_cast<CPDF_Document*>(document); +} + CPDF_Document::CPDF_Document(CPDF_Parser* pParser) : CPDF_IndirectObjects(pParser) { ASSERT(pParser != NULL); diff --git a/fpdfsdk/src/fpdf_dataavail.cpp b/fpdfsdk/src/fpdf_dataavail.cpp index 5343723476..3944f67b03 100644 --- a/fpdfsdk/src/fpdf_dataavail.cpp +++ b/fpdfsdk/src/fpdf_dataavail.cpp @@ -115,9 +115,9 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { } DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc) { - if (doc == NULL) + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(doc); + if (!doc) return 0; - CPDF_Document* pDoc = (CPDF_Document*)doc; return ((CPDF_Parser*)pDoc->GetParser())->GetFirstPageNo(); } diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp index 2d84ff2a50..1cc1829914 100644 --- a/fpdfsdk/src/fpdf_ext.cpp +++ b/fpdfsdk/src/fpdf_ext.cpp @@ -183,10 +183,11 @@ void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code) { } DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document) { - if (!document) + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) return PAGEMODE_UNKNOWN; - CPDF_Dictionary* pRoot = ((CPDF_Document*)document)->GetRoot(); + CPDF_Dictionary* pRoot = pDoc->GetRoot(); if (!pRoot) return PAGEMODE_UNKNOWN; diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp index 4e2e7f3d0b..ffdad281c6 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -52,9 +52,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 = (CPDF_Document*)document; + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) + return nullptr; CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); return tree.GetFirstChild(bookmark).GetDict(); @@ -62,9 +62,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 = (CPDF_Document*)document; + if (!pDict) + return nullptr; + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) + return nullptr; CPDF_BookmarkTree tree(pDoc); CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); return tree.GetNextSibling(bookmark).GetDict(); @@ -87,11 +89,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 = (CPDF_Document*)document; + return nullptr; + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) + return nullptr; CPDF_BookmarkTree tree(pDoc); FX_STRSIZE len = CFX_WideString::WStringLength(title); CFX_WideString encodedTitle = CFX_WideString::FromUTF16LE(title, len); @@ -100,12 +102,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 = CPDF_Document::FromFPDFDocument(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(); @@ -113,7 +115,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(); } @@ -146,10 +148,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 = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) return nullptr; - - CPDF_Document* pDoc = (CPDF_Document*)document; CPDF_Action action((CPDF_Dictionary*)pDict); return action.GetDest(pDoc).GetObject(); } @@ -172,10 +175,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 = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) return 0; - - CPDF_Document* pDoc = (CPDF_Document*)document; CPDF_Action action((CPDF_Dictionary*)pDict); CFX_ByteString path = action.GetURI(pDoc); unsigned long len = path.GetLength() + 1; @@ -186,10 +190,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 = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) return 0; - - CPDF_Document* pDoc = (CPDF_Document*)document; CPDF_Dest dest((CPDF_Array*)pDict); return dest.GetPageIndex(pDoc); } @@ -219,10 +224,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 = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) return nullptr; - - CPDF_Document* pDoc = (CPDF_Document*)document; CPDF_Link link((CPDF_Dictionary*)pDict); FPDF_DEST dest = link.GetDest(pDoc).GetObject(); if (dest) @@ -317,10 +323,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 = CPDF_Document::FromFPDFDocument(doc); + if (!pDoc) return 0; - CPDF_Document* pDoc = (CPDF_Document*)doc; - // 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 bb710789cc..ef0576b602 100644 --- a/fpdfsdk/src/fpdfeditimg.cpp +++ b/fpdfsdk/src/fpdfeditimg.cpp @@ -9,10 +9,11 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { - if (!document) - return NULL; + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) + return nullptr; CPDF_ImageObject* pImageObj = new CPDF_ImageObject; - CPDF_Image* pImg = new CPDF_Image((CPDF_Document*)document); + 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 8796d0e2b1..574fa399c5 100644 --- a/fpdfsdk/src/fpdfeditpage.cpp +++ b/fpdfsdk/src/fpdfeditpage.cpp @@ -44,10 +44,8 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() { } DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index) { - CPDF_Document* pDoc = (CPDF_Document*)document; - if (pDoc == NULL) - return; - if (page_index < 0 || page_index >= pDoc->GetPageCount()) + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc || page_index < 0 || page_index >= pDoc->GetPageCount()) return; pDoc->DeletePage(page_index); @@ -57,17 +55,14 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index, double width, double height) { - if (!document) - return NULL; + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); + if (!pDoc) + return nullptr; - // CPDF_Parser* pParser = (CPDF_Parser*)document; - CPDF_Document* pDoc = (CPDF_Document*)document; 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/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp index 37af1fbf95..fed9a7e97e 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -79,10 +79,12 @@ DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo) { - if (!document || !formInfo || formInfo->version != 1) + if (!formInfo || formInfo->version != 1) return nullptr; - CPDF_Document* pDocument = (CPDF_Document*)document; + CPDF_Document* pDocument = CPDF_Document::FromFPDFDocument(document); + if (!pDocument) + return nullptr; CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); return pEnv; diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp index a37772492f..50ed6607d5 100644 --- a/fpdfsdk/src/fpdfppo.cpp +++ b/fpdfsdk/src/fpdfppo.cpp @@ -369,11 +369,15 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, FPDF_DOCUMENT src_doc, FPDF_BYTESTRING pagerange, int index) { - if (!dest_doc || !src_doc) + CPDF_Document* pDestDoc = CPDF_Document::FromFPDFDocument(dest_doc); + if (!dest_doc) + return FALSE; + + CPDF_Document* pSrcDoc = CPDF_Document::FromFPDFDocument(src_doc); + if (!pSrcDoc) return FALSE; CFX_WordArray pageArray; - CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc; int nCount = pSrcDoc->GetPageCount(); if (pagerange) { if (!ParserPageRangeString(pagerange, &pageArray, nCount)) @@ -384,30 +388,30 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc, } } - CPDF_Document* pDestDoc = (CPDF_Document*)dest_doc; CPDF_PageOrganizer pageOrg; - 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 || !dest_doc) - return false; + CPDF_Document* pDstDoc = CPDF_Document::FromFPDFDocument(dest_doc); + if (!pDstDoc) + return FALSE; + + CPDF_Document* pSrcDoc = CPDF_Document::FromFPDFDocument(src_doc); + if (!pSrcDoc) + return FALSE; - CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc; CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot(); pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences")); - ; if (!pSrcDict) return FALSE; - CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc; CPDF_Dictionary* pDstDict = pDstDoc->GetRoot(); if (!pDstDict) return FALSE; + pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); return TRUE; } diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp index 36553092ee..e0f239828d 100644 --- a/fpdfsdk/src/fpdfsave.cpp +++ b/fpdfsdk/src/fpdfsave.cpp @@ -56,7 +56,7 @@ FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, FPDF_DWORD flags, FPDF_BOOL bSetVersion, int fileVerion) { - CPDF_Document* pDoc = (CPDF_Document*)document; + CPDF_Document* pDoc = CPDF_Document::FromFPDFDocument(document); if (!pDoc) return 0; 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); } |