OLD | NEW |
| (Empty) |
1 // 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. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "fpdfsdk/src/javascript/Document.h" | |
8 | |
9 #include <vector> | |
10 | |
11 #include "core/include/fpdfapi/cpdf_document.h" | |
12 #include "fpdfsdk/include/fsdk_mgr.h" | |
13 #include "fpdfsdk/include/javascript/IJavaScript.h" | |
14 #include "fpdfsdk/src/javascript/Field.h" | |
15 #include "fpdfsdk/src/javascript/Icon.h" | |
16 #include "fpdfsdk/src/javascript/JS_Context.h" | |
17 #include "fpdfsdk/src/javascript/JS_Define.h" | |
18 #include "fpdfsdk/src/javascript/JS_EventHandler.h" | |
19 #include "fpdfsdk/src/javascript/JS_Object.h" | |
20 #include "fpdfsdk/src/javascript/JS_Runtime.h" | |
21 #include "fpdfsdk/src/javascript/JS_Value.h" | |
22 #include "fpdfsdk/src/javascript/app.h" | |
23 #include "fpdfsdk/src/javascript/resource.h" | |
24 #include "third_party/base/numerics/safe_math.h" | |
25 | |
26 static v8::Isolate* GetIsolate(IJS_Context* cc) { | |
27 CJS_Context* pContext = (CJS_Context*)cc; | |
28 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
29 return pRuntime->GetIsolate(); | |
30 } | |
31 | |
32 BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) | |
33 END_JS_STATIC_CONST() | |
34 | |
35 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) | |
36 END_JS_STATIC_PROP() | |
37 | |
38 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) | |
39 END_JS_STATIC_METHOD() | |
40 | |
41 IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) | |
42 | |
43 PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject) | |
44 : CJS_EmbedObj(pJSObject) { | |
45 bUI = TRUE; | |
46 nStart = 0; | |
47 nEnd = 0; | |
48 bSilent = FALSE; | |
49 bShrinkToFit = FALSE; | |
50 bPrintAsImage = FALSE; | |
51 bReverse = FALSE; | |
52 bAnnotations = TRUE; | |
53 } | |
54 | |
55 /* ---------------------- Document ---------------------- */ | |
56 | |
57 #define MINWIDTH 5.0f | |
58 #define MINHEIGHT 5.0f | |
59 | |
60 BEGIN_JS_STATIC_CONST(CJS_Document) | |
61 END_JS_STATIC_CONST() | |
62 | |
63 BEGIN_JS_STATIC_PROP(CJS_Document) | |
64 JS_STATIC_PROP_ENTRY(ADBE) | |
65 JS_STATIC_PROP_ENTRY(author) | |
66 JS_STATIC_PROP_ENTRY(baseURL) | |
67 JS_STATIC_PROP_ENTRY(bookmarkRoot) | |
68 JS_STATIC_PROP_ENTRY(calculate) | |
69 JS_STATIC_PROP_ENTRY(Collab) | |
70 JS_STATIC_PROP_ENTRY(creationDate) | |
71 JS_STATIC_PROP_ENTRY(creator) | |
72 JS_STATIC_PROP_ENTRY(delay) | |
73 JS_STATIC_PROP_ENTRY(dirty) | |
74 JS_STATIC_PROP_ENTRY(documentFileName) | |
75 JS_STATIC_PROP_ENTRY(external) | |
76 JS_STATIC_PROP_ENTRY(filesize) | |
77 JS_STATIC_PROP_ENTRY(icons) | |
78 JS_STATIC_PROP_ENTRY(info) | |
79 JS_STATIC_PROP_ENTRY(keywords) | |
80 JS_STATIC_PROP_ENTRY(layout) | |
81 JS_STATIC_PROP_ENTRY(media) | |
82 JS_STATIC_PROP_ENTRY(modDate) | |
83 JS_STATIC_PROP_ENTRY(mouseX) | |
84 JS_STATIC_PROP_ENTRY(mouseY) | |
85 JS_STATIC_PROP_ENTRY(numFields) | |
86 JS_STATIC_PROP_ENTRY(numPages) | |
87 JS_STATIC_PROP_ENTRY(pageNum) | |
88 JS_STATIC_PROP_ENTRY(pageWindowRect) | |
89 JS_STATIC_PROP_ENTRY(path) | |
90 JS_STATIC_PROP_ENTRY(producer) | |
91 JS_STATIC_PROP_ENTRY(subject) | |
92 JS_STATIC_PROP_ENTRY(title) | |
93 JS_STATIC_PROP_ENTRY(zoom) | |
94 JS_STATIC_PROP_ENTRY(zoomType) | |
95 END_JS_STATIC_PROP() | |
96 | |
97 BEGIN_JS_STATIC_METHOD(CJS_Document) | |
98 JS_STATIC_METHOD_ENTRY(addAnnot) | |
99 JS_STATIC_METHOD_ENTRY(addField) | |
100 JS_STATIC_METHOD_ENTRY(addLink) | |
101 JS_STATIC_METHOD_ENTRY(addIcon) | |
102 JS_STATIC_METHOD_ENTRY(calculateNow) | |
103 JS_STATIC_METHOD_ENTRY(closeDoc) | |
104 JS_STATIC_METHOD_ENTRY(createDataObject) | |
105 JS_STATIC_METHOD_ENTRY(deletePages) | |
106 JS_STATIC_METHOD_ENTRY(exportAsText) | |
107 JS_STATIC_METHOD_ENTRY(exportAsFDF) | |
108 JS_STATIC_METHOD_ENTRY(exportAsXFDF) | |
109 JS_STATIC_METHOD_ENTRY(extractPages) | |
110 JS_STATIC_METHOD_ENTRY(getAnnot) | |
111 JS_STATIC_METHOD_ENTRY(getAnnots) | |
112 JS_STATIC_METHOD_ENTRY(getAnnot3D) | |
113 JS_STATIC_METHOD_ENTRY(getAnnots3D) | |
114 JS_STATIC_METHOD_ENTRY(getField) | |
115 JS_STATIC_METHOD_ENTRY(getIcon) | |
116 JS_STATIC_METHOD_ENTRY(getLinks) | |
117 JS_STATIC_METHOD_ENTRY(getNthFieldName) | |
118 JS_STATIC_METHOD_ENTRY(getOCGs) | |
119 JS_STATIC_METHOD_ENTRY(getPageBox) | |
120 JS_STATIC_METHOD_ENTRY(getPageNthWord) | |
121 JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) | |
122 JS_STATIC_METHOD_ENTRY(getPageNumWords) | |
123 JS_STATIC_METHOD_ENTRY(getPrintParams) | |
124 JS_STATIC_METHOD_ENTRY(getURL) | |
125 JS_STATIC_METHOD_ENTRY(importAnFDF) | |
126 JS_STATIC_METHOD_ENTRY(importAnXFDF) | |
127 JS_STATIC_METHOD_ENTRY(importTextData) | |
128 JS_STATIC_METHOD_ENTRY(insertPages) | |
129 JS_STATIC_METHOD_ENTRY(mailForm) | |
130 JS_STATIC_METHOD_ENTRY(print) | |
131 JS_STATIC_METHOD_ENTRY(removeField) | |
132 JS_STATIC_METHOD_ENTRY(replacePages) | |
133 JS_STATIC_METHOD_ENTRY(resetForm) | |
134 JS_STATIC_METHOD_ENTRY(removeIcon) | |
135 JS_STATIC_METHOD_ENTRY(saveAs) | |
136 JS_STATIC_METHOD_ENTRY(submitForm) | |
137 JS_STATIC_METHOD_ENTRY(mailDoc) | |
138 END_JS_STATIC_METHOD() | |
139 | |
140 IMPLEMENT_JS_CLASS(CJS_Document, Document) | |
141 | |
142 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { | |
143 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | |
144 Document* pDoc = static_cast<Document*>(GetEmbedObject()); | |
145 pDoc->AttachDoc(pRuntime->GetReaderDocument()); | |
146 pDoc->SetIsolate(pRuntime->GetIsolate()); | |
147 } | |
148 | |
149 /* --------------------------------- Document --------------------------------- | |
150 */ | |
151 | |
152 Document::Document(CJS_Object* pJSObject) | |
153 : CJS_EmbedObj(pJSObject), | |
154 m_isolate(NULL), | |
155 m_pDocument(NULL), | |
156 m_cwBaseURL(L""), | |
157 m_bDelay(FALSE) {} | |
158 | |
159 Document::~Document() { | |
160 for (int i = 0; i < m_DelayData.GetSize(); i++) { | |
161 delete m_DelayData.GetAt(i); | |
162 } | |
163 | |
164 m_DelayData.RemoveAll(); | |
165 } | |
166 | |
167 // the total number of fileds in document. | |
168 FX_BOOL Document::numFields(IJS_Context* cc, | |
169 CJS_PropValue& vp, | |
170 CFX_WideString& sError) { | |
171 if (vp.IsSetting()) { | |
172 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
173 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
174 return FALSE; | |
175 } | |
176 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | |
177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | |
178 vp << (int)pPDFForm->CountFields(); | |
179 return TRUE; | |
180 } | |
181 | |
182 FX_BOOL Document::dirty(IJS_Context* cc, | |
183 CJS_PropValue& vp, | |
184 CFX_WideString& sError) { | |
185 if (vp.IsGetting()) { | |
186 if (m_pDocument->GetChangeMark()) | |
187 vp << true; | |
188 else | |
189 vp << false; | |
190 } else { | |
191 bool bChanged = false; | |
192 | |
193 vp >> bChanged; | |
194 | |
195 if (bChanged) | |
196 m_pDocument->SetChangeMark(); | |
197 else | |
198 m_pDocument->ClearChangeMark(); | |
199 } | |
200 | |
201 return TRUE; | |
202 } | |
203 | |
204 FX_BOOL Document::ADBE(IJS_Context* cc, | |
205 CJS_PropValue& vp, | |
206 CFX_WideString& sError) { | |
207 if (vp.IsGetting()) { | |
208 vp.SetNull(); | |
209 } else { | |
210 } | |
211 | |
212 return TRUE; | |
213 } | |
214 | |
215 FX_BOOL Document::pageNum(IJS_Context* cc, | |
216 CJS_PropValue& vp, | |
217 CFX_WideString& sError) { | |
218 if (vp.IsGetting()) { | |
219 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { | |
220 vp << pPageView->GetPageIndex(); | |
221 } | |
222 } else { | |
223 int iPageCount = m_pDocument->GetPageCount(); | |
224 int iPageNum = 0; | |
225 vp >> iPageNum; | |
226 | |
227 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | |
228 if (iPageNum >= 0 && iPageNum < iPageCount) { | |
229 pEnv->JS_docgotoPage(iPageNum); | |
230 } else if (iPageNum >= iPageCount) { | |
231 pEnv->JS_docgotoPage(iPageCount - 1); | |
232 } else if (iPageNum < 0) { | |
233 pEnv->JS_docgotoPage(0); | |
234 } | |
235 } | |
236 | |
237 return TRUE; | |
238 } | |
239 | |
240 FX_BOOL Document::addAnnot(IJS_Context* cc, | |
241 const std::vector<CJS_Value>& params, | |
242 CJS_Value& vRet, | |
243 CFX_WideString& sError) { | |
244 // Not supported. | |
245 return TRUE; | |
246 } | |
247 | |
248 FX_BOOL Document::addField(IJS_Context* cc, | |
249 const std::vector<CJS_Value>& params, | |
250 CJS_Value& vRet, | |
251 CFX_WideString& sError) { | |
252 // Not supported. | |
253 return TRUE; | |
254 } | |
255 | |
256 FX_BOOL Document::exportAsText(IJS_Context* cc, | |
257 const std::vector<CJS_Value>& params, | |
258 CJS_Value& vRet, | |
259 CFX_WideString& sError) { | |
260 // Unsafe, not supported. | |
261 return TRUE; | |
262 } | |
263 | |
264 FX_BOOL Document::exportAsFDF(IJS_Context* cc, | |
265 const std::vector<CJS_Value>& params, | |
266 CJS_Value& vRet, | |
267 CFX_WideString& sError) { | |
268 // Unsafe, not supported. | |
269 return TRUE; | |
270 } | |
271 | |
272 FX_BOOL Document::exportAsXFDF(IJS_Context* cc, | |
273 const std::vector<CJS_Value>& params, | |
274 CJS_Value& vRet, | |
275 CFX_WideString& sError) { | |
276 // Unsafe, not supported. | |
277 return TRUE; | |
278 } | |
279 | |
280 // Maps a field object in PDF document to a JavaScript variable | |
281 // comment: | |
282 // note: the paremter cName, this is clue how to treat if the cName is not a | |
283 // valiable filed name in this document | |
284 | |
285 FX_BOOL Document::getField(IJS_Context* cc, | |
286 const std::vector<CJS_Value>& params, | |
287 CJS_Value& vRet, | |
288 CFX_WideString& sError) { | |
289 CJS_Context* pContext = (CJS_Context*)cc; | |
290 if (params.size() < 1) { | |
291 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
292 return FALSE; | |
293 } | |
294 | |
295 CFX_WideString wideName = params[0].ToCFXWideString(); | |
296 | |
297 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | |
298 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | |
299 if (pPDFForm->CountFields(wideName) <= 0) { | |
300 vRet.SetNull(); | |
301 return TRUE; | |
302 } | |
303 | |
304 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
305 v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj( | |
306 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); | |
307 | |
308 v8::Isolate* isolate = GetIsolate(cc); | |
309 CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj); | |
310 Field* pField = (Field*)pJSField->GetEmbedObject(); | |
311 pField->AttachField(this, wideName); | |
312 | |
313 vRet = pJSField; | |
314 return TRUE; | |
315 } | |
316 | |
317 // Gets the name of the nth field in the document | |
318 FX_BOOL Document::getNthFieldName(IJS_Context* cc, | |
319 const std::vector<CJS_Value>& params, | |
320 CJS_Value& vRet, | |
321 CFX_WideString& sError) { | |
322 CJS_Context* pContext = (CJS_Context*)cc; | |
323 if (params.size() != 1) { | |
324 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
325 return FALSE; | |
326 } | |
327 | |
328 int nIndex = params[0].ToInt(); | |
329 if (nIndex < 0) { | |
330 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | |
331 return FALSE; | |
332 } | |
333 | |
334 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | |
335 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | |
336 CPDF_FormField* pField = pPDFForm->GetField(nIndex); | |
337 if (!pField) | |
338 return FALSE; | |
339 | |
340 vRet = pField->GetFullName().c_str(); | |
341 return TRUE; | |
342 } | |
343 | |
344 FX_BOOL Document::importAnFDF(IJS_Context* cc, | |
345 const std::vector<CJS_Value>& params, | |
346 CJS_Value& vRet, | |
347 CFX_WideString& sError) { | |
348 // Unsafe, not supported. | |
349 return TRUE; | |
350 } | |
351 | |
352 FX_BOOL Document::importAnXFDF(IJS_Context* cc, | |
353 const std::vector<CJS_Value>& params, | |
354 CJS_Value& vRet, | |
355 CFX_WideString& sError) { | |
356 // Unsafe, not supported. | |
357 return TRUE; | |
358 } | |
359 | |
360 FX_BOOL Document::importTextData(IJS_Context* cc, | |
361 const std::vector<CJS_Value>& params, | |
362 CJS_Value& vRet, | |
363 CFX_WideString& sError) { | |
364 // Unsafe, not supported. | |
365 return TRUE; | |
366 } | |
367 | |
368 // exports the form data and mails the resulting fdf file as an attachment to | |
369 // all recipients. | |
370 // comment: need reader supports | |
371 // note: | |
372 // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string | |
373 // cbcc,string cSubject,string cms); | |
374 | |
375 FX_BOOL Document::mailForm(IJS_Context* cc, | |
376 const std::vector<CJS_Value>& params, | |
377 CJS_Value& vRet, | |
378 CFX_WideString& sError) { | |
379 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | |
380 return FALSE; | |
381 | |
382 int iLength = params.size(); | |
383 | |
384 FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; | |
385 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; | |
386 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; | |
387 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; | |
388 CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; | |
389 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; | |
390 | |
391 CPDFSDK_InterForm* pInterForm = | |
392 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
393 CFX_ByteTextBuf textBuf; | |
394 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) | |
395 return FALSE; | |
396 | |
397 CJS_Context* pContext = (CJS_Context*)cc; | |
398 CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); | |
399 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
400 | |
401 pRuntime->BeginBlock(); | |
402 pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, | |
403 cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), | |
404 cMsg.c_str()); | |
405 pRuntime->EndBlock(); | |
406 return TRUE; | |
407 } | |
408 | |
409 FX_BOOL Document::print(IJS_Context* cc, | |
410 const std::vector<CJS_Value>& params, | |
411 CJS_Value& vRet, | |
412 CFX_WideString& sError) { | |
413 FX_BOOL bUI = TRUE; | |
414 int nStart = 0; | |
415 int nEnd = 0; | |
416 FX_BOOL bSilent = FALSE; | |
417 FX_BOOL bShrinkToFit = FALSE; | |
418 FX_BOOL bPrintAsImage = FALSE; | |
419 FX_BOOL bReverse = FALSE; | |
420 FX_BOOL bAnnotations = FALSE; | |
421 | |
422 int nlength = params.size(); | |
423 if (nlength == 9) { | |
424 if (params[8].GetType() == CJS_Value::VT_fxobject) { | |
425 v8::Local<v8::Object> pObj = params[8].ToV8Object(); | |
426 { | |
427 if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { | |
428 if (CJS_Object* pJSObj = params[8].ToCJSObject()) { | |
429 if (PrintParamsObj* pprintparamsObj = | |
430 (PrintParamsObj*)pJSObj->GetEmbedObject()) { | |
431 bUI = pprintparamsObj->bUI; | |
432 nStart = pprintparamsObj->nStart; | |
433 nEnd = pprintparamsObj->nEnd; | |
434 bSilent = pprintparamsObj->bSilent; | |
435 bShrinkToFit = pprintparamsObj->bShrinkToFit; | |
436 bPrintAsImage = pprintparamsObj->bPrintAsImage; | |
437 bReverse = pprintparamsObj->bReverse; | |
438 bAnnotations = pprintparamsObj->bAnnotations; | |
439 } | |
440 } | |
441 } | |
442 } | |
443 } | |
444 } else { | |
445 if (nlength >= 1) | |
446 bUI = params[0].ToBool(); | |
447 if (nlength >= 2) | |
448 nStart = params[1].ToInt(); | |
449 if (nlength >= 3) | |
450 nEnd = params[2].ToInt(); | |
451 if (nlength >= 4) | |
452 bSilent = params[3].ToBool(); | |
453 if (nlength >= 5) | |
454 bShrinkToFit = params[4].ToBool(); | |
455 if (nlength >= 6) | |
456 bPrintAsImage = params[5].ToBool(); | |
457 if (nlength >= 7) | |
458 bReverse = params[6].ToBool(); | |
459 if (nlength >= 8) | |
460 bAnnotations = params[7].ToBool(); | |
461 } | |
462 | |
463 if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { | |
464 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, | |
465 bReverse, bAnnotations); | |
466 return TRUE; | |
467 } | |
468 return FALSE; | |
469 } | |
470 | |
471 // removes the specified field from the document. | |
472 // comment: | |
473 // note: if the filed name is not retional, adobe is dumb for it. | |
474 | |
475 FX_BOOL Document::removeField(IJS_Context* cc, | |
476 const std::vector<CJS_Value>& params, | |
477 CJS_Value& vRet, | |
478 CFX_WideString& sError) { | |
479 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | |
480 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) | |
481 return FALSE; | |
482 | |
483 CJS_Context* pContext = (CJS_Context*)cc; | |
484 if (params.size() != 1) { | |
485 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
486 return FALSE; | |
487 } | |
488 | |
489 CFX_WideString sFieldName = params[0].ToCFXWideString(); | |
490 CPDFSDK_InterForm* pInterForm = | |
491 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
492 | |
493 std::vector<CPDFSDK_Widget*> widgets; | |
494 pInterForm->GetWidgets(sFieldName, &widgets); | |
495 | |
496 if (widgets.empty()) | |
497 return TRUE; | |
498 | |
499 for (CPDFSDK_Widget* pWidget : widgets) { | |
500 CFX_FloatRect rcAnnot = pWidget->GetRect(); | |
501 --rcAnnot.left; | |
502 --rcAnnot.bottom; | |
503 ++rcAnnot.right; | |
504 ++rcAnnot.top; | |
505 | |
506 CFX_RectArray aRefresh; | |
507 aRefresh.Add(rcAnnot); | |
508 | |
509 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | |
510 ASSERT(pPage); | |
511 | |
512 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); | |
513 pPageView->DeleteAnnot(pWidget); | |
514 pPageView->UpdateRects(aRefresh); | |
515 } | |
516 m_pDocument->SetChangeMark(); | |
517 | |
518 return TRUE; | |
519 } | |
520 | |
521 // reset filed values within a document. | |
522 // comment: | |
523 // note: if the fields names r not rational, aodbe is dumb for it. | |
524 | |
525 FX_BOOL Document::resetForm(IJS_Context* cc, | |
526 const std::vector<CJS_Value>& params, | |
527 CJS_Value& vRet, | |
528 CFX_WideString& sError) { | |
529 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | |
530 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | |
531 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) | |
532 return FALSE; | |
533 | |
534 CPDFSDK_InterForm* pInterForm = | |
535 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
536 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | |
537 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
538 CJS_Array aName(pRuntime); | |
539 | |
540 if (params.empty()) { | |
541 pPDFForm->ResetForm(TRUE); | |
542 m_pDocument->SetChangeMark(); | |
543 return TRUE; | |
544 } | |
545 | |
546 switch (params[0].GetType()) { | |
547 default: | |
548 aName.Attach(params[0].ToV8Array()); | |
549 break; | |
550 case CJS_Value::VT_string: | |
551 aName.SetElement(0, params[0]); | |
552 break; | |
553 } | |
554 | |
555 std::vector<CPDF_FormField*> aFields; | |
556 for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { | |
557 CJS_Value valElement(pRuntime); | |
558 aName.GetElement(i, valElement); | |
559 CFX_WideString swVal = valElement.ToCFXWideString(); | |
560 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) | |
561 aFields.push_back(pPDFForm->GetField(j, swVal)); | |
562 } | |
563 | |
564 if (!aFields.empty()) { | |
565 pPDFForm->ResetForm(aFields, TRUE, TRUE); | |
566 m_pDocument->SetChangeMark(); | |
567 } | |
568 | |
569 return TRUE; | |
570 } | |
571 | |
572 FX_BOOL Document::saveAs(IJS_Context* cc, | |
573 const std::vector<CJS_Value>& params, | |
574 CJS_Value& vRet, | |
575 CFX_WideString& sError) { | |
576 // Unsafe, not supported. | |
577 return TRUE; | |
578 } | |
579 | |
580 FX_BOOL Document::submitForm(IJS_Context* cc, | |
581 const std::vector<CJS_Value>& params, | |
582 CJS_Value& vRet, | |
583 CFX_WideString& sError) { | |
584 CJS_Context* pContext = (CJS_Context*)cc; | |
585 int nSize = params.size(); | |
586 if (nSize < 1) { | |
587 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
588 return FALSE; | |
589 } | |
590 | |
591 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
592 v8::Isolate* isolate = pRuntime->GetIsolate(); | |
593 CJS_Array aFields(pRuntime); | |
594 CFX_WideString strURL; | |
595 FX_BOOL bFDF = TRUE; | |
596 FX_BOOL bEmpty = FALSE; | |
597 | |
598 CJS_Value v = params[0]; | |
599 if (v.GetType() == CJS_Value::VT_string) { | |
600 strURL = params[0].ToCFXWideString(); | |
601 if (nSize > 1) | |
602 bFDF = params[1].ToBool(); | |
603 if (nSize > 2) | |
604 bEmpty = params[2].ToBool(); | |
605 if (nSize > 3) | |
606 aFields.Attach(params[3].ToV8Array()); | |
607 } else if (v.GetType() == CJS_Value::VT_object) { | |
608 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | |
609 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL"); | |
610 if (!pValue.IsEmpty()) | |
611 strURL = | |
612 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
613 | |
614 pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF"); | |
615 bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); | |
616 | |
617 pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty"); | |
618 bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); | |
619 | |
620 pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); | |
621 aFields.Attach( | |
622 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); | |
623 } | |
624 | |
625 CPDFSDK_InterForm* pInterForm = | |
626 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
627 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | |
628 if (aFields.GetLength() == 0 && bEmpty) { | |
629 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { | |
630 pRuntime->BeginBlock(); | |
631 pInterForm->SubmitForm(strURL, FALSE); | |
632 pRuntime->EndBlock(); | |
633 } | |
634 return TRUE; | |
635 } | |
636 | |
637 std::vector<CPDF_FormField*> fieldObjects; | |
638 for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { | |
639 CJS_Value valName(pRuntime); | |
640 aFields.GetElement(i, valName); | |
641 | |
642 CFX_WideString sName = valName.ToCFXWideString(); | |
643 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | |
644 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { | |
645 CPDF_FormField* pField = pPDFForm->GetField(j, sName); | |
646 if (!bEmpty && pField->GetValue().IsEmpty()) | |
647 continue; | |
648 | |
649 fieldObjects.push_back(pField); | |
650 } | |
651 } | |
652 | |
653 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { | |
654 pRuntime->BeginBlock(); | |
655 pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); | |
656 pRuntime->EndBlock(); | |
657 } | |
658 return TRUE; | |
659 } | |
660 | |
661 void Document::AttachDoc(CPDFSDK_Document* pDoc) { | |
662 m_pDocument = pDoc; | |
663 } | |
664 | |
665 CPDFSDK_Document* Document::GetReaderDoc() { | |
666 return m_pDocument; | |
667 } | |
668 | |
669 FX_BOOL Document::bookmarkRoot(IJS_Context* cc, | |
670 CJS_PropValue& vp, | |
671 CFX_WideString& sError) { | |
672 return TRUE; | |
673 } | |
674 | |
675 FX_BOOL Document::mailDoc(IJS_Context* cc, | |
676 const std::vector<CJS_Value>& params, | |
677 CJS_Value& vRet, | |
678 CFX_WideString& sError) { | |
679 FX_BOOL bUI = TRUE; | |
680 CFX_WideString cTo = L""; | |
681 CFX_WideString cCc = L""; | |
682 CFX_WideString cBcc = L""; | |
683 CFX_WideString cSubject = L""; | |
684 CFX_WideString cMsg = L""; | |
685 | |
686 if (params.size() >= 1) | |
687 bUI = params[0].ToBool(); | |
688 if (params.size() >= 2) | |
689 cTo = params[1].ToCFXWideString(); | |
690 if (params.size() >= 3) | |
691 cCc = params[2].ToCFXWideString(); | |
692 if (params.size() >= 4) | |
693 cBcc = params[3].ToCFXWideString(); | |
694 if (params.size() >= 5) | |
695 cSubject = params[4].ToCFXWideString(); | |
696 if (params.size() >= 6) | |
697 cMsg = params[5].ToCFXWideString(); | |
698 | |
699 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
700 v8::Isolate* isolate = pRuntime->GetIsolate(); | |
701 | |
702 if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { | |
703 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | |
704 | |
705 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI"); | |
706 bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt(); | |
707 | |
708 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo"); | |
709 cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
710 | |
711 pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc"); | |
712 cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
713 | |
714 pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc"); | |
715 cBcc = | |
716 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
717 | |
718 pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject"); | |
719 cSubject = | |
720 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
721 | |
722 pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg"); | |
723 cMsg = | |
724 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
725 } | |
726 | |
727 pRuntime->BeginBlock(); | |
728 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); | |
729 pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), | |
730 cBcc.c_str(), cMsg.c_str()); | |
731 pRuntime->EndBlock(); | |
732 | |
733 return TRUE; | |
734 } | |
735 | |
736 FX_BOOL Document::author(IJS_Context* cc, | |
737 CJS_PropValue& vp, | |
738 CFX_WideString& sError) { | |
739 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
740 if (!pDictionary) | |
741 return FALSE; | |
742 | |
743 if (vp.IsGetting()) { | |
744 vp << pDictionary->GetUnicodeTextBy("Author"); | |
745 return TRUE; | |
746 } else { | |
747 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
748 return FALSE; | |
749 | |
750 CFX_WideString csAuthor; | |
751 vp >> csAuthor; | |
752 pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor)); | |
753 m_pDocument->SetChangeMark(); | |
754 return TRUE; | |
755 } | |
756 } | |
757 | |
758 FX_BOOL Document::info(IJS_Context* cc, | |
759 CJS_PropValue& vp, | |
760 CFX_WideString& sError) { | |
761 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
762 if (!pDictionary) | |
763 return FALSE; | |
764 | |
765 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); | |
766 CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); | |
767 CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); | |
768 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); | |
769 CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); | |
770 CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); | |
771 CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); | |
772 CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); | |
773 CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); | |
774 | |
775 v8::Isolate* isolate = GetIsolate(cc); | |
776 if (vp.IsGetting()) { | |
777 CJS_Context* pContext = (CJS_Context*)cc; | |
778 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
779 v8::Local<v8::Object> pObj = | |
780 FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); | |
781 FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); | |
782 FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); | |
783 FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); | |
784 FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); | |
785 FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); | |
786 FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); | |
787 FXJS_PutObjectString(isolate, pObj, L"CreationDate", | |
788 cwCreationDate.c_str()); | |
789 FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); | |
790 FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); | |
791 | |
792 // It's to be compatible to non-standard info dictionary. | |
793 for (const auto& it : *pDictionary) { | |
794 const CFX_ByteString& bsKey = it.first; | |
795 CPDF_Object* pValueObj = it.second; | |
796 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength()); | |
797 | |
798 if (pValueObj->IsString() || pValueObj->IsName()) { | |
799 FXJS_PutObjectString(isolate, pObj, wsKey.c_str(), | |
800 pValueObj->GetUnicodeText().c_str()); | |
801 } else if (pValueObj->IsNumber()) { | |
802 FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(), | |
803 (float)pValueObj->GetNumber()); | |
804 } else if (pValueObj->IsBoolean()) { | |
805 FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), | |
806 !!pValueObj->GetInteger()); | |
807 } | |
808 } | |
809 vp << pObj; | |
810 } | |
811 return TRUE; | |
812 } | |
813 | |
814 FX_BOOL Document::creationDate(IJS_Context* cc, | |
815 CJS_PropValue& vp, | |
816 CFX_WideString& sError) { | |
817 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
818 if (!pDictionary) | |
819 return FALSE; | |
820 | |
821 if (vp.IsGetting()) { | |
822 vp << pDictionary->GetUnicodeTextBy("CreationDate"); | |
823 } else { | |
824 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
825 return FALSE; | |
826 | |
827 CFX_WideString csCreationDate; | |
828 vp >> csCreationDate; | |
829 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); | |
830 m_pDocument->SetChangeMark(); | |
831 } | |
832 return TRUE; | |
833 } | |
834 | |
835 FX_BOOL Document::creator(IJS_Context* cc, | |
836 CJS_PropValue& vp, | |
837 CFX_WideString& sError) { | |
838 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
839 if (!pDictionary) | |
840 return FALSE; | |
841 | |
842 if (vp.IsGetting()) { | |
843 vp << pDictionary->GetUnicodeTextBy("Creator"); | |
844 } else { | |
845 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
846 return FALSE; | |
847 | |
848 CFX_WideString csCreator; | |
849 vp >> csCreator; | |
850 pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator)); | |
851 m_pDocument->SetChangeMark(); | |
852 } | |
853 return TRUE; | |
854 } | |
855 | |
856 FX_BOOL Document::delay(IJS_Context* cc, | |
857 CJS_PropValue& vp, | |
858 CFX_WideString& sError) { | |
859 if (vp.IsGetting()) { | |
860 vp << m_bDelay; | |
861 } else { | |
862 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
863 return FALSE; | |
864 | |
865 vp >> m_bDelay; | |
866 if (m_bDelay) { | |
867 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) | |
868 delete m_DelayData.GetAt(i); | |
869 | |
870 m_DelayData.RemoveAll(); | |
871 } else { | |
872 CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess; | |
873 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { | |
874 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { | |
875 DelayDataToProcess.Add(pData); | |
876 m_DelayData.SetAt(i, NULL); | |
877 } | |
878 } | |
879 m_DelayData.RemoveAll(); | |
880 for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) { | |
881 CJS_DelayData* pData = DelayDataToProcess.GetAt(i); | |
882 Field::DoDelay(m_pDocument, pData); | |
883 DelayDataToProcess.SetAt(i, NULL); | |
884 delete pData; | |
885 } | |
886 } | |
887 } | |
888 return TRUE; | |
889 } | |
890 | |
891 FX_BOOL Document::keywords(IJS_Context* cc, | |
892 CJS_PropValue& vp, | |
893 CFX_WideString& sError) { | |
894 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
895 if (!pDictionary) | |
896 return FALSE; | |
897 | |
898 if (vp.IsGetting()) { | |
899 vp << pDictionary->GetUnicodeTextBy("Keywords"); | |
900 } else { | |
901 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
902 return FALSE; | |
903 | |
904 CFX_WideString csKeywords; | |
905 vp >> csKeywords; | |
906 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); | |
907 m_pDocument->SetChangeMark(); | |
908 } | |
909 return TRUE; | |
910 } | |
911 | |
912 FX_BOOL Document::modDate(IJS_Context* cc, | |
913 CJS_PropValue& vp, | |
914 CFX_WideString& sError) { | |
915 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
916 if (!pDictionary) | |
917 return FALSE; | |
918 | |
919 if (vp.IsGetting()) { | |
920 vp << pDictionary->GetUnicodeTextBy("ModDate"); | |
921 } else { | |
922 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
923 return FALSE; | |
924 | |
925 CFX_WideString csmodDate; | |
926 vp >> csmodDate; | |
927 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); | |
928 m_pDocument->SetChangeMark(); | |
929 } | |
930 return TRUE; | |
931 } | |
932 | |
933 FX_BOOL Document::producer(IJS_Context* cc, | |
934 CJS_PropValue& vp, | |
935 CFX_WideString& sError) { | |
936 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
937 if (!pDictionary) | |
938 return FALSE; | |
939 | |
940 if (vp.IsGetting()) { | |
941 vp << pDictionary->GetUnicodeTextBy("Producer"); | |
942 } else { | |
943 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
944 return FALSE; | |
945 | |
946 CFX_WideString csproducer; | |
947 vp >> csproducer; | |
948 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); | |
949 m_pDocument->SetChangeMark(); | |
950 } | |
951 return TRUE; | |
952 } | |
953 | |
954 FX_BOOL Document::subject(IJS_Context* cc, | |
955 CJS_PropValue& vp, | |
956 CFX_WideString& sError) { | |
957 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
958 if (!pDictionary) | |
959 return FALSE; | |
960 | |
961 if (vp.IsGetting()) { | |
962 vp << pDictionary->GetUnicodeTextBy("Subject"); | |
963 } else { | |
964 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
965 return FALSE; | |
966 | |
967 CFX_WideString cssubject; | |
968 vp >> cssubject; | |
969 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); | |
970 m_pDocument->SetChangeMark(); | |
971 } | |
972 return TRUE; | |
973 } | |
974 | |
975 FX_BOOL Document::title(IJS_Context* cc, | |
976 CJS_PropValue& vp, | |
977 CFX_WideString& sError) { | |
978 if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) | |
979 return FALSE; | |
980 | |
981 CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); | |
982 if (!pDictionary) | |
983 return FALSE; | |
984 | |
985 if (vp.IsGetting()) { | |
986 vp << pDictionary->GetUnicodeTextBy("Title"); | |
987 } else { | |
988 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | |
989 return FALSE; | |
990 | |
991 CFX_WideString cstitle; | |
992 vp >> cstitle; | |
993 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); | |
994 m_pDocument->SetChangeMark(); | |
995 } | |
996 return TRUE; | |
997 } | |
998 | |
999 FX_BOOL Document::numPages(IJS_Context* cc, | |
1000 CJS_PropValue& vp, | |
1001 CFX_WideString& sError) { | |
1002 if (vp.IsSetting()) { | |
1003 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1004 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
1005 return FALSE; | |
1006 } | |
1007 vp << m_pDocument->GetPageCount(); | |
1008 return TRUE; | |
1009 } | |
1010 | |
1011 FX_BOOL Document::external(IJS_Context* cc, | |
1012 CJS_PropValue& vp, | |
1013 CFX_WideString& sError) { | |
1014 // In Chrome case,should always return true. | |
1015 if (vp.IsGetting()) { | |
1016 vp << true; | |
1017 } | |
1018 return TRUE; | |
1019 } | |
1020 | |
1021 FX_BOOL Document::filesize(IJS_Context* cc, | |
1022 CJS_PropValue& vp, | |
1023 CFX_WideString& sError) { | |
1024 if (vp.IsSetting()) { | |
1025 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1026 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
1027 return FALSE; | |
1028 } | |
1029 vp << 0; | |
1030 return TRUE; | |
1031 } | |
1032 | |
1033 FX_BOOL Document::mouseX(IJS_Context* cc, | |
1034 CJS_PropValue& vp, | |
1035 CFX_WideString& sError) { | |
1036 return TRUE; | |
1037 } | |
1038 | |
1039 FX_BOOL Document::mouseY(IJS_Context* cc, | |
1040 CJS_PropValue& vp, | |
1041 CFX_WideString& sError) { | |
1042 return TRUE; | |
1043 } | |
1044 | |
1045 FX_BOOL Document::baseURL(IJS_Context* cc, | |
1046 CJS_PropValue& vp, | |
1047 CFX_WideString& sError) { | |
1048 if (vp.IsGetting()) { | |
1049 vp << m_cwBaseURL; | |
1050 } else { | |
1051 vp >> m_cwBaseURL; | |
1052 } | |
1053 return TRUE; | |
1054 } | |
1055 | |
1056 FX_BOOL Document::calculate(IJS_Context* cc, | |
1057 CJS_PropValue& vp, | |
1058 CFX_WideString& sError) { | |
1059 CPDFSDK_InterForm* pInterForm = | |
1060 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
1061 | |
1062 if (vp.IsGetting()) { | |
1063 if (pInterForm->IsCalculateEnabled()) | |
1064 vp << true; | |
1065 else | |
1066 vp << false; | |
1067 } else { | |
1068 bool bCalculate; | |
1069 vp >> bCalculate; | |
1070 | |
1071 pInterForm->EnableCalculate(bCalculate); | |
1072 } | |
1073 | |
1074 return TRUE; | |
1075 } | |
1076 | |
1077 FX_BOOL Document::documentFileName(IJS_Context* cc, | |
1078 CJS_PropValue& vp, | |
1079 CFX_WideString& sError) { | |
1080 if (vp.IsSetting()) { | |
1081 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1082 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
1083 return FALSE; | |
1084 } | |
1085 CFX_WideString wsFilePath = m_pDocument->GetPath(); | |
1086 int32_t i = wsFilePath.GetLength() - 1; | |
1087 for (; i >= 0; i--) { | |
1088 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') | |
1089 break; | |
1090 } | |
1091 if (i >= 0 && i < wsFilePath.GetLength() - 1) { | |
1092 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); | |
1093 } else { | |
1094 vp << L""; | |
1095 } | |
1096 return TRUE; | |
1097 } | |
1098 | |
1099 FX_BOOL Document::path(IJS_Context* cc, | |
1100 CJS_PropValue& vp, | |
1101 CFX_WideString& sError) { | |
1102 if (vp.IsSetting()) { | |
1103 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1104 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
1105 return FALSE; | |
1106 } | |
1107 vp << app::SysPathToPDFPath(m_pDocument->GetPath()); | |
1108 return TRUE; | |
1109 } | |
1110 | |
1111 FX_BOOL Document::pageWindowRect(IJS_Context* cc, | |
1112 CJS_PropValue& vp, | |
1113 CFX_WideString& sError) { | |
1114 return TRUE; | |
1115 } | |
1116 | |
1117 FX_BOOL Document::layout(IJS_Context* cc, | |
1118 CJS_PropValue& vp, | |
1119 CFX_WideString& sError) { | |
1120 return TRUE; | |
1121 } | |
1122 | |
1123 FX_BOOL Document::addLink(IJS_Context* cc, | |
1124 const std::vector<CJS_Value>& params, | |
1125 CJS_Value& vRet, | |
1126 CFX_WideString& sError) { | |
1127 return TRUE; | |
1128 } | |
1129 | |
1130 FX_BOOL Document::closeDoc(IJS_Context* cc, | |
1131 const std::vector<CJS_Value>& params, | |
1132 CJS_Value& vRet, | |
1133 CFX_WideString& sError) { | |
1134 return TRUE; | |
1135 } | |
1136 | |
1137 FX_BOOL Document::getPageBox(IJS_Context* cc, | |
1138 const std::vector<CJS_Value>& params, | |
1139 CJS_Value& vRet, | |
1140 CFX_WideString& sError) { | |
1141 return TRUE; | |
1142 } | |
1143 | |
1144 FX_BOOL Document::getAnnot(IJS_Context* cc, | |
1145 const std::vector<CJS_Value>& params, | |
1146 CJS_Value& vRet, | |
1147 CFX_WideString& sError) { | |
1148 return TRUE; | |
1149 } | |
1150 | |
1151 FX_BOOL Document::getAnnots(IJS_Context* cc, | |
1152 const std::vector<CJS_Value>& params, | |
1153 CJS_Value& vRet, | |
1154 CFX_WideString& sError) { | |
1155 vRet.SetNull(); | |
1156 return TRUE; | |
1157 } | |
1158 | |
1159 FX_BOOL Document::getAnnot3D(IJS_Context* cc, | |
1160 const std::vector<CJS_Value>& params, | |
1161 CJS_Value& vRet, | |
1162 CFX_WideString& sError) { | |
1163 vRet.SetNull(); | |
1164 return TRUE; | |
1165 } | |
1166 | |
1167 FX_BOOL Document::getAnnots3D(IJS_Context* cc, | |
1168 const std::vector<CJS_Value>& params, | |
1169 CJS_Value& vRet, | |
1170 CFX_WideString& sError) { | |
1171 vRet = CJS_Value::VT_undefined; | |
1172 return TRUE; | |
1173 } | |
1174 | |
1175 FX_BOOL Document::getOCGs(IJS_Context* cc, | |
1176 const std::vector<CJS_Value>& params, | |
1177 CJS_Value& vRet, | |
1178 CFX_WideString& sError) { | |
1179 return TRUE; | |
1180 } | |
1181 | |
1182 FX_BOOL Document::getLinks(IJS_Context* cc, | |
1183 const std::vector<CJS_Value>& params, | |
1184 CJS_Value& vRet, | |
1185 CFX_WideString& sError) { | |
1186 return TRUE; | |
1187 } | |
1188 | |
1189 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { | |
1190 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && | |
1191 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); | |
1192 } | |
1193 | |
1194 FX_BOOL Document::addIcon(IJS_Context* cc, | |
1195 const std::vector<CJS_Value>& params, | |
1196 CJS_Value& vRet, | |
1197 CFX_WideString& sError) { | |
1198 CJS_Context* pContext = (CJS_Context*)cc; | |
1199 if (params.size() != 2) { | |
1200 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
1201 return FALSE; | |
1202 } | |
1203 CFX_WideString swIconName = params[0].ToCFXWideString(); | |
1204 | |
1205 if (params[1].GetType() != CJS_Value::VT_object) { | |
1206 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | |
1207 return FALSE; | |
1208 } | |
1209 | |
1210 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); | |
1211 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { | |
1212 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | |
1213 return FALSE; | |
1214 } | |
1215 | |
1216 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); | |
1217 if (!pEmbedObj) { | |
1218 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | |
1219 return FALSE; | |
1220 } | |
1221 | |
1222 m_IconList.push_back(std::unique_ptr<IconElement>( | |
1223 new IconElement(swIconName, (Icon*)pEmbedObj))); | |
1224 return TRUE; | |
1225 } | |
1226 | |
1227 FX_BOOL Document::icons(IJS_Context* cc, | |
1228 CJS_PropValue& vp, | |
1229 CFX_WideString& sError) { | |
1230 if (vp.IsSetting()) { | |
1231 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1232 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); | |
1233 return FALSE; | |
1234 } | |
1235 | |
1236 if (m_IconList.empty()) { | |
1237 vp.SetNull(); | |
1238 return TRUE; | |
1239 } | |
1240 | |
1241 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
1242 CJS_Array Icons(pRuntime); | |
1243 | |
1244 int i = 0; | |
1245 for (const auto& pIconElement : m_IconList) { | |
1246 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | |
1247 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | |
1248 if (pObj.IsEmpty()) | |
1249 return FALSE; | |
1250 | |
1251 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | |
1252 if (!pJS_Icon) | |
1253 return FALSE; | |
1254 | |
1255 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | |
1256 if (!pIcon) | |
1257 return FALSE; | |
1258 | |
1259 pIcon->SetStream(pIconElement->IconStream->GetStream()); | |
1260 pIcon->SetIconName(pIconElement->IconName); | |
1261 Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon)); | |
1262 } | |
1263 | |
1264 vp << Icons; | |
1265 return TRUE; | |
1266 } | |
1267 | |
1268 FX_BOOL Document::getIcon(IJS_Context* cc, | |
1269 const std::vector<CJS_Value>& params, | |
1270 CJS_Value& vRet, | |
1271 CFX_WideString& sError) { | |
1272 CJS_Context* pContext = (CJS_Context*)cc; | |
1273 if (params.size() != 1) { | |
1274 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
1275 return FALSE; | |
1276 } | |
1277 | |
1278 if (m_IconList.empty()) | |
1279 return FALSE; | |
1280 | |
1281 CFX_WideString swIconName = params[0].ToCFXWideString(); | |
1282 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
1283 | |
1284 for (const auto& pIconElement : m_IconList) { | |
1285 if (pIconElement->IconName == swIconName) { | |
1286 Icon* pRetIcon = pIconElement->IconStream; | |
1287 | |
1288 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | |
1289 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | |
1290 if (pObj.IsEmpty()) | |
1291 return FALSE; | |
1292 | |
1293 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); | |
1294 if (!pJS_Icon) | |
1295 return FALSE; | |
1296 | |
1297 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | |
1298 if (!pIcon) | |
1299 return FALSE; | |
1300 | |
1301 pIcon->SetIconName(swIconName); | |
1302 pIcon->SetStream(pRetIcon->GetStream()); | |
1303 vRet = pJS_Icon; | |
1304 return TRUE; | |
1305 } | |
1306 } | |
1307 | |
1308 return FALSE; | |
1309 } | |
1310 | |
1311 FX_BOOL Document::removeIcon(IJS_Context* cc, | |
1312 const std::vector<CJS_Value>& params, | |
1313 CJS_Value& vRet, | |
1314 CFX_WideString& sError) { | |
1315 // Unsafe, no supported. | |
1316 return TRUE; | |
1317 } | |
1318 | |
1319 FX_BOOL Document::createDataObject(IJS_Context* cc, | |
1320 const std::vector<CJS_Value>& params, | |
1321 CJS_Value& vRet, | |
1322 CFX_WideString& sError) { | |
1323 // Unsafe, not implemented. | |
1324 return TRUE; | |
1325 } | |
1326 | |
1327 FX_BOOL Document::media(IJS_Context* cc, | |
1328 CJS_PropValue& vp, | |
1329 CFX_WideString& sError) { | |
1330 return TRUE; | |
1331 } | |
1332 | |
1333 FX_BOOL Document::calculateNow(IJS_Context* cc, | |
1334 const std::vector<CJS_Value>& params, | |
1335 CJS_Value& vRet, | |
1336 CFX_WideString& sError) { | |
1337 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | |
1338 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || | |
1339 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) | |
1340 return FALSE; | |
1341 | |
1342 CPDFSDK_InterForm* pInterForm = | |
1343 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | |
1344 pInterForm->OnCalculate(); | |
1345 return TRUE; | |
1346 } | |
1347 | |
1348 FX_BOOL Document::Collab(IJS_Context* cc, | |
1349 CJS_PropValue& vp, | |
1350 CFX_WideString& sError) { | |
1351 return TRUE; | |
1352 } | |
1353 | |
1354 FX_BOOL Document::getPageNthWord(IJS_Context* cc, | |
1355 const std::vector<CJS_Value>& params, | |
1356 CJS_Value& vRet, | |
1357 CFX_WideString& sError) { | |
1358 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | |
1359 return FALSE; | |
1360 | |
1361 int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; | |
1362 int nWordNo = params.size() > 1 ? params[1].ToInt() : 0; | |
1363 bool bStrip = params.size() > 2 ? params[2].ToBool() : true; | |
1364 | |
1365 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | |
1366 if (!pDocument) | |
1367 return FALSE; | |
1368 | |
1369 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1370 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | |
1371 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | |
1372 return FALSE; | |
1373 } | |
1374 | |
1375 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | |
1376 if (!pPageDict) | |
1377 return FALSE; | |
1378 | |
1379 CPDF_Page page; | |
1380 page.Load(pDocument, pPageDict); | |
1381 page.ParseContent(nullptr); | |
1382 | |
1383 int nWords = 0; | |
1384 CFX_WideString swRet; | |
1385 for (auto& pPageObj : *page.GetPageObjectList()) { | |
1386 if (pPageObj->IsText()) { | |
1387 CPDF_TextObject* pTextObj = pPageObj->AsText(); | |
1388 int nObjWords = CountWords(pTextObj); | |
1389 if (nWords + nObjWords >= nWordNo) { | |
1390 swRet = GetObjWordStr(pTextObj, nWordNo - nWords); | |
1391 break; | |
1392 } | |
1393 nWords += nObjWords; | |
1394 } | |
1395 } | |
1396 | |
1397 if (bStrip) { | |
1398 swRet.TrimLeft(); | |
1399 swRet.TrimRight(); | |
1400 } | |
1401 | |
1402 vRet = swRet.c_str(); | |
1403 return TRUE; | |
1404 } | |
1405 | |
1406 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, | |
1407 const std::vector<CJS_Value>& params, | |
1408 CJS_Value& vRet, | |
1409 CFX_WideString& sError) { | |
1410 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | |
1411 return FALSE; | |
1412 | |
1413 return FALSE; | |
1414 } | |
1415 | |
1416 FX_BOOL Document::getPageNumWords(IJS_Context* cc, | |
1417 const std::vector<CJS_Value>& params, | |
1418 CJS_Value& vRet, | |
1419 CFX_WideString& sError) { | |
1420 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | |
1421 return FALSE; | |
1422 | |
1423 int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; | |
1424 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | |
1425 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1426 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | |
1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | |
1428 return FALSE; | |
1429 } | |
1430 | |
1431 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | |
1432 if (!pPageDict) | |
1433 return FALSE; | |
1434 | |
1435 CPDF_Page page; | |
1436 page.Load(pDocument, pPageDict); | |
1437 page.ParseContent(nullptr); | |
1438 | |
1439 int nWords = 0; | |
1440 for (auto& pPageObj : *page.GetPageObjectList()) { | |
1441 if (pPageObj->IsText()) | |
1442 nWords += CountWords(pPageObj->AsText()); | |
1443 } | |
1444 | |
1445 vRet = nWords; | |
1446 return TRUE; | |
1447 } | |
1448 | |
1449 FX_BOOL Document::getPrintParams(IJS_Context* cc, | |
1450 const std::vector<CJS_Value>& params, | |
1451 CJS_Value& vRet, | |
1452 CFX_WideString& sError) { | |
1453 CJS_Context* pContext = (CJS_Context*)cc; | |
1454 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
1455 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | |
1456 pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); | |
1457 | |
1458 // Not implemented yet. | |
1459 | |
1460 vRet = pRetObj; | |
1461 return TRUE; | |
1462 } | |
1463 | |
1464 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) | |
1465 | |
1466 int Document::CountWords(CPDF_TextObject* pTextObj) { | |
1467 if (!pTextObj) | |
1468 return 0; | |
1469 | |
1470 int nWords = 0; | |
1471 | |
1472 CPDF_Font* pFont = pTextObj->GetFont(); | |
1473 if (!pFont) | |
1474 return 0; | |
1475 | |
1476 FX_BOOL bIsLatin = FALSE; | |
1477 | |
1478 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { | |
1479 FX_DWORD charcode = -1; | |
1480 FX_FLOAT kerning; | |
1481 | |
1482 pTextObj->GetCharInfo(i, charcode, kerning); | |
1483 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); | |
1484 | |
1485 FX_WORD unicode = 0; | |
1486 if (swUnicode.GetLength() > 0) | |
1487 unicode = swUnicode[0]; | |
1488 | |
1489 if (ISLATINWORD(unicode) && bIsLatin) | |
1490 continue; | |
1491 | |
1492 bIsLatin = ISLATINWORD(unicode); | |
1493 if (unicode != 0x20) | |
1494 nWords++; | |
1495 } | |
1496 | |
1497 return nWords; | |
1498 } | |
1499 | |
1500 CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, | |
1501 int nWordIndex) { | |
1502 CFX_WideString swRet; | |
1503 | |
1504 CPDF_Font* pFont = pTextObj->GetFont(); | |
1505 if (!pFont) | |
1506 return L""; | |
1507 | |
1508 int nWords = 0; | |
1509 FX_BOOL bIsLatin = FALSE; | |
1510 | |
1511 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { | |
1512 FX_DWORD charcode = -1; | |
1513 FX_FLOAT kerning; | |
1514 | |
1515 pTextObj->GetCharInfo(i, charcode, kerning); | |
1516 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); | |
1517 | |
1518 FX_WORD unicode = 0; | |
1519 if (swUnicode.GetLength() > 0) | |
1520 unicode = swUnicode[0]; | |
1521 | |
1522 if (ISLATINWORD(unicode) && bIsLatin) { | |
1523 } else { | |
1524 bIsLatin = ISLATINWORD(unicode); | |
1525 if (unicode != 0x20) | |
1526 nWords++; | |
1527 } | |
1528 | |
1529 if (nWords - 1 == nWordIndex) | |
1530 swRet += unicode; | |
1531 } | |
1532 | |
1533 return swRet; | |
1534 } | |
1535 | |
1536 FX_BOOL Document::zoom(IJS_Context* cc, | |
1537 CJS_PropValue& vp, | |
1538 CFX_WideString& sError) { | |
1539 return TRUE; | |
1540 } | |
1541 | |
1542 /** | |
1543 (none, NoVary) | |
1544 (fitP, FitPage) | |
1545 (fitW, FitWidth) | |
1546 (fitH, FitHeight) | |
1547 (fitV, FitVisibleWidth) | |
1548 (pref, Preferred) | |
1549 (refW, ReflowWidth) | |
1550 */ | |
1551 | |
1552 FX_BOOL Document::zoomType(IJS_Context* cc, | |
1553 CJS_PropValue& vp, | |
1554 CFX_WideString& sError) { | |
1555 return TRUE; | |
1556 } | |
1557 | |
1558 FX_BOOL Document::deletePages(IJS_Context* cc, | |
1559 const std::vector<CJS_Value>& params, | |
1560 CJS_Value& vRet, | |
1561 CFX_WideString& sError) { | |
1562 // Unsafe, no supported. | |
1563 return TRUE; | |
1564 } | |
1565 | |
1566 FX_BOOL Document::extractPages(IJS_Context* cc, | |
1567 const std::vector<CJS_Value>& params, | |
1568 CJS_Value& vRet, | |
1569 CFX_WideString& sError) { | |
1570 // Unsafe, not supported. | |
1571 return TRUE; | |
1572 } | |
1573 | |
1574 FX_BOOL Document::insertPages(IJS_Context* cc, | |
1575 const std::vector<CJS_Value>& params, | |
1576 CJS_Value& vRet, | |
1577 CFX_WideString& sError) { | |
1578 // Unsafe, not supported. | |
1579 return TRUE; | |
1580 } | |
1581 | |
1582 FX_BOOL Document::replacePages(IJS_Context* cc, | |
1583 const std::vector<CJS_Value>& params, | |
1584 CJS_Value& vRet, | |
1585 CFX_WideString& sError) { | |
1586 // Unsafe, not supported. | |
1587 return TRUE; | |
1588 } | |
1589 | |
1590 FX_BOOL Document::getURL(IJS_Context* cc, | |
1591 const std::vector<CJS_Value>& params, | |
1592 CJS_Value& vRet, | |
1593 CFX_WideString& sError) { | |
1594 // Unsafe, not supported. | |
1595 return TRUE; | |
1596 } | |
1597 | |
1598 void Document::AddDelayData(CJS_DelayData* pData) { | |
1599 m_DelayData.Add(pData); | |
1600 } | |
1601 | |
1602 void Document::DoFieldDelay(const CFX_WideString& sFieldName, | |
1603 int nControlIndex) { | |
1604 CFX_DWordArray DelArray; | |
1605 CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex; | |
1606 | |
1607 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { | |
1608 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { | |
1609 if (pData->sFieldName == sFieldName && | |
1610 pData->nControlIndex == nControlIndex) { | |
1611 DelayDataForFieldAndControlIndex.Add(pData); | |
1612 m_DelayData.SetAt(i, NULL); | |
1613 DelArray.Add(i); | |
1614 } | |
1615 } | |
1616 } | |
1617 | |
1618 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | |
1619 m_DelayData.RemoveAt(DelArray[j]); | |
1620 } | |
1621 | |
1622 for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz; | |
1623 i++) { | |
1624 CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); | |
1625 Field::DoDelay(m_pDocument, pData); | |
1626 DelayDataForFieldAndControlIndex.SetAt(i, NULL); | |
1627 delete pData; | |
1628 } | |
1629 } | |
1630 | |
1631 CJS_Document* Document::GetCJSDoc() const { | |
1632 return static_cast<CJS_Document*>(m_pJSObject); | |
1633 } | |
OLD | NEW |