summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/Document.cpp
diff options
context:
space:
mode:
authortonikitoo <tonikitoo@igalia.com>2016-08-18 20:10:17 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-18 20:10:17 -0700
commit618cb1f3e561b5d2a1dea9ec4653804f0da7267c (patch)
treea17067c25b751d6dfba46ab38114bd23a10ca2ff /fpdfsdk/javascript/Document.cpp
parent7996fe888cb98597cd1608af05fb59f45c837fc6 (diff)
downloadpdfium-618cb1f3e561b5d2a1dea9ec4653804f0da7267c.tar.xz
Add initial Document::getAnnot supportchromium/2833
CL implements the first step in order to support Annotations manipulation in PDFium: Document::getAnnot. The method takes two arguments, an integer (page number) and a string (annotation name). When called, it iterates over the annotations on the given page number, searching for the one whose name matches the string in the second parameter. If found, then an Annot instance (see Annot.cpp/g added by this CL), is bound to a Javascript object and returned. With the use cases described in bug [1] as an initial test case, CL adds support to the following Annotation object properties: - hidden - name - type Idea is to keep evolving the implementation with more methods and properties in follow up CLs. [1] https://bugs.chromium.org/p/pdfium/issues/detail?id=492 BUG=pdfium:492 Review-Url: https://codereview.chromium.org/2260663002
Diffstat (limited to 'fpdfsdk/javascript/Document.cpp')
-rw-r--r--fpdfsdk/javascript/Document.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index e38f61d5fc..8fb07b085b 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;
}