diff options
Diffstat (limited to 'fpdfsdk/javascript')
-rw-r--r-- | fpdfsdk/javascript/Annot.cpp | 89 | ||||
-rw-r--r-- | fpdfsdk/javascript/Annot.h | 39 | ||||
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 46 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_runtime.cpp | 4 |
4 files changed, 177 insertions, 1 deletions
diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp new file mode 100644 index 0000000000..df123274d5 --- /dev/null +++ b/fpdfsdk/javascript/Annot.cpp @@ -0,0 +1,89 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/javascript/Annot.h" + +#include "fpdfsdk/javascript/JS_Define.h" +#include "fpdfsdk/javascript/JS_Object.h" +#include "fpdfsdk/javascript/JS_Value.h" +#include "fpdfsdk/javascript/cjs_context.h" + +BEGIN_JS_STATIC_CONST(CJS_Annot) +END_JS_STATIC_CONST() + +BEGIN_JS_STATIC_PROP(CJS_Annot) +JS_STATIC_PROP_ENTRY(hidden) +JS_STATIC_PROP_ENTRY(name) +JS_STATIC_PROP_ENTRY(type) +END_JS_STATIC_PROP() + +BEGIN_JS_STATIC_METHOD(CJS_Annot) +END_JS_STATIC_METHOD() + +IMPLEMENT_JS_CLASS(CJS_Annot, Annot) + +Annot::Annot(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} + +Annot::~Annot() {} + +FX_BOOL Annot::hidden(IJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + CPDF_Annot* pPDFAnnot = m_BAAnnot->GetPDFAnnot(); + vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()); + return TRUE; + } + + bool bHidden; + vp >> bHidden; + + uint32_t flags = m_BAAnnot->GetFlags(); + if (bHidden) { + flags |= ANNOTFLAG_HIDDEN; + flags |= ANNOTFLAG_INVISIBLE; + flags |= ANNOTFLAG_NOVIEW; + flags &= ~ANNOTFLAG_PRINT; + } else { + flags &= ~ANNOTFLAG_HIDDEN; + flags &= ~ANNOTFLAG_INVISIBLE; + flags &= ~ANNOTFLAG_NOVIEW; + flags |= ANNOTFLAG_PRINT; + } + m_BAAnnot->SetFlags(flags); + return TRUE; +} + +FX_BOOL Annot::name(IJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << m_BAAnnot->GetAnnotName(); + return TRUE; + } + + CFX_WideString annotName; + vp >> annotName; + m_BAAnnot->SetAnnotName(annotName); + return TRUE; +} + +FX_BOOL Annot::type(IJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast<CJS_Context*>(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } + + vp << m_BAAnnot->GetType(); + return TRUE; +} + +void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) { + m_BAAnnot = annot; +} diff --git a/fpdfsdk/javascript/Annot.h b/fpdfsdk/javascript/Annot.h new file mode 100644 index 0000000000..b3ea292aed --- /dev/null +++ b/fpdfsdk/javascript/Annot.h @@ -0,0 +1,39 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_JAVASCRIPT_ANNOT_H_ +#define FPDFSDK_JAVASCRIPT_ANNOT_H_ + +#include "fpdfsdk/include/cpdfsdk_baannot.h" +#include "fpdfsdk/javascript/JS_Define.h" + +class Annot : public CJS_EmbedObj { + public: + explicit Annot(CJS_Object* pJSObject); + ~Annot() override; + + FX_BOOL hidden(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); + FX_BOOL name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); + FX_BOOL type(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); + + void SetSDKAnnot(CPDFSDK_BAAnnot* annot); + + private: + CPDFSDK_BAAnnot* m_BAAnnot = nullptr; +}; + +class CJS_Annot : public CJS_Object { + public: + explicit CJS_Annot(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} + ~CJS_Annot() override {} + + DECLARE_JS_CLASS(); + JS_STATIC_PROP(hidden, Annot); + JS_STATIC_PROP(name, Annot); + JS_STATIC_PROP(type, Annot); +}; + +#endif // FPDFSDK_JAVASCRIPT_ANNOT_H_ 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; } diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index 7ea9b158a5..b12a3f5eeb 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -9,6 +9,7 @@ #include <algorithm> #include "fpdfsdk/include/fsdk_mgr.h" +#include "fpdfsdk/javascript/Annot.h" #include "fpdfsdk/javascript/Consts.h" #include "fpdfsdk/javascript/Document.h" #include "fpdfsdk/javascript/Field.h" @@ -175,9 +176,10 @@ void CJS_Runtime::DefineJSObjects() { CJS_GlobalConsts::DefineJSObjects(this); CJS_GlobalArrays::DefineJSObjects(this); - // ObjDefIDs 21 - 22. + // ObjDefIDs 21 - 23. CJS_TimerObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); CJS_PrintParamsObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); + CJS_Annot::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC); } IJS_Context* CJS_Runtime::NewContext() { |