From 0ee35908e906922a423fb18d7085ef80d0d8d8c8 Mon Sep 17 00:00:00 2001 From: tonikitoo Date: Fri, 26 Aug 2016 14:41:29 -0700 Subject: Add support to Document::getAnnots method Although notably, the parameters handling support is not complete, CL intends to be the first step towards a more complete implementation of this API. TEST=testing/resources/javascript/bug_492_1.in BUG=pdfium:492 Review-Url: https://codereview.chromium.org/2281273002 --- fpdfsdk/javascript/Document.cpp | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'fpdfsdk/javascript/Document.cpp') diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 8fb9ce60dc..c1381f5865 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -1090,7 +1090,48 @@ FX_BOOL Document::getAnnots(IJS_Context* cc, const std::vector& params, CJS_Value& vRet, CFX_WideString& sError) { - vRet.SetNull(CJS_Runtime::FromContext(cc)); + CJS_Context* pContext = static_cast(cc); + + // TODO(tonikitoo): Add support supported parameters as per + // the PDF spec. + + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + + int nPageNo = m_pDocument->GetPageCount(); + CJS_Array annots; + + for (int i = 0; i < nPageNo; ++i) { + CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(i); + if (!pPageView) + return FALSE; + + CPDFSDK_AnnotIterator annotIterator(pPageView, false); + while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { + CPDFSDK_BAAnnot* pSDKBAAnnot = + static_cast(pSDKAnnotCur); + if (!pSDKBAAnnot) + return FALSE; + + v8::Local pObj = + pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); + if (pObj.IsEmpty()) + return FALSE; + + CJS_Annot* pJS_Annot = + static_cast(pRuntime->GetObjectPrivate(pObj)); + if (!pJS_Annot) + return FALSE; + + Annot* pAnnot = static_cast(pJS_Annot->GetEmbedObject()); + if (!pAnnot) + return FALSE; + + pAnnot->SetSDKAnnot(pSDKBAAnnot); + annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot)); + } + } + + vRet = CJS_Value(pRuntime, annots); return TRUE; } -- cgit v1.2.3