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

Unified Diff: fpdfsdk/javascript/Document.cpp

Issue 2221823003: Add support to Document::gotoNamedDest method. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 4 months 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
Index: fpdfsdk/javascript/Document.cpp
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 161a5d09e97d31b522e8c3fca38b86a86d9f6da3..fd476a3e57228aa5be2fde5f715b866a24953f16 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -10,9 +10,11 @@
#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
+#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
#include "core/fpdfdoc/include/cpdf_interform.h"
+#include "core/fpdfdoc/include/cpdf_nametree.h"
#include "fpdfsdk/include/fsdk_mgr.h"
#include "fpdfsdk/javascript/Field.h"
#include "fpdfsdk/javascript/Icon.h"
@@ -124,6 +126,7 @@ JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
JS_STATIC_METHOD_ENTRY(getPageNumWords)
JS_STATIC_METHOD_ENTRY(getPrintParams)
JS_STATIC_METHOD_ENTRY(getURL)
+JS_STATIC_METHOD_ENTRY(gotoNamedDest)
JS_STATIC_METHOD_ENTRY(importAnFDF)
JS_STATIC_METHOD_ENTRY(importAnXFDF)
JS_STATIC_METHOD_ENTRY(importTextData)
@@ -1466,6 +1469,52 @@ FX_BOOL Document::getURL(IJS_Context* cc,
return TRUE;
}
+FX_BOOL Document::gotoNamedDest(IJS_Context* cc,
+ const std::vector<CJS_Value>& params,
+ CJS_Value& vRet,
+ CFX_WideString& sError) {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ if (params.size() != 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
+ if (!pDocument)
+ return FALSE;
+
+ CFX_WideString wideName = params[0].ToCFXWideString();
+ CFX_ByteString utf16Name = wideName.UTF8Encode();
dsinclair 2016/08/08 20:05:29 What about CFX_ByteString utf16Name = params[0].To
+
+ CPDF_NameTree name_tree(pDocument, "Dests");
dsinclair 2016/08/08 20:05:29 nit: name_tree should probably be nameTree
+ CPDF_Array* destArray = name_tree.LookupNamedDest(pDocument, utf16Name);
+ if (!destArray)
+ return FALSE;
+
+ CPDF_Dest dest(destArray);
+
+ int nPageIndex = dest.GetPageIndex(pDocument);
+ int nFitType = dest.GetZoomMode();
+
+ const CPDF_Array* pMyArray = ToArray(dest.GetObject());
+ float* pPosAry = nullptr;
dsinclair 2016/08/08 20:05:29 Can float* pPosAry be a std::unique_ptr and then j
+ int sizeOfAry = 0;
+ if (pMyArray) {
+ pPosAry = new float[pMyArray->GetCount()];
+ int j = 0;
+ for (size_t i = 2; i < pMyArray->GetCount(); i++) {
+ pPosAry[j++] = pMyArray->GetFloatAt(i);
+ }
dsinclair 2016/08/08 20:05:29 nit: no {}'s
+ sizeOfAry = j;
+ }
+
+ CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
+ pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
dsinclair 2016/08/08 20:05:29 No need to store nFitType, just use dest.GetZoomMo
+ delete[] pPosAry;
dsinclair 2016/08/08 20:05:29 delete won't be needed after moving to a unique_pt
+
+ return TRUE;
+}
+
void Document::AddDelayData(CJS_DelayData* pData) {
m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData));
}

Powered by Google App Engine
This is Rietveld 408576698