blob: 3f55058fad9993c1e7633cd8be2641090c24f29c [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../../include/javascript/JavaScript.h"
8#include "../../include/javascript/IJavaScript.h"
9#include "../../include/javascript/JS_Define.h"
10#include "../../include/javascript/JS_Object.h"
11#include "../../include/javascript/JS_Value.h"
12#include "../../include/javascript/Document.h"
13#include "../../include/javascript/JS_EventHandler.h"
14#include "../../include/javascript/JS_Context.h"
15#include "../../include/javascript/JS_Runtime.h"
16#include "../../include/javascript/app.h"
17#include "../../include/javascript/Field.h"
18#include "../../include/javascript/Icon.h"
Tom Sepez3a832662015-03-02 12:59:05 -080019#include "../../include/javascript/resource.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Tom Sepez35425892015-02-05 10:03:18 -080021#include "../../../third_party/base/numerics/safe_math.h"
Chris Palmer9108ad22014-06-26 16:01:46 -070022
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023static v8::Isolate* GetIsolate(IFXJS_Context* cc)
24{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070025 CJS_Context* pContext = (CJS_Context *)cc;
26 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Tom Sepez2f2ffec2015-07-23 14:42:09 -070028 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
29 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Tom Sepez2f2ffec2015-07-23 14:42:09 -070031 return pRuntime->GetIsolate();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032}
33
34BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
35END_JS_STATIC_CONST()
36
37BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
38END_JS_STATIC_PROP()
39
40BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
41END_JS_STATIC_METHOD()
42
43IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
44
45PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
46: CJS_EmbedObj(pJSObject)
47{
Tom Sepez2f2ffec2015-07-23 14:42:09 -070048 bUI = TRUE;
49 nStart = 0;
50 nEnd = 0;
51 bSilent = FALSE;
52 bShrinkToFit = FALSE;
53 bPrintAsImage = FALSE;
54 bReverse = FALSE;
55 bAnnotations = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056}
57
58/* ---------------------- Document ---------------------- */
59
60#define MINWIDTH 5.0f
61#define MINHEIGHT 5.0f
62
63BEGIN_JS_STATIC_CONST(CJS_Document)
64END_JS_STATIC_CONST()
65
66BEGIN_JS_STATIC_PROP(CJS_Document)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070067 JS_STATIC_PROP_ENTRY(ADBE)
68 JS_STATIC_PROP_ENTRY(author)
69 JS_STATIC_PROP_ENTRY(baseURL)
70 JS_STATIC_PROP_ENTRY(bookmarkRoot)
71 JS_STATIC_PROP_ENTRY(calculate)
72 JS_STATIC_PROP_ENTRY(Collab)
73 JS_STATIC_PROP_ENTRY(creationDate)
74 JS_STATIC_PROP_ENTRY(creator)
75 JS_STATIC_PROP_ENTRY(delay)
76 JS_STATIC_PROP_ENTRY(dirty)
77 JS_STATIC_PROP_ENTRY(documentFileName)
78 JS_STATIC_PROP_ENTRY(external)
79 JS_STATIC_PROP_ENTRY(filesize)
80 JS_STATIC_PROP_ENTRY(icons)
81 JS_STATIC_PROP_ENTRY(info)
82 JS_STATIC_PROP_ENTRY(keywords)
83 JS_STATIC_PROP_ENTRY(layout)
84 JS_STATIC_PROP_ENTRY(media)
85 JS_STATIC_PROP_ENTRY(modDate)
86 JS_STATIC_PROP_ENTRY(mouseX)
87 JS_STATIC_PROP_ENTRY(mouseY)
88 JS_STATIC_PROP_ENTRY(numFields)
89 JS_STATIC_PROP_ENTRY(numPages)
90 JS_STATIC_PROP_ENTRY(pageNum)
91 JS_STATIC_PROP_ENTRY(pageWindowRect)
92 JS_STATIC_PROP_ENTRY(path)
93 JS_STATIC_PROP_ENTRY(producer)
94 JS_STATIC_PROP_ENTRY(subject)
95 JS_STATIC_PROP_ENTRY(title)
96 JS_STATIC_PROP_ENTRY(zoom)
97 JS_STATIC_PROP_ENTRY(zoomType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098END_JS_STATIC_PROP()
99
100BEGIN_JS_STATIC_METHOD(CJS_Document)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700101 JS_STATIC_METHOD_ENTRY(addAnnot)
102 JS_STATIC_METHOD_ENTRY(addField)
103 JS_STATIC_METHOD_ENTRY(addLink)
104 JS_STATIC_METHOD_ENTRY(addIcon)
105 JS_STATIC_METHOD_ENTRY(calculateNow)
106 JS_STATIC_METHOD_ENTRY(closeDoc)
107 JS_STATIC_METHOD_ENTRY(createDataObject)
108 JS_STATIC_METHOD_ENTRY(deletePages)
109 JS_STATIC_METHOD_ENTRY(exportAsText)
110 JS_STATIC_METHOD_ENTRY(exportAsFDF)
111 JS_STATIC_METHOD_ENTRY(exportAsXFDF)
112 JS_STATIC_METHOD_ENTRY(extractPages)
113 JS_STATIC_METHOD_ENTRY(getAnnot)
114 JS_STATIC_METHOD_ENTRY(getAnnots)
115 JS_STATIC_METHOD_ENTRY(getAnnot3D)
116 JS_STATIC_METHOD_ENTRY(getAnnots3D)
117 JS_STATIC_METHOD_ENTRY(getField)
118 JS_STATIC_METHOD_ENTRY(getIcon)
119 JS_STATIC_METHOD_ENTRY(getLinks)
120 JS_STATIC_METHOD_ENTRY(getNthFieldName)
121 JS_STATIC_METHOD_ENTRY(getOCGs)
122 JS_STATIC_METHOD_ENTRY(getPageBox)
123 JS_STATIC_METHOD_ENTRY(getPageNthWord)
124 JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
125 JS_STATIC_METHOD_ENTRY(getPageNumWords)
126 JS_STATIC_METHOD_ENTRY(getPrintParams)
127 JS_STATIC_METHOD_ENTRY(getURL)
128 JS_STATIC_METHOD_ENTRY(importAnFDF)
129 JS_STATIC_METHOD_ENTRY(importAnXFDF)
130 JS_STATIC_METHOD_ENTRY(importTextData)
131 JS_STATIC_METHOD_ENTRY(insertPages)
132 JS_STATIC_METHOD_ENTRY(mailForm)
133 JS_STATIC_METHOD_ENTRY(print)
134 JS_STATIC_METHOD_ENTRY(removeField)
135 JS_STATIC_METHOD_ENTRY(replacePages)
136 JS_STATIC_METHOD_ENTRY(resetForm)
137 JS_STATIC_METHOD_ENTRY(removeIcon)
138 JS_STATIC_METHOD_ENTRY(saveAs)
139 JS_STATIC_METHOD_ENTRY(submitForm)
140 JS_STATIC_METHOD_ENTRY(mailDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141END_JS_STATIC_METHOD()
142
143IMPLEMENT_JS_CLASS(CJS_Document, Document)
144
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700145FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700147 CJS_Context* pContext = (CJS_Context*)cc;
148 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700150 Document* pDoc = (Document*)GetEmbedObject();
151 ASSERT(pDoc != NULL);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800152
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700153 pDoc->AttachDoc(pContext->GetReaderDocument());
154 pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
155 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156};
157
158/* --------------------------------- Document --------------------------------- */
159
160Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700161 m_isolate(NULL),
162 m_pIconTree(NULL),
163 m_pDocument(NULL),
164 m_cwBaseURL(L""),
165 m_bDelay(FALSE)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700166{
167}
168
169Document::~Document()
170{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700171 if (m_pIconTree)
172 {
173 m_pIconTree->DeleteIconTree();
174 delete m_pIconTree;
175 m_pIconTree = NULL;
176 }
177 for (int i=0; i<m_DelayData.GetSize(); i++)
178 {
179 if (CJS_DelayData* pData = m_DelayData.GetAt(i))
180 {
181 delete pData;
182 pData = NULL;
183 m_DelayData.SetAt(i, NULL);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800184
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700185 }
186 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700188 m_DelayData.RemoveAll();
189 m_DelayAnnotData.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190}
191
192//the total number of fileds in document.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800193FX_BOOL Document::numFields(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700195 if (vp.IsSetting()) {
196 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
197 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
198 return FALSE;
199 }
200 CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
201 CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
202 vp << (int)pPDFForm->CountFields();
203 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204}
205
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800206FX_BOOL Document::dirty(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700208 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700210 if (vp.IsGetting())
211 {
212 if (m_pDocument->GetChangeMark())
213 vp << true;
214 else
215 vp << false;
216 }
217 else
218 {
219 bool bChanged = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700221 vp >> bChanged;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700222
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700223 if (bChanged)
224 m_pDocument->SetChangeMark();
225 else
226 m_pDocument->ClearChangeMark();
227 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700229 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700230}
231
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800232FX_BOOL Document::ADBE(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700234 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700236 if (vp.IsGetting())
237 {
238 vp.SetNull();
239 }
240 else
241 {
242 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700244 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800247FX_BOOL Document::pageNum(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700248{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700249 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700251 if (vp.IsGetting())
252 {
253 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())
254 {
255 vp << pPageView->GetPageIndex();
256 }
257 }
258 else
259 {
260 int iPageCount = m_pDocument->GetPageCount();
261 int iPageNum = 0;
262 vp >> iPageNum;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700264 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
265 if (iPageNum >= 0 && iPageNum < iPageCount)
266 {
267 pEnv->JS_docgotoPage(iPageNum);
268 }
269 else if (iPageNum >= iPageCount)
270 {
271 pEnv->JS_docgotoPage(iPageCount-1);
272 }
273 else if (iPageNum < 0)
274 {
275 pEnv->JS_docgotoPage(0);
276 }
277 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700278
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700279 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700280}
281
282FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj)
283{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700284 // Not supported.
285 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286}
287
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800288FX_BOOL Document::addAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700290 // Not supported.
291 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800294FX_BOOL Document::addField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700296 // Not supported.
297 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700298}
299
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800300FX_BOOL Document::exportAsText(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700302 // Unsafe, not supported.
303 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700304}
305
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800306FX_BOOL Document::exportAsFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700307{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700308 // Unsafe, not supported.
309 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310}
311
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800312FX_BOOL Document::exportAsXFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700314 // Unsafe, not supported.
315 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700316}
317
318//Maps a field object in PDF document to a JavaScript variable
319//comment:
320//note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document
321
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800322FX_BOOL Document::getField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700323{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700324 CJS_Context* pContext = (CJS_Context*)cc;
325 if (params.size() < 1) {
326 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
327 return FALSE;
328 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700329
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700330 CFX_WideString wideName = params[0].ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700331
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700332 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
333 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
334 if (pPDFForm->CountFields(wideName) <= 0)
335 {
336 vRet.SetNull();
337 return TRUE;
338 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700339
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700340 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
341 JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700342
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700343 v8::Isolate* isolate = GetIsolate(cc);
344 CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
345 Field* pField = (Field *)pJSField->GetEmbedObject();
346 pField->AttachField(this, wideName);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700348 vRet = pJSField;
349 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350}
351
Tom Sepezc6ab1722015-02-05 15:27:25 -0800352//Gets the name of the nth field in the document
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800353FX_BOOL Document::getNthFieldName(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700355 CJS_Context* pContext = (CJS_Context*)cc;
356 if (params.size() != 1) {
357 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
358 return FALSE;
359 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700361 int nIndex = params[0].ToInt();
362 if (nIndex < 0) {
363 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
364 return FALSE;
365 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700367 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
368 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
369 CPDF_FormField* pField = pPDFForm->GetField(nIndex);
370 if (!pField)
371 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700373 vRet = pField->GetFullName().c_str();
374 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375}
376
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800377FX_BOOL Document::importAnFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700378{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700379 // Unsafe, not supported.
380 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700381}
382
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800383FX_BOOL Document::importAnXFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700385 // Unsafe, not supported.
386 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700387}
388
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800389FX_BOOL Document::importTextData(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700391 // Unsafe, not supported.
392 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393}
394
395//exports the form data and mails the resulting fdf file as an attachment to all recipients.
396//comment: need reader supports
397//note:
398//int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);
399
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800400FX_BOOL Document::mailForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700402 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700403
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700404 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700406 int iLength = params.size();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700407
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700408 FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE;
409 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L"";
410 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L"";
411 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L"";
412 CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L"";
413 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L"";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700414
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700415 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
416 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700417
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700418 CFX_ByteTextBuf textBuf;
419 if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
420 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700421
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700422 CJS_Context* pContext = (CJS_Context*)cc;
423 ASSERT(pContext != NULL);
424 CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
425 ASSERT(pEnv != NULL);
426 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
427 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700429 pRuntime->BeginBlock();
430 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
431 pRuntime->EndBlock();
432 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700433}
434
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800435FX_BOOL Document::print(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700437 CJS_Context* pContext = (CJS_Context*)cc;
438 ASSERT(pContext != NULL);
439 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
440 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700441
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700442 FX_BOOL bUI = TRUE;
443 int nStart = 0;
444 int nEnd = 0;
445 FX_BOOL bSilent = FALSE;
446 FX_BOOL bShrinkToFit = FALSE;
447 FX_BOOL bPrintAsImage = FALSE;
448 FX_BOOL bReverse = FALSE;
449 FX_BOOL bAnnotations = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700451 int nlength = params.size();
452 if(nlength ==9)
453 {
454 if (params[8].GetType() == VT_fxobject)
455 {
456 JSFXObject pObj = params[8].ToV8Object();
457 {
458 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
459 {
460 if (CJS_Object* pJSObj = params[8].ToCJSObject())
461 {
462 if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())
463 {
464 bUI = pprintparamsObj->bUI;
465 nStart = pprintparamsObj->nStart;
466 nEnd = pprintparamsObj->nEnd;
467 bSilent = pprintparamsObj->bSilent;
468 bShrinkToFit = pprintparamsObj->bShrinkToFit;
469 bPrintAsImage = pprintparamsObj->bPrintAsImage;
470 bReverse = pprintparamsObj->bReverse;
471 bAnnotations = pprintparamsObj->bAnnotations;
472 }
473 }
474 }
475 }
476 }
477 }
478 else
479 {
480 if(nlength >= 1)
481 bUI = params[0].ToBool();
482 if(nlength >= 2)
483 nStart = params[1].ToInt();
484 if(nlength >= 3)
485 nEnd = params[2].ToInt();
486 if(nlength >= 4)
487 bSilent = params[3].ToBool();
488 if(nlength >= 5)
489 bShrinkToFit = params[4].ToBool();
490 if(nlength >= 6)
491 bPrintAsImage = params[5].ToBool();
492 if(nlength >= 7)
493 bReverse = params[6].ToBool();
494 if(nlength >= 8)
495 bAnnotations = params[7].ToBool();
496 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700498 ASSERT(m_pDocument != NULL);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800499
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700500 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())
501 {
502 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
503 return TRUE;
504 }
505 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506}
507
508//removes the specified field from the document.
509//comment:
510//note: if the filed name is not retional, adobe is dumb for it.
511
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800512FX_BOOL Document::removeField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700513{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700514 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700516 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
517 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700518
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700519 CJS_Context* pContext = (CJS_Context*)cc;
520 if (params.size() != 1) {
521 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
522 return FALSE;
523 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700525 CFX_WideString sFieldName = params[0].ToCFXWideString();
526 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
527 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700528
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700529 CFX_PtrArray widgets;
530 pInterForm->GetWidgets(sFieldName, widgets);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700532 int nSize = widgets.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700534 if (nSize > 0)
535 {
536 for (int i=0; i<nSize; i++)
537 {
538 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];
539 ASSERT(pWidget != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700541 CPDF_Rect rcAnnot = pWidget->GetRect();
542 rcAnnot.left -= 1;
543 rcAnnot.bottom -= 1;
544 rcAnnot.right += 1;
545 rcAnnot.top += 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700547 CFX_RectArray aRefresh;
548 aRefresh.Add(rcAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549
Bo Xufdc00a72014-10-28 23:03:33 -0700550 CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700551 ASSERT(pPage != NULL);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800552
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700553 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
554 pPageView->DeleteAnnot(pWidget);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700555
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700556 pPageView->UpdateRects(aRefresh);
557 }
558 m_pDocument->SetChangeMark();
559 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700561 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562}
563
564//reset filed values within a document.
565//comment:
566//note: if the fields names r not rational, aodbe is dumb for it.
567
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800568FX_BOOL Document::resetForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700570 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700572 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
573 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
574 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700575
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700576 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
577 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700578
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700579 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
580 ASSERT(pPDFForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700582 v8::Isolate* isolate = GetIsolate(cc);
583 CJS_Array aName(isolate);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700584
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700585 if (params.size() > 0)
586 {
587 switch (params[0].GetType())
588 {
589 default:
590 aName.Attach(params[0].ToV8Array());
591 break;
592 case VT_string:
593 aName.SetElement(0,params[0]);
594 break;
595 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700597 CFX_PtrArray aFields;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700599 for (int i=0,isz=aName.GetLength(); i<isz; i++)
600 {
601 CJS_Value valElement(isolate);
602 aName.GetElement(i,valElement);
603 CFX_WideString swVal = valElement.ToCFXWideString();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800604
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700605 for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)
606 {
607 aFields.Add((void*)pPDFForm->GetField(j,swVal));
608 }
609 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700611 if (aFields.GetSize() > 0)
612 {
613 pPDFForm->ResetForm(aFields, TRUE, TRUE);
614 m_pDocument->SetChangeMark();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700616 }
617 }
618 else
619 {
620 pPDFForm->ResetForm(TRUE);
621 m_pDocument->SetChangeMark();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700623 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700625 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626}
627
628
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800629FX_BOOL Document::saveAs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630{
Tom Sepezc6ab1722015-02-05 15:27:25 -0800631 // Unsafe, not supported.
632 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633}
634
635
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800636FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700638 ASSERT(m_pDocument != NULL);
639 CJS_Context* pContext = (CJS_Context*)cc;
640 int nSize = params.size();
641 if (nSize < 1) {
642 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
643 return FALSE;
644 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700646 CFX_WideString strURL;
647 FX_BOOL bFDF = TRUE;
648 FX_BOOL bEmpty = FALSE;
649 v8::Isolate* isolate = GetIsolate(cc);
650 CJS_Array aFields(isolate);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700652 CJS_Value v = params[0];
653 if (v.GetType() == VT_string)
654 {
655 strURL = params[0].ToCFXWideString();
656 if (nSize > 1)
657 bFDF = params[1].ToBool();
658 if (nSize > 2)
659 bEmpty = params[2].ToBool();
660 if (nSize > 3)
661 aFields.Attach(params[3].ToV8Array());
662 }
663 else if (v.GetType() == VT_object)
664 {
665 JSObject pObj = params[0].ToV8Object();
666 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cURL");
667 if (!pValue.IsEmpty())
668 strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
669 pValue = JS_GetObjectElement(isolate, pObj, L"bFDF");
670 bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
671 pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty");
672 bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
673 pValue = JS_GetObjectElement(isolate, pObj,L"aFields");
674 aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
675 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700677 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
678 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
679 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
680 FX_BOOL bAll = (aFields.GetLength() == 0);
681 if (bAll && bEmpty)
682 {
683 if (pPDFInterForm->CheckRequiredFields())
684 {
685 pRuntime->BeginBlock();
686 pInterForm->SubmitForm(strURL, FALSE);
687 pRuntime->EndBlock();
688 }
689 return TRUE;
690 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700692 CFX_PtrArray fieldObjects;
693 for (int i=0,sz=aFields.GetLength(); i<sz; i++)
694 {
695 CJS_Value valName(isolate);
696 aFields.GetElement(i, valName);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700698 CFX_WideString sName = valName.ToCFXWideString();
699 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
700 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j)
701 {
702 CPDF_FormField* pField = pPDFForm->GetField(j, sName);
703 if (!bEmpty && pField->GetValue().IsEmpty())
704 continue;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700706 fieldObjects.Add(pField);
707 }
708 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800709
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700710 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
711 {
712 pRuntime->BeginBlock();
713 pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
714 pRuntime->EndBlock();
715 }
716 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700717}
718
719//////////////////////////////////////////////////////////////////////////////////////////////
720
721void Document::AttachDoc(CPDFSDK_Document *pDoc)
722{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700723 m_pDocument = pDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700724}
725
726CPDFSDK_Document * Document::GetReaderDoc()
727{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700728 return m_pDocument;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729}
730
731FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)
732{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700733 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
736FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)
737{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700738 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800741FX_BOOL Document::bookmarkRoot(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
Tom Sepezc6ab1722015-02-05 15:27:25 -0800742{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700743 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800746FX_BOOL Document::mailDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700747{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700748 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700750 FX_BOOL bUI = TRUE;
751 CFX_WideString cTo = L"";
752 CFX_WideString cCc = L"";
753 CFX_WideString cBcc = L"";
754 CFX_WideString cSubject = L"";
755 CFX_WideString cMsg = L"";
Tom Sepezc6ab1722015-02-05 15:27:25 -0800756
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700757 if (params.size() >= 1)
758 bUI = params[0].ToBool();
759 if (params.size() >= 2)
760 cTo = params[1].ToCFXWideString();
761 if (params.size() >= 3)
762 cCc = params[2].ToCFXWideString();
763 if (params.size() >= 4)
764 cBcc = params[3].ToCFXWideString();
765 if (params.size() >= 5)
766 cSubject = params[4].ToCFXWideString();
767 if (params.size() >= 6)
768 cMsg = params[5].ToCFXWideString();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800769
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700770 v8::Isolate* isolate = GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700772 if(params.size() >= 1 && params[0].GetType() == VT_object)
773 {
774 JSObject pObj = params[0].ToV8Object();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700776 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
777 bUI = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700779 pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
780 cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700782 pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
783 cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700784
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700785 pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
786 cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700788 pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
789 cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700791 pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
792 cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800793
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700794 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700796 CJS_Context* pContext = (CJS_Context*)cc;
797 ASSERT(pContext != NULL);
798 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
799 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700801 pRuntime->BeginBlock();
802 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
803 pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
804 pRuntime->EndBlock();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700806 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700807}
808
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800809FX_BOOL Document::author(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700810{
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700811 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812
Bo Xufdc00a72014-10-28 23:03:33 -0700813 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814 if (!pDictionary)return FALSE;
815
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700816 if (vp.IsGetting())
817 {
818 vp << pDictionary->GetUnicodeText("Author");
819 return TRUE;
820 }
821 else
822 {
823 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700825 CFX_WideString csAuthor;
826 vp >> csAuthor;
827 pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
828 m_pDocument->SetChangeMark();
829 return TRUE;
830 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831}
832
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800833FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834{
835 ASSERT(m_pDocument != NULL);
836
Bo Xufdc00a72014-10-28 23:03:33 -0700837 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700838 if (!pDictionary)return FALSE;
839
840 CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
841 CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title");
842 CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject");
843 CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords");
844 CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator");
845 CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
846 CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
847 CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
848 CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
849
850 v8::Isolate* isolate = GetIsolate(cc);
Tom Sepez3a832662015-03-02 12:59:05 -0800851 if (vp.IsGetting())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852 {
853 CJS_Context* pContext = (CJS_Context *)cc;
854 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
855
856 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
857
Tom Sepez4f7bc042015-04-27 12:06:58 -0700858 JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
859 JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
860 JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
861 JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
862 JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
863 JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
864 JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str());
865 JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
866 JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867
Tom Sepezc6ab1722015-02-05 15:27:25 -0800868// It's to be compatible to non-standard info dictionary.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869 FX_POSITION pos = pDictionary->GetStartPos();
870 while(pos)
871 {
872 CFX_ByteString bsKey;
873 CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
Bo Xu8daab312014-07-14 12:13:53 -0700874 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875 if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
Tom Sepez4f7bc042015-04-27 12:06:58 -0700876 JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877 if(pValueObj->GetType()==PDFOBJ_NUMBER)
Tom Sepez4f7bc042015-04-27 12:06:58 -0700878 JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700879 if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
Tom Sepez4f7bc042015-04-27 12:06:58 -0700880 JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881 }
882
883 vp << pObj;
884 return TRUE;
885 }
886 else
887 {
888 return TRUE;
889 }
890}
891
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800892FX_BOOL Document::creationDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893{
Bo Xufdc00a72014-10-28 23:03:33 -0700894 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700895 if (!pDictionary)
896 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897
898 if (vp.IsGetting())
899 {
900 vp << pDictionary->GetUnicodeText("CreationDate");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901 }
902 else
903 {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700904 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
905 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700907 CFX_WideString csCreationDate;
908 vp >> csCreationDate;
909 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
910 m_pDocument->SetChangeMark();
911 }
912 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700913}
914
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800915FX_BOOL Document::creator(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700916{
Bo Xufdc00a72014-10-28 23:03:33 -0700917 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700918 if (!pDictionary)
919 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700920
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700921 if (vp.IsGetting())
922 {
923 vp << pDictionary->GetUnicodeText("Creator");
924 }
925 else
926 {
927 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
928 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700929
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700930 CFX_WideString csCreator;
931 vp >> csCreator;
932 pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
933 m_pDocument->SetChangeMark();
934 }
935 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700936}
937
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800938FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700939{
940 if (vp.IsGetting())
941 {
942 vp << m_bDelay;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700943 }
944 else
945 {
946 ASSERT(m_pDocument != NULL);
947
948 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
949
950 bool b;
951 vp >> b;
952
953 m_bDelay = b;
954
Tom Sepezc6ab1722015-02-05 15:27:25 -0800955 if (m_bDelay)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956 {
957 for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
958 delete m_DelayData.GetAt(i);
959
960 m_DelayData.RemoveAll();
961 }
962 else
963 {
964 for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
965 {
966 if (CJS_DelayData* pData = m_DelayData.GetAt(i))
967 {
968 Field::DoDelay(m_pDocument, pData);
969 delete m_DelayData.GetAt(i);
970 }
971 }
972 m_DelayData.RemoveAll();
973 }
974
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700975 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700976 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700977}
978
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800979FX_BOOL Document::keywords(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980{
Bo Xufdc00a72014-10-28 23:03:33 -0700981 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700982 if (!pDictionary)
983 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700985 if (vp.IsGetting())
986 {
987 vp << pDictionary->GetUnicodeText("Keywords");
988 }
989 else
990 {
991 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
992 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700993
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700994 CFX_WideString csKeywords;
995 vp >> csKeywords;
996 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
997 m_pDocument->SetChangeMark();
998 }
999 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001000}
1001
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001002FX_BOOL Document::modDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001003{
Bo Xufdc00a72014-10-28 23:03:33 -07001004 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001005 if (!pDictionary)
1006 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001007
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001008 if (vp.IsGetting())
1009 {
1010 vp << pDictionary->GetUnicodeText("ModDate");
1011 }
1012 else
1013 {
1014 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1015 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001016
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001017 CFX_WideString csmodDate;
1018 vp >> csmodDate;
1019 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
1020 m_pDocument->SetChangeMark();
1021 }
1022 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001023}
1024
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001025FX_BOOL Document::producer(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001026{
Bo Xufdc00a72014-10-28 23:03:33 -07001027 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001028 if (!pDictionary)
1029 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001030
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001031 if (vp.IsGetting())
1032 {
1033 vp << pDictionary->GetUnicodeText("Producer");
1034 }
1035 else
1036 {
1037 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1038 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001039
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001040 CFX_WideString csproducer;
1041 vp >> csproducer;
1042 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
1043 m_pDocument->SetChangeMark();
1044 }
1045 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001046}
1047
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001048FX_BOOL Document::subject(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049{
Bo Xufdc00a72014-10-28 23:03:33 -07001050 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001051 if (!pDictionary)
1052 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001053
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001054 if (vp.IsGetting())
1055 {
1056 vp << pDictionary->GetUnicodeText("Subject");
1057 }
1058 else
1059 {
1060 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1061 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001062
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001063 CFX_WideString cssubject;
1064 vp >> cssubject;
1065 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
1066 m_pDocument->SetChangeMark();
1067 }
1068 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001069}
1070
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001071FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001072{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001073 if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
1074 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001075
Bo Xufdc00a72014-10-28 23:03:33 -07001076 CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001077 if (!pDictionary)
1078 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001079
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001080 if (vp.IsGetting())
1081 {
1082 vp << pDictionary->GetUnicodeText("Title");
1083 }
1084 else
1085 {
1086 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
1087 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001088
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001089 CFX_WideString cstitle;
1090 vp >> cstitle;
1091 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
1092 m_pDocument->SetChangeMark();
1093 }
1094 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001095}
1096
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001097FX_BOOL Document::numPages(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001098{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001099 if (vp.IsSetting()) {
1100 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1101 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1102 return FALSE;
1103 }
1104 vp << m_pDocument->GetPageCount();
1105 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106}
1107
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001108FX_BOOL Document::external(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001109{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001110 //In Chrome case,should always return true.
1111 if (vp.IsGetting()) {
1112 vp << TRUE;
1113 }
1114 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001115}
1116
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001117FX_BOOL Document::filesize(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001118{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001119 if (vp.IsSetting()) {
1120 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1121 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1122 return FALSE;
1123 }
1124 vp << 0;
1125 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001126}
1127
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001128FX_BOOL Document::mouseX(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001129{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001130 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001131}
1132
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001133FX_BOOL Document::mouseY(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001134{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001135 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001136}
1137
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001138FX_BOOL Document::baseURL(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001139{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001140 if (vp.IsGetting())
1141 {
1142 vp << m_cwBaseURL;
1143 }
1144 else
1145 {
1146 vp >> m_cwBaseURL;
1147 }
1148 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001149}
1150
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001151FX_BOOL Document::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001152{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001153 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001154
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001155 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1156 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001157
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001158 if (vp.IsGetting())
1159 {
1160 if (pInterForm->IsCalculateEnabled())
1161 vp << true;
1162 else
1163 vp << false;
1164 }
1165 else
1166 {
1167 bool bCalculate;
1168 vp >> bCalculate;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001169
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001170 pInterForm->EnableCalculate(bCalculate);
1171 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001172
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001173 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001174}
1175
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001176FX_BOOL Document::documentFileName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001177{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001178 if (vp.IsSetting()) {
1179 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1180 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1181 return FALSE;
1182 }
1183 CFX_WideString wsFilePath = m_pDocument->GetPath();
1184 int32_t i = wsFilePath.GetLength() - 1;
1185 for ( ; i >= 0; i-- )
1186 {
1187 if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )
1188 break;
1189 }
1190 if ( i >= 0 && i < wsFilePath.GetLength() - 1 )
1191 {
1192 vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );
1193 }else{
1194 vp << L"";
1195 }
1196 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001197}
1198
1199CFX_WideString Document::ReversalStr(CFX_WideString cbFrom)
1200{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001201 size_t iLength = cbFrom.GetLength();
Tom Sepez35425892015-02-05 10:03:18 -08001202 pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001203 iSize *= (iLength + 1);
1204 wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
1205 wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001206
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001207 for (size_t i = 0; i < iLength; i++)
1208 {
1209 pResult[i] = *(pFrom + iLength - i - 1);
1210 }
1211 pResult[iLength] = L'\0';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001212
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001213 cbFrom.ReleaseBuffer();
1214 CFX_WideString cbRet = CFX_WideString(pResult);
1215 free(pResult);
1216 pResult = NULL;
1217 return cbRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001218}
1219
1220CFX_WideString Document::CutString(CFX_WideString cbFrom)
1221{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001222 size_t iLength = cbFrom.GetLength();
1223 pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
1224 iSize *= (iLength + 1);
1225 wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
1226 wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001227
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001228 for (int i = 0; i < iLength; i++)
1229 {
1230 if (pFrom[i] == L'\\' || pFrom[i] == L'/')
1231 {
1232 pResult[i] = L'\0';
1233 break;
1234 }
1235 pResult[i] = pFrom[i];
1236 }
1237 pResult[iLength] = L'\0';
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001238
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001239 cbFrom.ReleaseBuffer();
1240 CFX_WideString cbRet = CFX_WideString(pResult);
1241 free(pResult);
1242 pResult = NULL;
1243 return cbRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001244}
1245
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001246FX_BOOL Document::path(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001247{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001248 if (vp.IsSetting()) {
1249 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1250 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1251 return FALSE;
1252 }
1253 vp << app::SysPathToPDFPath(m_pDocument->GetPath());
1254 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001255}
1256
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001257FX_BOOL Document::pageWindowRect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001258{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001259 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001260}
1261
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001262FX_BOOL Document::layout(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
Tom Sepezc6ab1722015-02-05 15:27:25 -08001263{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001264 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001265}
1266
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001267FX_BOOL Document::addLink(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001268{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001269 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001270}
1271
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001272FX_BOOL Document::closeDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001273{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001274 ASSERT(m_pDocument != NULL);
1275 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001276}
1277
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001278FX_BOOL Document::getPageBox(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001279{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001280 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001281}
1282
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001283FX_BOOL Document::getAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001284{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001285 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001286}
1287
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001288FX_BOOL Document::getAnnots(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001289{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001290 vRet.SetNull();
1291 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001292}
1293
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001294FX_BOOL Document::getAnnot3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001295{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001296 vRet.SetNull();
1297 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001298}
1299
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001300FX_BOOL Document::getAnnots3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001301{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001302 vRet = VT_undefined;
1303 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001304}
1305
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001306FX_BOOL Document::getOCGs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
Tom Sepezc6ab1722015-02-05 15:27:25 -08001307{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001308 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001309}
1310
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001311FX_BOOL Document::getLinks(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001312{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001313 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001314}
1315
1316bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
1317{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001318 return (rect.left <= LinkRect.left &&
1319 rect.top <= LinkRect.top &&
1320 rect.right >= LinkRect.right &&
1321 rect.bottom >= LinkRect.bottom);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001322}
1323
1324void IconTree::InsertIconElement(IconElement* pNewIcon)
1325{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001326 if (!pNewIcon)return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001327
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001328 if (m_pHead == NULL && m_pEnd == NULL)
1329 {
1330 m_pHead = m_pEnd = pNewIcon;
1331 m_iLength++;
1332 }
1333 else
1334 {
1335 m_pEnd->NextIcon = pNewIcon;
1336 m_pEnd = pNewIcon;
1337 m_iLength++;
1338 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001339}
1340
1341void IconTree::DeleteIconTree()
1342{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001343 if (!m_pHead || !m_pEnd)return;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001344
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001345 IconElement* pTemp = NULL;
1346 while(m_pEnd != m_pHead)
1347 {
1348 pTemp = m_pHead;
1349 m_pHead = m_pHead->NextIcon;
1350 delete pTemp;
1351 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001352
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001353 delete m_pEnd;
1354 m_pHead = NULL;
1355 m_pEnd = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001356}
1357
1358int IconTree::GetLength()
1359{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001360 return m_iLength;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001361}
1362
1363IconElement* IconTree::operator [](int iIndex)
1364{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001365 if (iIndex >= 0 && iIndex <= m_iLength)
1366 {
1367 IconElement* pTemp = m_pHead;
1368 for (int i = 0; i < iIndex; i++)
1369 {
1370 pTemp = pTemp->NextIcon;
1371 }
1372 return pTemp;
1373 }
1374 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001375}
1376
1377void IconTree::DeleteIconElement(CFX_WideString swIconName)
1378{
1379 IconElement* pTemp = m_pHead;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001380 int iLoopCount = m_iLength;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001381 for (int i = 0; i < iLoopCount - 1; i++)
1382 {
1383 if (pTemp == m_pEnd)
1384 break;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001385
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001386 if (m_pHead->IconName == swIconName)
1387 {
1388 m_pHead = m_pHead->NextIcon;
1389 delete pTemp;
1390 m_iLength--;
1391 pTemp = m_pHead;
1392 }
1393 if (pTemp->NextIcon->IconName == swIconName)
1394 {
1395 if (pTemp->NextIcon == m_pEnd)
1396 {
1397 m_pEnd = pTemp;
1398 delete pTemp->NextIcon;
1399 m_iLength--;
1400 pTemp->NextIcon = NULL;
1401 }
1402 else
1403 {
1404 IconElement* pElement = pTemp->NextIcon;
1405 pTemp->NextIcon = pTemp->NextIcon->NextIcon;
1406 delete pElement;
1407 m_iLength--;
1408 pElement = NULL;
1409 }
1410
1411 continue;
1412 }
1413
1414 pTemp = pTemp->NextIcon;
1415 }
1416}
1417
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001418FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001419{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001420 CJS_Context* pContext = (CJS_Context*)cc;
1421 if (params.size() != 2) {
1422 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1423 return FALSE;
1424 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001425
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001426 CFX_WideString swIconName = params[0].ToCFXWideString();
1427 JSFXObject pJSIcon = params[1].ToV8Object();
Tom Sepeze5350ef2015-04-23 18:14:26 -07001428
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001429 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1430 if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) {
1431 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1432 return FALSE;
1433 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001434
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001435 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
1436 if (!pEmbedObj) {
1437 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1438 return FALSE;
1439 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001440
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001441 Icon* pIcon = (Icon*)pEmbedObj;
1442 if (!m_pIconTree)
1443 m_pIconTree = new IconTree();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001444
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001445 IconElement* pNewIcon = new IconElement();
1446 pNewIcon->IconName = swIconName;
1447 pNewIcon->NextIcon = NULL;
1448 pNewIcon->IconStream = pIcon;
1449 m_pIconTree->InsertIconElement(pNewIcon);
1450 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001451}
1452
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001453FX_BOOL Document::icons(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001454{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001455 if (vp.IsSetting()) {
1456 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1457 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1458 return FALSE;
1459 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001460
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001461 if (!m_pIconTree)
1462 {
1463 vp.SetNull();
1464 return TRUE;
1465 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001466
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001467 CJS_Array Icons(m_isolate);
1468 IconElement* pIconElement = NULL;
1469 int iIconTreeLength = m_pIconTree->GetLength();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001470
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001471 CJS_Context* pContext = (CJS_Context *)cc;
1472 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001473
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001474 for (int i = 0; i < iIconTreeLength; i++)
1475 {
1476 pIconElement = (*m_pIconTree)[i];
Tom Sepezc6ab1722015-02-05 15:27:25 -08001477
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001478 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
1479 if (pObj.IsEmpty()) return FALSE;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001480
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001481 CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
1482 if (!pJS_Icon) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001483
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001484 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1485 if (!pIcon)return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001486
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001487 pIcon->SetStream(pIconElement->IconStream->GetStream());
1488 pIcon->SetIconName(pIconElement->IconName);
1489 Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));
1490 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001491
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001492 vp << Icons;
1493 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001494}
1495
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001496FX_BOOL Document::getIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001497{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001498 CJS_Context* pContext = (CJS_Context *)cc;
1499 if (params.size() != 1) {
1500 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1501 return FALSE;
1502 }
Tom Sepeze5350ef2015-04-23 18:14:26 -07001503
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001504 if(!m_pIconTree)
1505 return FALSE;
1506 CFX_WideString swIconName = params[0].ToCFXWideString();
1507 int iIconCounts = m_pIconTree->GetLength();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001508
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001509 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001510
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001511 for (int i = 0; i < iIconCounts; i++)
1512 {
1513 if ((*m_pIconTree)[i]->IconName == swIconName)
1514 {
1515 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001516
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001517 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
1518 if (pObj.IsEmpty()) return FALSE;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001519
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001520 CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
1521 if (!pJS_Icon) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001522
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001523 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1524 if (!pIcon)return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001525
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001526 pIcon->SetIconName(swIconName);
1527 pIcon->SetStream(pRetIcon->GetStream());
1528 vRet = pJS_Icon;
1529 return TRUE;
1530 }
1531 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001532
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001533 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001534}
1535
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001536FX_BOOL Document::removeIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001537{
Tom Sepeze5350ef2015-04-23 18:14:26 -07001538 CJS_Context* pContext = (CJS_Context *)cc;
1539 if (params.size() != 1) {
1540 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1541 return FALSE;
1542 }
1543
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001544 if(!m_pIconTree)
1545 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001546 CFX_WideString swIconName = params[0].ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001547 return TRUE;
1548}
1549
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001550FX_BOOL Document::createDataObject(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001551{
Tom Sepezc6ab1722015-02-05 15:27:25 -08001552 // Unsafe, not implemented.
1553 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001554}
1555
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001556FX_BOOL Document::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001557{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001558 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001559}
1560
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001561FX_BOOL Document::calculateNow(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001562{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001563 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001564
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001565 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
1566 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
1567 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001568
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001569 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1570 ASSERT(pInterForm != NULL);
1571 pInterForm->OnCalculate();
1572 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001573}
1574
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001575FX_BOOL Document::Collab(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001576{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001577 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001578}
1579
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001580FX_BOOL Document::getPageNthWord(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001581{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001582 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001583
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001584 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001585
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001586 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
1587 int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0;
1588 bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001589
Bo Xufdc00a72014-10-28 23:03:33 -07001590 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001591 if (!pDocument)
1592 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001593
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001594 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1595 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
1596 {
1597 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
1598 return FALSE;
1599 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001600
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001601 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1602 if (!pPageDict) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001603
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001604 CPDF_Page page;
1605 page.Load(pDocument, pPageDict);
1606 page.StartParse();
1607 page.ParseContent();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001608
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001609 FX_POSITION pos = page.GetFirstObjectPosition();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001610
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001611 int nWords = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001612
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001613 CFX_WideString swRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001614
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001615 while (pos)
1616 {
1617 if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
1618 {
1619 if (pPageObj->m_Type == PDFPAGE_TEXT)
1620 {
1621 int nObjWords = CountWords((CPDF_TextObject*)pPageObj);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001622
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001623 if (nWords + nObjWords >= nWordNo)
1624 {
1625 swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
1626 break;
1627 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001628
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001629 nWords += nObjWords;
1630 }
1631 }
1632 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001633
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001634 if (bStrip)
1635 {
1636 swRet.TrimLeft();
1637 swRet.TrimRight();
1638 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001639
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001640 vRet = swRet.c_str();
1641 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001642}
1643
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001644FX_BOOL Document::getPageNthWordQuads(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001645{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001646 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001647
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001648 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001649
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001650 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001651}
1652
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001653FX_BOOL Document::getPageNumWords(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001654{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001655 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001656
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001657 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001658
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001659 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
Bo Xufdc00a72014-10-28 23:03:33 -07001660 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001661 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1662 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
1663 {
1664 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
1665 return FALSE;
1666 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001667
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001668 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
1669 if (!pPageDict) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001670
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001671 CPDF_Page page;
1672 page.Load(pDocument, pPageDict);
1673 page.StartParse();
1674 page.ParseContent();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001675
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001676 FX_POSITION pos = page.GetFirstObjectPosition();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001677
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001678 int nWords = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001679
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001680 while (pos)
1681 {
1682 if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
1683 {
1684 if (pPageObj->m_Type == PDFPAGE_TEXT)
1685 {
1686 CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
1687 nWords += CountWords(pTextObj);
1688 }
1689 }
1690 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001691
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001692 vRet = nWords;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001693
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001694 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001695}
1696
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001697FX_BOOL Document::getPrintParams(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001698{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001699 CJS_Context* pContext = (CJS_Context*)cc;
1700 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1701 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001702
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001703 // Not implemented yet.
Tom Sepeze5350ef2015-04-23 18:14:26 -07001704
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001705 vRet = pRetObj;
1706 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001707}
1708
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001709#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001710
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001711int Document::CountWords(CPDF_TextObject* pTextObj)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001712{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001713 if (!pTextObj) return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001714
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001715 int nWords = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001716
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001717 CPDF_Font* pFont = pTextObj->GetFont();
1718 if (!pFont) return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001719
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001720 FX_BOOL bIsLatin = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001721
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001722 for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
1723 {
1724 FX_DWORD charcode = -1;
1725 FX_FLOAT kerning;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001726
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001727 pTextObj->GetCharInfo(i, charcode, kerning);
1728 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001729
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001730 FX_WORD unicode = 0;
1731 if (swUnicode.GetLength() > 0)
1732 unicode = swUnicode[0];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001733
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001734 if (ISLATINWORD(unicode) && bIsLatin)
1735 continue;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001736
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001737 bIsLatin = ISLATINWORD(unicode);
1738 if (unicode != 0x20)
1739 nWords++;
1740 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001741
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001742 return nWords;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001743}
1744
1745CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)
1746{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001747 ASSERT(pTextObj != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001748
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001749 CFX_WideString swRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001750
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001751 CPDF_Font* pFont = pTextObj->GetFont();
1752 if (!pFont) return L"";
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001753
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001754 int nWords = 0;
1755 FX_BOOL bIsLatin = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001756
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001757 for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
1758 {
1759 FX_DWORD charcode = -1;
1760 FX_FLOAT kerning;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001761
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001762 pTextObj->GetCharInfo(i, charcode, kerning);
1763 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001764
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001765 FX_WORD unicode = 0;
1766 if (swUnicode.GetLength() > 0)
1767 unicode = swUnicode[0];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001768
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001769 if (ISLATINWORD(unicode) && bIsLatin)
1770 {
1771 }
1772 else
1773 {
1774 bIsLatin = ISLATINWORD(unicode);
1775 if (unicode != 0x20)
1776 nWords++;
1777 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001778
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001779 if (nWords-1 == nWordIndex)
1780 swRet += unicode;
1781 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001782
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001783 return swRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001784}
1785
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001786FX_BOOL Document::zoom(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001787{
1788
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001789 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001790}
1791
1792/**
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001793(none, NoVary)
1794(fitP, FitPage)
1795(fitW, FitWidth)
1796(fitH, FitHeight)
1797(fitV, FitVisibleWidth)
1798(pref, Preferred)
1799(refW, ReflowWidth)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001800*/
1801
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001802FX_BOOL Document::zoomType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001803{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001804 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001805}
1806
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001807FX_BOOL Document::deletePages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001808{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001809 v8::Isolate* isolate = GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001810 ASSERT(m_pDocument != NULL);
1811
Tom Sepezc6ab1722015-02-05 15:27:25 -08001812 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001813 m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
1814
1815 int iSize = params.size();
Tom Sepezc6ab1722015-02-05 15:27:25 -08001816
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001817 int nStart = 0;
1818 int nEnd = 0;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001819
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001820 if (iSize < 1)
1821 {
1822 }
1823 else if (iSize == 1)
1824 {
1825 if (params[0].GetType() == VT_object)
1826 {
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001827 JSObject pObj = params[0].ToV8Object();
Jochen Eisingerdfa2c992015-05-19 00:38:00 +02001828 v8::Local<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"nStart");
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001829 nStart = CJS_Value(m_isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001830
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001831 pValue = JS_GetObjectElement(isolate, pObj, L"nEnd");
1832 nEnd = CJS_Value(m_isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001833 }
1834 else
1835 {
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001836 nStart = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001837 }
1838 }
1839 else
1840 {
Tom Sepezf4ef3f92015-04-23 11:31:31 -07001841 nStart = params[0].ToInt();
1842 nEnd = params[1].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001843 }
1844
1845 int nTotal = m_pDocument->GetPageCount();
1846
1847 if (nStart < 0) nStart = 0;
1848 if (nStart >= nTotal) nStart = nTotal - 1;
1849
1850 if (nEnd < 0) nEnd = 0;
1851 if (nEnd >= nTotal) nEnd = nTotal - 1;
1852
1853 if (nEnd < nStart) nEnd = nStart;
1854
Tom Sepezc6ab1722015-02-05 15:27:25 -08001855
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001856
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001857 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001858}
1859
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001860FX_BOOL Document::extractPages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001861{
Tom Sepezc6ab1722015-02-05 15:27:25 -08001862 // Unsafe, not supported.
1863 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001864}
1865
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001866FX_BOOL Document::insertPages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001867{
Tom Sepezc6ab1722015-02-05 15:27:25 -08001868 // Unsafe, not supported.
1869 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001870}
1871
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001872FX_BOOL Document::replacePages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001873{
Tom Sepezc6ab1722015-02-05 15:27:25 -08001874 // Unsafe, not supported.
1875 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001876}
1877
Tom Sepez2f3dfef2015-03-02 15:35:26 -08001878FX_BOOL Document::getURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001879{
Tom Sepezc6ab1722015-02-05 15:27:25 -08001880 // Unsafe, not supported.
1881 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001882}
1883
1884void Document::AddDelayData(CJS_DelayData* pData)
1885{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001886 m_DelayData.Add(pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001887}
1888
1889void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)
1890{
1891 CFX_DWordArray DelArray;
1892
1893 for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
1894 {
1895 if (CJS_DelayData* pData = m_DelayData.GetAt(i))
1896 {
1897 if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)
1898 {
1899 Field::DoDelay(m_pDocument, pData);
1900 delete pData;
1901 m_DelayData.SetAt(i, NULL);
1902 DelArray.Add(i);
1903 }
1904 }
1905 }
1906
1907 for (int j=DelArray.GetSize()-1; j>=0; j--)
1908 {
1909 m_DelayData.RemoveAt(DelArray[j]);
1910 }
1911}
1912
1913void Document::AddDelayAnnotData(CJS_AnnotObj *pData)
1914{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001915 m_DelayAnnotData.Add(pData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001916}
1917
1918void Document::DoAnnotDelay()
1919{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001920 CFX_DWordArray DelArray;
Tom Sepezc6ab1722015-02-05 15:27:25 -08001921
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001922 for (int j=DelArray.GetSize()-1; j>=0; j--)
1923 {
1924 m_DelayData.RemoveAt(DelArray[j]);
1925 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001926}
JUN FANG33f6f0d2015-04-06 12:39:51 -07001927
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001928CJS_Document* Document::GetCJSDoc() const
JUN FANG33f6f0d2015-04-06 12:39:51 -07001929{
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001930 return static_cast<CJS_Document*>(m_pJSObject);
JUN FANG33f6f0d2015-04-06 12:39:51 -07001931}