diff options
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r-- | fpdfsdk/src/fpdfdoc.cpp | 36 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfview.cpp | 77 |
2 files changed, 107 insertions, 6 deletions
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp index f2a190bc67..23c3c2e713 100644 --- a/fpdfsdk/src/fpdfdoc.cpp +++ b/fpdfsdk/src/fpdfdoc.cpp @@ -29,6 +29,42 @@ static CPDF_Bookmark FindBookmark(const CPDF_BookmarkTree& tree, CPDF_Bookmark b return CPDF_Bookmark(); } +DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) +{ + if (!document || !pDict) + return NULL; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); + CPDF_BookmarkTree tree(pDoc); + CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); + return tree.GetFirstChild(bookmark).GetDict(); +} + +DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK pDict) +{ + if (!document || !pDict) + return NULL; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); + CPDF_BookmarkTree tree(pDoc); + CPDF_Bookmark bookmark = CPDF_Bookmark((CPDF_Dictionary*)pDict); + return tree.GetNextSibling(bookmark).GetDict(); +} + +DLLEXPORT unsigned long STDCALL FPDFBookmark_GetTitle(FPDF_BOOKMARK pDict, void* buffer, unsigned long buflen) +{ + if (!pDict) + return 0; + CPDF_Bookmark bookmark((CPDF_Dictionary*)pDict); + CFX_WideString title = bookmark.GetTitle(); + CFX_ByteString encodedTitle = title.UTF16LE_Encode(FALSE); + unsigned long len = encodedTitle.GetLength(); + if (buffer && buflen >= len + 2) { + FXSYS_memcpy(buffer, encodedTitle.c_str(), len); + ((FX_BYTE*)buffer)[len] = 0; + ((FX_BYTE*)buffer)[len + 1] = 0; + } + return len + 2; +} + DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title) { if (!document) diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index f8f7a28940..291b9f6d94 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -422,7 +422,7 @@ DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { if (document == NULL) return -1; - CPDF_Document*pDoc = (CPDF_Document*)document; + CPDF_Document*pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); CPDF_Dictionary* pDict = pParser->GetEncryptDict(); if (pDict == NULL) return -1; @@ -900,7 +900,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT documen DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document) { - CPDF_Document* pDoc = (CPDF_Document*)document; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); if (!pDoc) return 1; CPDF_ViewerPreferences viewRef(pDoc); return viewRef.NumCopies(); @@ -908,7 +908,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 = ((CPDFXFA_Document*)document)->GetPDFDoc(); if (!pDoc) return NULL; CPDF_ViewerPreferences viewRef(pDoc); return viewRef.PrintPageRange(); @@ -916,7 +916,7 @@ DLLEXPORT FPDF_PAGERANGE STDCALL FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT DLLEXPORT FPDF_DUPLEXTYPE STDCALL FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { - CPDF_Document* pDoc = (CPDF_Document*)document; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); if (!pDoc) return DuplexUndefined; CPDF_ViewerPreferences viewRef(pDoc); CFX_ByteString duplex = viewRef.Duplex(); @@ -929,11 +929,27 @@ DLLEXPORT FPDF_DUPLEXTYPE STDCALL FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT documen return DuplexUndefined; } +DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) +{ + if (!document) return 0; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); + + CPDF_Dictionary* pRoot = pDoc->GetRoot(); + if (!pRoot) return 0; + + CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); + int count = nameTree.GetCount(); + CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); + if (pDest) + count += pDest->GetCount(); + return count; +} + DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_BYTESTRING name) { - if (document == NULL) + if (!document) return NULL; - if (name == NULL || name[0] == 0) + if (!name || name[0] == 0) return NULL; CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; @@ -1000,3 +1016,52 @@ FPDF_RESULT FPDF_BStr_Clear(FPDF_BSTR* str) str->len = 0; return 0; } + +DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, unsigned long& buflen) +{ + if (!buffer) + buflen = 0; + if (!document || index < 0) return NULL; + CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); + + CPDF_Dictionary* pRoot = pDoc->GetRoot(); + if (!pRoot) return NULL; + + CPDF_Object* pDestObj = NULL; + CFX_ByteString bsName; + CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); + int count = nameTree.GetCount(); + if (index >= count) { + CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); + if (!pDest) return NULL; + if (index >= count + pDest->GetCount()) return NULL; + index -= count; + FX_POSITION pos = pDest->GetStartPos(); + int i = 0; + while (pos) { + pDestObj = pDest->GetNextElement(pos, bsName); + if (!pDestObj) continue; + if (i == index) break; + i++; + } + } else { + pDestObj = nameTree.LookupValue(index, bsName); + } + if (!pDestObj) return NULL; + if (pDestObj->GetType() == PDFOBJ_DICTIONARY) + pDestObj = ((CPDF_Dictionary*)pDestObj)->GetArray(FX_BSTRC("D")); + if (pDestObj->GetType() != PDFOBJ_ARRAY) return NULL; + CFX_WideString wsName = PDF_DecodeText(bsName); + CFX_ByteString utf16Name = wsName.UTF16LE_Encode(); + unsigned int len = utf16Name.GetLength(); + if (!buffer) { + buflen = len + 2; + } else if (buflen >= len + 2) { + memcpy(buffer, utf16Name.c_str(), len); + ((FX_BYTE*)buffer)[len] = 0; + ((FX_BYTE*)buffer)[len + 1] = 0; + } else { + len = -1; + } + return (FPDF_DEST)pDestObj; +} |