Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1005)

Unified Diff: fpdfsdk/src/fpdfview.cpp

Issue 834703002: Add APIs for getting bookmarks and named destinations. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« fpdfsdk/src/fpdfdoc.cpp ('K') | « fpdfsdk/src/fpdfdoc.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/fpdfview.cpp
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index d8ec8c676a077e53189adb8b6df247b61e36b2dc..c88c41d6a64c9078e2a77ca71717603c887279f1 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -788,6 +788,21 @@ 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 = (CPDF_Document*)document;
Tom Sepez 2015/01/01 01:10:08 nit: blank line here if you want to use one-line i
Bo Xu 2015/01/05 22:46:52 Done.
+ 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)
@@ -799,3 +814,42 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_
CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
return name_tree.LookupNamedDest(pDoc, name);
}
+
+DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, std::string& name)
+{
+ if (!document || index < 0) return NULL;
+ CPDF_Document* pDoc = (CPDF_Document*)document;
Tom Sepez 2015/01/01 01:10:08 nit: blank line.
Bo Xu 2015/01/05 22:46:52 Done.
+ CPDF_Dictionary* pRoot = pDoc->GetRoot();
+ if (!pRoot) return NULL;
+
+ CPDF_Object* pDestObj = NULL;
+ CFX_ByteString bsName;
+
Tom Sepez 2015/01/01 01:10:08 nit: no blank line
Bo Xu 2015/01/05 22:46:52 Done.
+ 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();
+ name = utf16Name.c_str();
+ return (FPDF_DEST)pDestObj;
+}
« fpdfsdk/src/fpdfdoc.cpp ('K') | « fpdfsdk/src/fpdfdoc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698