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

Unified Diff: fpdfsdk/javascript/Document.cpp

Issue 2260663002: Add initial Document::getAnnot support (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix GYP build 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
« no previous file with comments | « fpdfsdk/javascript/Annot.cpp ('k') | fpdfsdk/javascript/cjs_runtime.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/javascript/Document.cpp
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index e38f61d5fca29d49ea5a83ce6834d7c31a75d284..8fb07b085b2c05f17315aafae3fdd87624073af7 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -15,9 +15,11 @@
#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/cpdfsdk_annotiterator.h"
#include "fpdfsdk/include/cpdfsdk_interform.h"
#include "fpdfsdk/include/cpdfsdk_widget.h"
#include "fpdfsdk/include/fsdk_mgr.h"
+#include "fpdfsdk/javascript/Annot.h"
#include "fpdfsdk/javascript/Field.h"
#include "fpdfsdk/javascript/Icon.h"
#include "fpdfsdk/javascript/JS_Define.h"
@@ -1029,6 +1031,50 @@ FX_BOOL Document::getAnnot(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ if (params.size() != 2) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ int nPageNo = params[0].ToInt(pRuntime);
+ CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime);
+
+ CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(nPageNo);
+ if (!pPageView)
+ return FALSE;
+
+ CPDFSDK_AnnotIterator annotIterator(pPageView, false);
+ CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr;
+ while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) {
+ CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur);
+ if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
+ pSDKBAAnnot = pBAAnnot;
+ break;
+ }
+ }
+
+ if (!pSDKBAAnnot)
+ return FALSE;
+
+ v8::Local<v8::Object> pObj =
+ pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID);
+ if (pObj.IsEmpty())
+ return FALSE;
+
+ CJS_Annot* pJS_Annot =
+ static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
+ if (!pJS_Annot)
+ return FALSE;
+
+ Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
+ if (!pAnnot)
+ return FALSE;
+
+ pAnnot->SetSDKAnnot(pSDKBAAnnot);
+
+ vRet = CJS_Value(pRuntime, pJS_Annot);
return TRUE;
}
« no previous file with comments | « fpdfsdk/javascript/Annot.cpp ('k') | fpdfsdk/javascript/cjs_runtime.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698