Initial commit.
[pdfium.git] / fpdfsdk / src / javascript / Document.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../include/javascript/JavaScript.h"\r
8 #include "../../include/javascript/IJavaScript.h"\r
9 #include "../../include/javascript/JS_Define.h"\r
10 #include "../../include/javascript/JS_Object.h"\r
11 #include "../../include/javascript/JS_Value.h"\r
12 #include "../../include/javascript/Document.h"\r
13 #include "../../include/javascript/JS_EventHandler.h"\r
14 #include "../../include/javascript/JS_Context.h"\r
15 #include "../../include/javascript/JS_Runtime.h"\r
16 #include "../../include/javascript/app.h"\r
17 #include "../../include/javascript/Field.h"\r
18 #include "../../include/javascript/Icon.h"\r
19 #include "../../include/javascript/Field.h"\r
20 \r
21 static v8::Isolate* GetIsolate(IFXJS_Context* cc)\r
22 {\r
23         CJS_Context* pContext = (CJS_Context *)cc;\r
24         ASSERT(pContext != NULL);\r
25 \r
26         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
27         ASSERT(pRuntime != NULL);\r
28 \r
29         return pRuntime->GetIsolate();\r
30 }\r
31 \r
32 BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)\r
33 END_JS_STATIC_CONST()\r
34 \r
35 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)\r
36 END_JS_STATIC_PROP()\r
37 \r
38 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)\r
39 END_JS_STATIC_METHOD()\r
40 \r
41 IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)\r
42 \r
43 PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)\r
44 : CJS_EmbedObj(pJSObject)\r
45 {\r
46         bUI = TRUE;\r
47         nStart = 0;\r
48         nEnd = 0;\r
49         bSilent = FALSE;\r
50         bShrinkToFit = FALSE;\r
51         bPrintAsImage = FALSE;\r
52         bReverse = FALSE;\r
53         bAnnotations = TRUE;\r
54 }\r
55 \r
56 /* ---------------------- Document ---------------------- */\r
57 \r
58 #define MINWIDTH  5.0f\r
59 #define MINHEIGHT 5.0f\r
60 \r
61 BEGIN_JS_STATIC_CONST(CJS_Document)\r
62 END_JS_STATIC_CONST()\r
63 \r
64 BEGIN_JS_STATIC_PROP(CJS_Document)\r
65         JS_STATIC_PROP_ENTRY(ADBE)\r
66         JS_STATIC_PROP_ENTRY(author)\r
67         JS_STATIC_PROP_ENTRY(baseURL)\r
68         JS_STATIC_PROP_ENTRY(bookmarkRoot)\r
69         JS_STATIC_PROP_ENTRY(calculate)\r
70         JS_STATIC_PROP_ENTRY(Collab)\r
71         JS_STATIC_PROP_ENTRY(creationDate)\r
72         JS_STATIC_PROP_ENTRY(creator)\r
73         JS_STATIC_PROP_ENTRY(delay)\r
74         JS_STATIC_PROP_ENTRY(dirty)\r
75         JS_STATIC_PROP_ENTRY(documentFileName)\r
76         JS_STATIC_PROP_ENTRY(external)\r
77         JS_STATIC_PROP_ENTRY(filesize)\r
78         JS_STATIC_PROP_ENTRY(icons)\r
79         JS_STATIC_PROP_ENTRY(info)   \r
80         JS_STATIC_PROP_ENTRY(keywords)\r
81         JS_STATIC_PROP_ENTRY(layout)\r
82         JS_STATIC_PROP_ENTRY(media)\r
83         JS_STATIC_PROP_ENTRY(modDate)\r
84         JS_STATIC_PROP_ENTRY(mouseX)\r
85         JS_STATIC_PROP_ENTRY(mouseY)\r
86         JS_STATIC_PROP_ENTRY(numFields)\r
87         JS_STATIC_PROP_ENTRY(numPages)\r
88         JS_STATIC_PROP_ENTRY(pageNum)   \r
89         JS_STATIC_PROP_ENTRY(pageWindowRect)\r
90         JS_STATIC_PROP_ENTRY(path)\r
91         JS_STATIC_PROP_ENTRY(producer)\r
92         JS_STATIC_PROP_ENTRY(subject)\r
93         JS_STATIC_PROP_ENTRY(title)\r
94         JS_STATIC_PROP_ENTRY(zoom)\r
95         JS_STATIC_PROP_ENTRY(zoomType)\r
96 END_JS_STATIC_PROP()\r
97 \r
98 BEGIN_JS_STATIC_METHOD(CJS_Document)\r
99         JS_STATIC_METHOD_ENTRY(addAnnot,0)\r
100         JS_STATIC_METHOD_ENTRY(addField, 4)\r
101         JS_STATIC_METHOD_ENTRY(addLink, 0)\r
102         JS_STATIC_METHOD_ENTRY(addIcon, 0)\r
103         JS_STATIC_METHOD_ENTRY(calculateNow, 0)\r
104         JS_STATIC_METHOD_ENTRY(closeDoc, 0)\r
105         JS_STATIC_METHOD_ENTRY(createDataObject, 0)\r
106         JS_STATIC_METHOD_ENTRY(deletePages, 2)\r
107         JS_STATIC_METHOD_ENTRY(exportAsText, 3)\r
108         JS_STATIC_METHOD_ENTRY(exportAsFDF, 6)\r
109         JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5)\r
110         JS_STATIC_METHOD_ENTRY(extractPages, 3)\r
111         JS_STATIC_METHOD_ENTRY(getAnnot, 0)\r
112         JS_STATIC_METHOD_ENTRY(getAnnots, 2)\r
113         JS_STATIC_METHOD_ENTRY(getAnnot3D, 2)\r
114         JS_STATIC_METHOD_ENTRY(getAnnots3D, 1)\r
115         JS_STATIC_METHOD_ENTRY(getField, 1)\r
116         JS_STATIC_METHOD_ENTRY(getIcon, 0)\r
117         JS_STATIC_METHOD_ENTRY(getLinks, 0)\r
118         JS_STATIC_METHOD_ENTRY(getNthFieldName, 1)\r
119         JS_STATIC_METHOD_ENTRY(getOCGs, 0)\r
120         JS_STATIC_METHOD_ENTRY(getPageBox, 0)\r
121         JS_STATIC_METHOD_ENTRY(getPageNthWord, 3)\r
122         JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2)\r
123         JS_STATIC_METHOD_ENTRY(getPageNumWords, 1)\r
124         JS_STATIC_METHOD_ENTRY(getPrintParams, 0)\r
125         JS_STATIC_METHOD_ENTRY(getURL, 2)\r
126         JS_STATIC_METHOD_ENTRY(importAnFDF, 1)\r
127         JS_STATIC_METHOD_ENTRY(importAnXFDF, 1)\r
128         JS_STATIC_METHOD_ENTRY(importTextData, 2)\r
129         JS_STATIC_METHOD_ENTRY(insertPages, 4)\r
130         JS_STATIC_METHOD_ENTRY(mailForm, 6)\r
131         JS_STATIC_METHOD_ENTRY(print, 9)\r
132         JS_STATIC_METHOD_ENTRY(removeField, 1)\r
133         JS_STATIC_METHOD_ENTRY(replacePages, 4)\r
134         JS_STATIC_METHOD_ENTRY(resetForm, 1)\r
135         JS_STATIC_METHOD_ENTRY(removeIcon, 0)\r
136         JS_STATIC_METHOD_ENTRY(saveAs, 5)\r
137         JS_STATIC_METHOD_ENTRY(submitForm, 23)\r
138         JS_STATIC_METHOD_ENTRY(mailDoc, 0)              \r
139 END_JS_STATIC_METHOD()\r
140 \r
141 IMPLEMENT_JS_CLASS(CJS_Document, Document)\r
142 \r
143 FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)\r
144 {\r
145         CJS_Context* pContext = (CJS_Context*)cc;\r
146         ASSERT(pContext != NULL);\r
147 \r
148         Document* pDoc = (Document*)GetEmbedObject();\r
149         ASSERT(pDoc != NULL);\r
150         \r
151         pDoc->AttachDoc(pContext->GetReaderDocument());\r
152         pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());\r
153         return TRUE;\r
154 };\r
155 \r
156 /* --------------------------------- Document --------------------------------- */\r
157 \r
158 Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),\r
159         m_cwBaseURL(L""),\r
160         m_pIconTree(NULL),\r
161         m_pDocument(NULL),\r
162         m_bDelay(FALSE),\r
163         m_isolate(NULL)\r
164 {\r
165 }\r
166 \r
167 Document::~Document()\r
168 {\r
169         if (m_pIconTree)\r
170         {\r
171                 m_pIconTree->DeleteIconTree();\r
172                 delete m_pIconTree;\r
173                 m_pIconTree = NULL;\r
174         }\r
175         for (int i=0; i<m_DelayData.GetSize(); i++)\r
176         {\r
177                 if (CJS_DelayData* pData = m_DelayData.GetAt(i))\r
178                 {\r
179                         delete pData;\r
180                         pData = NULL;\r
181                         m_DelayData.SetAt(i, NULL);\r
182                         \r
183                 }\r
184         }\r
185 \r
186         m_DelayData.RemoveAll();\r
187         m_DelayAnnotData.RemoveAll();\r
188 }\r
189 \r
190 //the total number of fileds in document.\r
191 FX_BOOL Document::numFields(OBJ_PROP_PARAMS)\r
192 {\r
193         if (!vp.IsGetting()) return FALSE;\r
194 \r
195         ASSERT(m_pDocument != NULL);\r
196 \r
197         CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();\r
198         ASSERT(pInterForm != NULL);\r
199 \r
200         CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();\r
201         ASSERT(pPDFForm != NULL);\r
202 \r
203         vp << (int)pPDFForm->CountFields();\r
204 \r
205         return TRUE;\r
206 }\r
207 \r
208 FX_BOOL Document::dirty(OBJ_PROP_PARAMS)\r
209 {\r
210         ASSERT(m_pDocument != NULL);\r
211 \r
212         if (vp.IsGetting())\r
213         {\r
214                 if (m_pDocument->GetChangeMark())\r
215                         vp << true;\r
216                 else\r
217                         vp << false;\r
218         }\r
219         else\r
220         {\r
221                 bool bChanged = false;\r
222 \r
223                 vp >> bChanged;\r
224 \r
225                 if (bChanged)\r
226                         m_pDocument->SetChangeMark();\r
227                 else\r
228                         m_pDocument->ClearChangeMark();\r
229         }\r
230 \r
231         return TRUE;\r
232 }\r
233 \r
234 FX_BOOL Document::ADBE(OBJ_PROP_PARAMS)\r
235 {\r
236         ASSERT(m_pDocument != NULL);\r
237 \r
238         if (vp.IsGetting())\r
239         {\r
240                 vp.SetNull();\r
241         }\r
242         else\r
243         {\r
244         }\r
245 \r
246         return TRUE;\r
247 }\r
248 \r
249 FX_BOOL Document::pageNum(OBJ_PROP_PARAMS)\r
250 {\r
251         ASSERT(m_pDocument != NULL);\r
252 \r
253         if (vp.IsGetting())\r
254         {                       \r
255                 if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())\r
256                 {\r
257                         vp << pPageView->GetPageIndex();\r
258                 }\r
259         }\r
260         else\r
261         {               \r
262                 int iPageCount = m_pDocument->GetPageCount();\r
263 \r
264                 int iPageNum = 0;\r
265                 vp >> iPageNum;\r
266 \r
267                 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
268                 if(!pEnv)\r
269                         return FALSE;\r
270 \r
271                 if (iPageNum >= 0 && iPageNum < iPageCount)\r
272                 {\r
273                          pEnv->JS_docgotoPage(iPageNum);\r
274                 }\r
275                 else if (iPageNum >= iPageCount)\r
276                 {\r
277                          pEnv->JS_docgotoPage(iPageCount-1);\r
278                 }\r
279                 else if (iPageNum < 0)\r
280                 {\r
281                          pEnv->JS_docgotoPage(0);\r
282                 }\r
283         }\r
284 \r
285         return TRUE;\r
286 }\r
287 \r
288 FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj)\r
289 {\r
290         return TRUE;\r
291 }\r
292 \r
293 FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS)\r
294 {\r
295         return TRUE;\r
296 }\r
297 \r
298 FX_BOOL Document::addField(OBJ_METHOD_PARAMS)\r
299 {\r
300         //Doesn't support.\r
301         return TRUE;\r
302 }\r
303 \r
304 //exports form fields as a tab-delimited text file to a local hard disk.\r
305 //comment: need reader support\r
306 //note : watch the third parameter:cPath, for what case it can be safely saved?\r
307 //int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath);\r
308 //return value, int the index of the parameters illegal, the index is based on 1.\r
309 \r
310 FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS)\r
311 {\r
312         if (IsSafeMode(cc)) return TRUE;\r
313         return TRUE;\r
314 }\r
315 \r
316 //exports form fields as a fdf file to the local hard drive\r
317 //comment: need reader supports\r
318 //note:the last parameter hasn't been confirmed.because the previous one blocks the way.\r
319 //int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations);\r
320 \r
321 FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS)\r
322 {\r
323         v8::Isolate* isolate = GetIsolate(cc);\r
324         if (IsSafeMode(cc)) return TRUE;\r
325 \r
326         ASSERT(m_pDocument != NULL);\r
327 \r
328         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
329 \r
330         FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE;\r
331         FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE;\r
332         FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE;\r
333         CJS_Array arrayFileds(isolate);\r
334         if (!bWhole)\r
335                 arrayFileds.Attach(params[2]);\r
336         //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE;\r
337     CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
338 \r
339         if (swFilePath.IsEmpty())\r
340         {\r
341                 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
342                 swFilePath = pEnv->JS_fieldBrowse();\r
343                 if(swFilePath.IsEmpty())\r
344                         return TRUE;\r
345         }\r
346         else\r
347         {\r
348                 swFilePath = app::PDFPathToSysPath(swFilePath);\r
349         }\r
350     \r
351         m_pDocument->SetFocusAnnot(NULL);\r
352    \r
353     CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
354         ASSERT(pInterForm != NULL);\r
355 \r
356         CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
357         ASSERT(pPDFForm != NULL);\r
358 \r
359         CFX_PtrArray aFields;\r
360 \r
361         if (bWhole)\r
362         {\r
363                 for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++)\r
364                 {\r
365                         aFields.Add(pPDFForm->GetField(j));\r
366                 }\r
367         }\r
368         else\r
369         {\r
370                 for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++)\r
371                 {\r
372                         CJS_Value valName(isolate);\r
373                         arrayFileds.GetElement(i,valName);\r
374                         CFX_WideString swName = valName.operator CFX_WideString();\r
375 \r
376                         for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++)\r
377                         {\r
378                                 aFields.Add(pPDFForm->GetField(j, swName));\r
379                         }\r
380                 }\r
381         }\r
382 \r
383         CFX_PtrArray fields;\r
384 \r
385         for (int i=0,sz=aFields.GetSize(); i<sz; i++)\r
386         {\r
387             CPDF_FormField* pField = (CPDF_FormField*)aFields[i];\r
388                 \r
389                 if (!bAllFields)\r
390                         if (pField->GetValue() == L"")\r
391                                 continue;\r
392 \r
393                 if (bNoPassWord)\r
394                         if (pField->GetFieldFlags() & 0x2000)\r
395                                 continue;\r
396 \r
397         fields.Add((void*)pField);\r
398         }    \r
399 \r
400     return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE);\r
401 }\r
402 \r
403 //exports form fields an XFDF file to the local hard drive\r
404 //comment: need reder supports\r
405 //note:the last parameter can't be test\r
406 //int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL  bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations);\r
407 \r
408 FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS)\r
409 {\r
410         if (IsSafeMode(cc)) return TRUE;\r
411         ASSERT(m_pDocument != NULL);\r
412 \r
413         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
414 \r
415         return TRUE;\r
416 }\r
417 \r
418 //Maps a field object in PDF document to a JavaScript variable\r
419 //comment:\r
420 //note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document\r
421 \r
422 FX_BOOL Document::getField(OBJ_METHOD_PARAMS)\r
423 {\r
424         v8::Isolate* isolate = GetIsolate(cc);\r
425         ASSERT(m_pDocument != NULL);\r
426 \r
427         if (params.size() < 1) return FALSE;\r
428 \r
429         CFX_WideString wideName = params[0].operator CFX_WideString();\r
430 \r
431     CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();\r
432         ASSERT(pInterForm != NULL);\r
433 \r
434         CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
435         ASSERT(pPDFForm != NULL);\r
436 \r
437         if (pPDFForm->CountFields(wideName) <= 0) \r
438         {\r
439                 vRet.SetNull();\r
440                 return TRUE;\r
441         }\r
442 \r
443         CJS_Context* pContext = (CJS_Context*)cc;\r
444         ASSERT(pContext != NULL);\r
445         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
446         ASSERT(pRuntime != NULL);\r
447 \r
448         JSFXObject  pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));\r
449 \r
450         CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);\r
451         ASSERT(pJSField != NULL);\r
452 \r
453         Field * pField = (Field *)pJSField->GetEmbedObject(); \r
454         ASSERT(pField != NULL);\r
455 \r
456         pField->AttachField(this, wideName);\r
457         vRet = pJSField;\r
458 \r
459         return TRUE;\r
460 }\r
461 \r
462 //Gets the name of the nth field in the document \r
463 //comment:\r
464 //note: the parameter nIndex, if it is not available\r
465 \r
466 FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS)\r
467 {\r
468         ASSERT(m_pDocument != NULL);\r
469 \r
470         int nIndex = params.size() > 0 ? (int)params[0] : -1;\r
471         if (nIndex == -1) return FALSE;\r
472 \r
473         CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();\r
474         ASSERT(pInterForm != NULL);\r
475 \r
476         CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
477         ASSERT(pPDFForm != NULL);\r
478 \r
479         CPDF_FormField* pField = pPDFForm->GetField(nIndex);\r
480         if (!pField)\r
481                 return FALSE;\r
482 \r
483         vRet = pField->GetFullName();\r
484         return TRUE;    \r
485 }\r
486 \r
487 //imports the specified fdf file.\r
488 //comments: need reader suppport\r
489 //note:once the cpath is illigl  then a file dialog box pops up in order to ask user to chooose the file\r
490 //int CPDFSDK_Document::importAnFDF(String cPath);\r
491 \r
492 FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS)\r
493 {\r
494         if (IsSafeMode(cc)) return TRUE;\r
495         ASSERT(m_pDocument != NULL);\r
496 \r
497         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
498                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
499                 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
500 \r
501 \r
502         CFX_WideString swPath;\r
503         \r
504         if (params.size() > 0)\r
505                 swPath = params[0];\r
506     \r
507         if (swPath.IsEmpty())\r
508         {\r
509                 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
510                 swPath = pEnv->JS_fieldBrowse();\r
511                 if(swPath.IsEmpty())\r
512                         return TRUE;\r
513         }\r
514         else\r
515         {\r
516                 swPath = app::PDFPathToSysPath(swPath);\r
517         }\r
518 \r
519         m_pDocument->SetFocusAnnot(NULL);\r
520 \r
521         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
522         ASSERT(pInterForm != NULL);\r
523 \r
524         if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE))\r
525                 return FALSE;\r
526 \r
527         m_pDocument->SetChangeMark();\r
528 //      CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
529 //      ASSERT(pEnv != NULL);\r
530 //      IUndo* pUndo = IUndo::GetUndo(pEnv);\r
531 //      ASSERT(pUndo != NULL);\r
532 //      pUndo->Reset(m_pDocument);\r
533 \r
534         return TRUE;\r
535 }\r
536 \r
537 //imports and specified XFDF file containing XML form data\r
538 //comment: need reader supports\r
539 //note: same as up\r
540 //int CPDFSDK_Document::importAnFDF(String cPath)\r
541 \r
542 FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS)\r
543 {\r
544         if (IsSafeMode(cc)) return TRUE;\r
545         ASSERT(m_pDocument != NULL);\r
546 \r
547         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
548                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
549                 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
550 \r
551         return TRUE;\r
552 }\r
553 \r
554 //imports and specified text file \r
555 //commnet: need reader supports\r
556 //note: same as up,when nRow is not rational,adobe is dumb for it.\r
557 //int CPDFSDK_Document::importTextData(String cPath,int nRow);\r
558 \r
559 FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS)\r
560 {\r
561         if (IsSafeMode(cc)) return TRUE;\r
562         ASSERT(m_pDocument != NULL);\r
563 \r
564         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
565                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
566                 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
567 \r
568         return TRUE;\r
569 }\r
570 \r
571 //exports the form data and mails the resulting fdf file as an attachment to all recipients.\r
572 //comment: need reader supports\r
573 //note:\r
574 //int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);\r
575 \r
576 FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)\r
577 {\r
578         ASSERT(m_pDocument != NULL);\r
579 \r
580         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
581 \r
582         int iLength = params.size();\r
583 \r
584         FX_BOOL bUI = iLength > 0 ? (FX_BOOL)params[0] : TRUE;\r
585         CFX_WideString cTo = iLength > 1 ? (FX_LPCWSTR)params[1].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
586         CFX_WideString cCc = iLength > 2 ? (FX_LPCWSTR)params[2].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
587         CFX_WideString cBcc = iLength > 3 ? (FX_LPCWSTR)params[3].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
588         CFX_WideString cSubject = iLength > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
589         CFX_WideString cMsg = iLength > 5 ? (FX_LPCWSTR)params[5].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
590 \r
591         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
592         ASSERT(pInterForm != NULL);\r
593 \r
594         CFX_ByteTextBuf textBuf;\r
595         if (!pInterForm->ExportFormToFDFTextBuf(textBuf))\r
596                 return FALSE;\r
597 \r
598         CJS_Context* pContext = (CJS_Context*)cc;\r
599         ASSERT(pContext != NULL);\r
600         CPDFDoc_Environment* pEnv = pContext->GetReaderApp();\r
601         ASSERT(pEnv != NULL);\r
602         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
603         ASSERT(pRuntime != NULL);\r
604 \r
605         pRuntime->BeginBlock();\r
606     pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);\r
607         pRuntime->EndBlock();\r
608         return TRUE;\r
609 }\r
610 \r
611 FX_BOOL Document::print(OBJ_METHOD_PARAMS)\r
612 {\r
613         CJS_Context* pContext = (CJS_Context*)cc;\r
614         ASSERT(pContext != NULL);\r
615         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
616         ASSERT(pRuntime != NULL);\r
617 \r
618         FX_BOOL bUI = TRUE;\r
619         int nStart = 0;\r
620         int nEnd = 0;\r
621         FX_BOOL bSilent = FALSE;\r
622         FX_BOOL bShrinkToFit = FALSE;\r
623         FX_BOOL bPrintAsImage = FALSE;\r
624         FX_BOOL bReverse = FALSE;\r
625         FX_BOOL bAnnotations = FALSE;\r
626 \r
627         int nlength = params.size();\r
628         if(nlength ==9)\r
629         {\r
630                 if (params[8].GetType() == VT_fxobject)\r
631                 {\r
632                         JSFXObject pObj = (JSFXObject)params[8];\r
633                         {\r
634                                 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))\r
635                                 {\r
636                                         if (CJS_Object* pJSObj = (CJS_Object*)params[8])\r
637                                         {\r
638                                                         if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())\r
639                                                         {\r
640                                                                 bUI = pprintparamsObj->bUI;\r
641                                                                 nStart = pprintparamsObj->nStart;\r
642                                                                 nEnd = pprintparamsObj->nEnd;\r
643                                                                 bSilent = pprintparamsObj->bSilent;\r
644                                                                 bShrinkToFit = pprintparamsObj->bShrinkToFit;\r
645                                                                 bPrintAsImage = pprintparamsObj->bPrintAsImage;\r
646                                                                 bReverse = pprintparamsObj->bReverse;\r
647                                                                 bAnnotations = pprintparamsObj->bAnnotations;\r
648                                                         }\r
649                                         }\r
650                                 }\r
651                         }       \r
652                 }\r
653         }\r
654         else\r
655         {\r
656                 if(nlength >= 1)\r
657                          bUI = params[0];\r
658                 if(nlength >= 2)\r
659                          nStart = (int)params[1];\r
660                 if(nlength >= 3)\r
661                     nEnd = (int)params[2];\r
662                 if(nlength >= 4)\r
663                         bSilent = params[3];\r
664                 if(nlength >= 5)\r
665                     bShrinkToFit = params[4];\r
666                 if(nlength >= 6)\r
667                         bPrintAsImage = params[5];\r
668                 if(nlength >= 7)\r
669                         bReverse = params[6];\r
670                 if(nlength >= 8)\r
671                         bAnnotations = params[7];\r
672         }\r
673 \r
674         ASSERT(m_pDocument != NULL);\r
675  \r
676         if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())\r
677         {\r
678                 pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);\r
679                 return TRUE;\r
680         }\r
681         return FALSE;\r
682 }\r
683 \r
684 //removes the specified field from the document.\r
685 //comment:\r
686 //note: if the filed name is not retional, adobe is dumb for it.\r
687 \r
688 FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)\r
689 {\r
690         ASSERT(m_pDocument != NULL);\r
691 \r
692         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
693                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;\r
694 \r
695         if (params.size() < 1)\r
696                 return TRUE;\r
697 \r
698         CFX_WideString sFieldName = params[0].operator CFX_WideString();\r
699 \r
700         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
701         ASSERT(pInterForm != NULL);\r
702 \r
703         CFX_PtrArray widgets;\r
704         pInterForm->GetWidgets(sFieldName, widgets);\r
705 \r
706         int nSize = widgets.GetSize();\r
707 \r
708         if (nSize > 0)\r
709         {\r
710                 for (int i=0; i<nSize; i++)\r
711                 {\r
712                         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];\r
713                         ASSERT(pWidget != NULL);\r
714 \r
715                         CPDF_Rect rcAnnot = pWidget->GetRect();\r
716                         rcAnnot.left -= 1;\r
717                         rcAnnot.bottom -= 1;\r
718                         rcAnnot.right += 1;\r
719                         rcAnnot.top += 1;\r
720 \r
721                         CFX_RectArray aRefresh;\r
722                         aRefresh.Add(rcAnnot);\r
723 \r
724                         CPDF_Page* pPage = pWidget->GetPDFPage();\r
725                         ASSERT(pPage != NULL);\r
726                         \r
727                         CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);\r
728                         pPageView->DeleteAnnot(pWidget);\r
729 \r
730                         pPageView->UpdateRects(aRefresh);\r
731                 }\r
732                 m_pDocument->SetChangeMark();\r
733         }\r
734 \r
735         return TRUE;\r
736 }\r
737 \r
738 //reset filed values within a document.\r
739 //comment:\r
740 //note: if the fields names r not rational, aodbe is dumb for it.\r
741 \r
742 FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS)\r
743 {\r
744         ASSERT(m_pDocument != NULL);\r
745 \r
746         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
747                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
748                 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
749 \r
750         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
751         ASSERT(pInterForm != NULL);\r
752 \r
753         CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
754         ASSERT(pPDFForm != NULL);\r
755 \r
756         v8::Isolate* isolate = GetIsolate(cc);\r
757         CJS_Array aName(isolate);\r
758 \r
759         if (params.size() > 0)\r
760         {\r
761                 switch (params[0].GetType())\r
762                 {\r
763                 default:\r
764                         aName.Attach(params[0]);\r
765                         break;\r
766                 case VT_string:\r
767                         aName.SetElement(0,params[0]);\r
768                         break;\r
769                 }\r
770 \r
771                 CFX_PtrArray aFields;\r
772 \r
773                 for (int i=0,isz=aName.GetLength(); i<isz; i++)\r
774                 {\r
775                         CJS_Value valElement(isolate);\r
776                         aName.GetElement(i,valElement);\r
777                         CFX_WideString swVal = valElement.operator CFX_WideString();    \r
778                         \r
779                         for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)\r
780                         {\r
781                                 aFields.Add((void*)pPDFForm->GetField(j,swVal));\r
782                         }               \r
783                 }\r
784 \r
785                 if (aFields.GetSize() > 0)\r
786                 {\r
787                         pPDFForm->ResetForm(aFields, TRUE, TRUE);\r
788                         m_pDocument->SetChangeMark();\r
789 \r
790                 }\r
791         }\r
792         else\r
793         {\r
794                 pPDFForm->ResetForm(TRUE);\r
795                 m_pDocument->SetChangeMark();\r
796 \r
797         }\r
798 \r
799         return TRUE;\r
800 }\r
801 \r
802 \r
803 FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS)\r
804 {\r
805 \r
806         if (IsSafeMode(cc)) return TRUE;\r
807 \r
808         ASSERT(m_pDocument != NULL);\r
809 \r
810 //      m_pDocument->DoSaveAs();\r
811 \r
812         return TRUE;\r
813 }\r
814 \r
815 \r
816 FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS)\r
817 {\r
818         ASSERT(m_pDocument != NULL);\r
819 \r
820 //      if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
821 \r
822         int nSize = params.size();\r
823         if (nSize < 1) return FALSE;\r
824 \r
825         CFX_WideString strURL;\r
826         FX_BOOL bFDF = TRUE;\r
827         FX_BOOL bEmpty = FALSE;\r
828         v8::Isolate* isolate = GetIsolate(cc);\r
829         CJS_Array aFields(isolate);\r
830 \r
831         CJS_Value v = params[0];\r
832         if (v.GetType() == VT_string)\r
833         {\r
834                 strURL = params[0].operator CFX_WideString();\r
835                 if (nSize > 1)\r
836                         bFDF = params[1];\r
837                 if (nSize > 2)\r
838                         bEmpty = params[2];\r
839                 if (nSize > 3)\r
840                         aFields.Attach(params[3]);\r
841         }\r
842         else if (v.GetType() == VT_object)\r
843         {\r
844                 JSObject pObj = (JSObject)params[0];\r
845                 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cURL");\r
846                 if (!pValue.IsEmpty())\r
847                         strURL = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
848                 pValue = JS_GetObjectElement(isolate,pObj, L"bFDF");\r
849                         bFDF = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));\r
850                 pValue = JS_GetObjectElement(isolate,pObj, L"bEmpty");\r
851                         bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));\r
852                 pValue = JS_GetObjectElement(isolate,pObj,L"aFields");\r
853                         aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)));\r
854         }               \r
855 \r
856         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
857         ASSERT(pInterForm != NULL);\r
858         CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();\r
859         ASSERT(pPDFInterForm != NULL);\r
860 \r
861         FX_BOOL bAll = (aFields.GetLength() == 0);\r
862 \r
863         if (bAll && bEmpty)\r
864         {\r
865                 CJS_Context* pContext = (CJS_Context*)cc;\r
866                 ASSERT(pContext != NULL);\r
867                 CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
868                 ASSERT(pRuntime != NULL);\r
869 \r
870                 \r
871                 if (pPDFInterForm->CheckRequiredFields())\r
872                 {\r
873                         pRuntime->BeginBlock();\r
874                         pInterForm->SubmitForm(strURL, FALSE);\r
875                         pRuntime->EndBlock();\r
876                 }\r
877 \r
878                 return TRUE;\r
879         }\r
880         else\r
881         {       \r
882                 CFX_PtrArray fieldObjects;\r
883 \r
884                 for (int i=0,sz=aFields.GetLength(); i<sz; i++)\r
885                 {\r
886                         CJS_Value valName(isolate);\r
887                         aFields.GetElement(i, valName);\r
888                         CFX_WideString sName = valName.operator CFX_WideString();\r
889 \r
890                         CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
891                         ASSERT(pPDFForm != NULL);\r
892 \r
893                         for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j++)\r
894                         {\r
895                                 CPDF_FormField* pField = pPDFForm->GetField(j, sName);\r
896                                 if (!bEmpty && pField->GetValue().IsEmpty())\r
897                                         continue;\r
898 \r
899                                 fieldObjects.Add(pField);\r
900                         }\r
901                 }\r
902 \r
903                 CJS_Context* pContext = (CJS_Context*)cc;\r
904                 ASSERT(pContext != NULL);\r
905                 CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
906                 ASSERT(pRuntime != NULL);\r
907 \r
908                 \r
909                 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))\r
910                 {\r
911                         pRuntime->BeginBlock();\r
912                         pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);\r
913                         pRuntime->EndBlock();\r
914                 }\r
915 \r
916                 return TRUE;\r
917         }\r
918 \r
919 }\r
920 \r
921 //////////////////////////////////////////////////////////////////////////////////////////////\r
922 \r
923 void Document::AttachDoc(CPDFSDK_Document *pDoc)\r
924 {\r
925         m_pDocument = pDoc;\r
926 }\r
927 \r
928 CPDFSDK_Document * Document::GetReaderDoc()\r
929 {\r
930         return m_pDocument;\r
931 }\r
932 \r
933 FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)\r
934 {\r
935         return FALSE;\r
936 }\r
937 \r
938 FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)\r
939 {\r
940         return FALSE;\r
941 }\r
942 \r
943 FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS)\r
944 {       \r
945         return TRUE;\r
946 }\r
947 \r
948 FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS)\r
949 {\r
950         ASSERT(m_pDocument != NULL);\r
951 \r
952         FX_BOOL bUI = TRUE;\r
953         CFX_WideString cTo = L"";\r
954         CFX_WideString cCc = L"";\r
955         CFX_WideString cBcc = L"";\r
956         CFX_WideString cSubject = L"";\r
957         CFX_WideString cMsg = L"";\r
958         \r
959 \r
960         bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE;\r
961         cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L"";\r
962         cCc = params.size()>=3?(const wchar_t*)params[2].operator CFX_WideString():L"";\r
963         cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L"";\r
964         cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L"";\r
965         cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L"";\r
966         \r
967         v8::Isolate* isolate = GetIsolate(cc);\r
968 \r
969         if(params.size()>=1 && params[0].GetType() == VT_object)\r
970         {\r
971                 JSObject  pObj = (JSObject )params[0];\r
972 \r
973                 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");\r
974                         bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
975 \r
976                 pValue = JS_GetObjectElement(isolate,pObj, L"cTo");\r
977                         cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
978 \r
979                 pValue = JS_GetObjectElement(isolate,pObj, L"cCc");\r
980                         cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
981 \r
982                 pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");\r
983                         cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
984 \r
985                 pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");\r
986                         cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
987 \r
988                 pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");\r
989                         cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
990         \r
991         }\r
992 \r
993         CJS_Context* pContext = (CJS_Context*)cc;\r
994         ASSERT(pContext != NULL);\r
995         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
996         ASSERT(pRuntime != NULL);\r
997 \r
998         pRuntime->BeginBlock();\r
999         CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();\r
1000         pEnv->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);\r
1001         pRuntime->EndBlock();\r
1002 \r
1003         return TRUE;\r
1004 }\r
1005 \r
1006 FX_BOOL Document::author(OBJ_PROP_PARAMS)\r
1007 {\r
1008         ASSERT(m_pDocument != NULL);\r
1009 \r
1010         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1011         if (!pDictionary)return FALSE;\r
1012 \r
1013         if (vp.IsGetting())\r
1014         {\r
1015                 vp << pDictionary->GetUnicodeText("Author");\r
1016                 return TRUE;\r
1017         }\r
1018         else\r
1019         {\r
1020                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1021 \r
1022                 CFX_WideString csAuthor;\r
1023                 vp >> csAuthor;\r
1024                 pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));\r
1025                 m_pDocument->SetChangeMark();\r
1026                 return TRUE;\r
1027         }\r
1028 }\r
1029 \r
1030 FX_BOOL Document::info(OBJ_PROP_PARAMS)\r
1031 {\r
1032         ASSERT(m_pDocument != NULL);\r
1033 \r
1034         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1035         if (!pDictionary)return FALSE;\r
1036 \r
1037         CFX_WideString cwAuthor                 = pDictionary->GetUnicodeText("Author");\r
1038         CFX_WideString cwTitle                  = pDictionary->GetUnicodeText("Title");\r
1039         CFX_WideString cwSubject                = pDictionary->GetUnicodeText("Subject");\r
1040         CFX_WideString cwKeywords               = pDictionary->GetUnicodeText("Keywords");\r
1041         CFX_WideString cwCreator                = pDictionary->GetUnicodeText("Creator");\r
1042         CFX_WideString cwProducer               = pDictionary->GetUnicodeText("Producer");\r
1043         CFX_WideString cwCreationDate   = pDictionary->GetUnicodeText("CreationDate");\r
1044         CFX_WideString cwModDate                = pDictionary->GetUnicodeText("ModDate");\r
1045         CFX_WideString cwTrapped                = pDictionary->GetUnicodeText("Trapped");\r
1046 \r
1047         v8::Isolate* isolate = GetIsolate(cc);\r
1048         if (!vp.IsSetting())\r
1049         {\r
1050                 CJS_Context* pContext = (CJS_Context *)cc;\r
1051                 CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
1052 \r
1053                 JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);\r
1054 \r
1055                 JS_PutObjectString(isolate,pObj, L"Author", cwAuthor);\r
1056                 JS_PutObjectString(isolate,pObj, L"Title", cwTitle);\r
1057                 JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);\r
1058                 JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);\r
1059                 JS_PutObjectString(isolate,pObj, L"Creator", cwCreator);\r
1060                 JS_PutObjectString(isolate,pObj, L"Producer", cwProducer);\r
1061                 JS_PutObjectString(isolate,pObj, L"CreationDate", cwCreationDate);\r
1062                 JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate);\r
1063                 JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped);\r
1064 \r
1065 // It's to be compatible to non-standard info dictionary.       \r
1066                 FX_POSITION pos = pDictionary->GetStartPos();\r
1067                 while(pos)\r
1068                 {\r
1069                         CFX_ByteString bsKey;\r
1070                         CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);\r
1071                         CFX_WideString wsKey  = CFX_WideString::FromUTF8(bsKey);\r
1072                         if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )\r
1073                                         JS_PutObjectString(isolate,pObj, wsKey, pValueObj->GetUnicodeText());\r
1074                         if(pValueObj->GetType()==PDFOBJ_NUMBER)\r
1075                                 JS_PutObjectNumber(isolate,pObj, wsKey, (float)pValueObj->GetNumber());\r
1076                         if(pValueObj->GetType()==PDFOBJ_BOOLEAN)\r
1077                                 JS_PutObjectBoolean(isolate,pObj, wsKey, (bool)pValueObj->GetInteger());\r
1078                 }\r
1079 \r
1080                 vp << pObj;\r
1081                 return TRUE;\r
1082         }\r
1083         else\r
1084         {\r
1085                 return TRUE;\r
1086         }\r
1087 }\r
1088 \r
1089 FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)\r
1090 {\r
1091         ASSERT(m_pDocument != NULL);\r
1092 \r
1093         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1094         if (!pDictionary)return FALSE;\r
1095 \r
1096         if (vp.IsGetting())\r
1097         {\r
1098                 vp << pDictionary->GetUnicodeText("CreationDate");\r
1099                 return TRUE;\r
1100         }\r
1101         else\r
1102         {\r
1103                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1104 \r
1105                 CFX_WideString csCreationDate;\r
1106                 vp >> csCreationDate;\r
1107                 pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));\r
1108                 m_pDocument->SetChangeMark();\r
1109 \r
1110                 return TRUE;\r
1111         }\r
1112 }\r
1113 \r
1114 FX_BOOL Document::creator(OBJ_PROP_PARAMS)\r
1115 {\r
1116         ASSERT(m_pDocument != NULL);\r
1117 \r
1118         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1119         if (!pDictionary)return FALSE;\r
1120 \r
1121         if (vp.IsGetting())\r
1122         {\r
1123                 vp << pDictionary->GetUnicodeText("Creator");\r
1124                 return TRUE;\r
1125         }\r
1126         else\r
1127         {\r
1128                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1129 \r
1130                 CFX_WideString csCreator;\r
1131                 vp >> csCreator;\r
1132                 pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));\r
1133                 m_pDocument->SetChangeMark();\r
1134                 return TRUE;\r
1135         }\r
1136 }\r
1137 \r
1138 FX_BOOL Document::delay(OBJ_PROP_PARAMS)\r
1139 {\r
1140         if (vp.IsGetting())\r
1141         {\r
1142                 vp << m_bDelay;\r
1143                 return TRUE;\r
1144         }\r
1145         else\r
1146         {\r
1147                 ASSERT(m_pDocument != NULL);\r
1148 \r
1149                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1150 \r
1151                 bool b;\r
1152                 vp >> b;\r
1153 \r
1154                 m_bDelay = b;\r
1155 \r
1156                 if (m_bDelay) \r
1157                 {\r
1158                         for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)\r
1159                                 delete m_DelayData.GetAt(i);\r
1160 \r
1161                         m_DelayData.RemoveAll();\r
1162                 }\r
1163                 else\r
1164                 {\r
1165                         for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)\r
1166                         {\r
1167                                 if (CJS_DelayData* pData = m_DelayData.GetAt(i))\r
1168                                 {\r
1169                                         Field::DoDelay(m_pDocument, pData);\r
1170                                         delete m_DelayData.GetAt(i);\r
1171                                 }\r
1172                         }\r
1173                         m_DelayData.RemoveAll();\r
1174                 }\r
1175 \r
1176                 return TRUE;\r
1177         }\r
1178 }\r
1179 \r
1180 FX_BOOL Document::keywords(OBJ_PROP_PARAMS)\r
1181 {\r
1182         ASSERT(m_pDocument != NULL);\r
1183 \r
1184         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1185         if (!pDictionary)return FALSE;\r
1186 \r
1187         if (vp.IsGetting())\r
1188         {\r
1189                 vp << pDictionary->GetUnicodeText("Keywords");\r
1190                 return TRUE;\r
1191         }\r
1192         else\r
1193         {\r
1194                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1195 \r
1196                 CFX_WideString csKeywords;\r
1197                 vp >> csKeywords;\r
1198                 pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));\r
1199                 m_pDocument->SetChangeMark();\r
1200                 return TRUE;\r
1201         }\r
1202 }\r
1203 \r
1204 FX_BOOL Document::modDate(OBJ_PROP_PARAMS)\r
1205 {\r
1206         ASSERT(m_pDocument != NULL);\r
1207 \r
1208         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1209         if (!pDictionary)return FALSE;\r
1210 \r
1211         if (vp.IsGetting())\r
1212         {\r
1213                 vp << pDictionary->GetUnicodeText("ModDate");\r
1214                 return TRUE;\r
1215         }\r
1216         else\r
1217         {\r
1218                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1219 \r
1220                 CFX_WideString csmodDate;\r
1221                 vp >> csmodDate;\r
1222                 pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));\r
1223                 m_pDocument->SetChangeMark();\r
1224                 return TRUE;\r
1225         }\r
1226 }\r
1227 \r
1228 FX_BOOL Document::producer(OBJ_PROP_PARAMS)\r
1229 {\r
1230         ASSERT(m_pDocument != NULL);\r
1231 \r
1232         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1233         if (!pDictionary)return FALSE;\r
1234 \r
1235         if (vp.IsGetting())\r
1236         {\r
1237                 vp << pDictionary->GetUnicodeText("Producer");\r
1238                 return TRUE;\r
1239         }\r
1240         else\r
1241         {\r
1242                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1243 \r
1244                 CFX_WideString csproducer;\r
1245                 vp >> csproducer;\r
1246                 pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));\r
1247                 m_pDocument->SetChangeMark();\r
1248                 return TRUE;\r
1249         }\r
1250 }\r
1251 \r
1252 FX_BOOL Document::subject(OBJ_PROP_PARAMS)\r
1253 {\r
1254         ASSERT(m_pDocument != NULL);\r
1255 \r
1256         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1257         if (!pDictionary)return FALSE;\r
1258 \r
1259         if (vp.IsGetting())\r
1260         {\r
1261                 vp << pDictionary->GetUnicodeText("Subject");\r
1262                 return TRUE;\r
1263         }\r
1264         else\r
1265         {\r
1266                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1267 \r
1268                 CFX_WideString cssubject;\r
1269                 vp >> cssubject;\r
1270                 pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));\r
1271                 m_pDocument->SetChangeMark();\r
1272                 return TRUE;\r
1273         }\r
1274 }\r
1275 \r
1276 FX_BOOL Document::title(OBJ_PROP_PARAMS)\r
1277 {\r
1278         ASSERT(m_pDocument != NULL);\r
1279 \r
1280         if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)\r
1281                 return FALSE;\r
1282 \r
1283         CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
1284         if (!pDictionary)return FALSE;\r
1285 \r
1286         if (vp.IsGetting())\r
1287         {\r
1288                 vp << pDictionary->GetUnicodeText("Title");\r
1289                 return TRUE;\r
1290         }\r
1291         else\r
1292         {\r
1293                 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
1294 \r
1295                 CFX_WideString cstitle;\r
1296                 vp >> cstitle;\r
1297                 pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));\r
1298                 m_pDocument->SetChangeMark();\r
1299                 return TRUE;\r
1300         }\r
1301 }\r
1302 \r
1303 FX_BOOL Document::numPages(OBJ_PROP_PARAMS)\r
1304 {\r
1305         if (vp.IsGetting())\r
1306         {\r
1307                 ASSERT(m_pDocument != NULL);\r
1308                 vp << m_pDocument->GetPageCount();\r
1309                 return TRUE;\r
1310         }\r
1311         else\r
1312         {\r
1313                 return FALSE;\r
1314         }\r
1315 }\r
1316 \r
1317 FX_BOOL Document::external(OBJ_PROP_PARAMS)\r
1318 {\r
1319         //In Chrome case,should always return true.\r
1320         vp << TRUE;\r
1321         return TRUE;\r
1322 }\r
1323 \r
1324 FX_BOOL Document::filesize(OBJ_PROP_PARAMS)\r
1325 {\r
1326         if (!vp.IsGetting())return FALSE;\r
1327 \r
1328         ASSERT(m_pDocument != NULL);\r
1329 \r
1330 //      CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);\r
1331 //      vp << (double)file.GetLength();\r
1332 //      file.Close();\r
1333 \r
1334         if ( m_pDocument->GetPath().IsEmpty() == FALSE)\r
1335         {\r
1336                 CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() );\r
1337                 FILE * pFile = NULL;\r
1338                 pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" );\r
1339                 if ( pFile )\r
1340                 {\r
1341                         fseek( pFile, 0, SEEK_END );\r
1342                         long lSize = ftell( pFile );\r
1343                         fclose( pFile );\r
1344                         pFile = NULL;\r
1345 \r
1346                         vp << (FX_INT32)(lSize);\r
1347                         return TRUE;\r
1348                 }\r
1349         }\r
1350 \r
1351         vp << 0;\r
1352         return TRUE;\r
1353 }\r
1354 \r
1355 FX_BOOL Document::mouseX(OBJ_PROP_PARAMS)\r
1356 {\r
1357         return TRUE;    \r
1358 }\r
1359 \r
1360 FX_BOOL Document::mouseY(OBJ_PROP_PARAMS)\r
1361 {\r
1362         return TRUE;\r
1363 }\r
1364 \r
1365 FX_BOOL Document::baseURL(OBJ_PROP_PARAMS)\r
1366 {\r
1367         if (vp.IsGetting())\r
1368         {\r
1369                 vp << m_cwBaseURL;\r
1370                 return TRUE;\r
1371         }\r
1372         else\r
1373         {\r
1374                 vp >> m_cwBaseURL;\r
1375                 return TRUE;\r
1376         }\r
1377 }\r
1378 \r
1379 FX_BOOL Document::calculate(OBJ_PROP_PARAMS)\r
1380 {\r
1381         ASSERT(m_pDocument != NULL);\r
1382 \r
1383         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
1384         ASSERT(pInterForm != NULL);\r
1385 \r
1386         if (vp.IsGetting())\r
1387         {\r
1388                 if (pInterForm->IsCalculateEnabled())\r
1389                         vp << true;\r
1390                 else\r
1391                         vp << false;\r
1392         }\r
1393         else\r
1394         {\r
1395                 bool bCalculate;\r
1396                 vp >> bCalculate;\r
1397 \r
1398                 pInterForm->EnableCalculate(bCalculate);\r
1399         }\r
1400 \r
1401         return TRUE;\r
1402 }\r
1403 \r
1404 FX_BOOL Document::documentFileName(OBJ_PROP_PARAMS)\r
1405 {\r
1406         if (!vp.IsGetting())\r
1407                 return FALSE;\r
1408 \r
1409         CFX_WideString wsFilePath = m_pDocument->GetPath();\r
1410 \r
1411         FX_INT32 i = wsFilePath.GetLength() - 1;\r
1412         for ( ; i >= 0; i-- )\r
1413         {\r
1414                 if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )\r
1415                         break;\r
1416         }\r
1417         if ( i >= 0 && i < wsFilePath.GetLength() - 1 )\r
1418         {\r
1419                 vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );\r
1420         }else{\r
1421                 vp << L"";\r
1422         }\r
1423         return TRUE;\r
1424 }\r
1425 \r
1426 CFX_WideString Document::ReversalStr(CFX_WideString cbFrom)\r
1427 {\r
1428         wchar_t* pFrom = NULL;\r
1429         int iLenth = cbFrom.GetLength();\r
1430         wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));\r
1431         memset(pResult, 0, (iLenth+1));\r
1432         pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);\r
1433 \r
1434         for (int i = 0; i < iLenth; i++)\r
1435         {\r
1436                 pResult[i] = *(pFrom + iLenth - i - 1);\r
1437         }\r
1438 \r
1439         cbFrom.ReleaseBuffer();\r
1440         CFX_WideString cbRet = CFX_WideString(pResult);\r
1441         free(pResult);\r
1442         pResult = NULL;\r
1443         return cbRet;\r
1444 }\r
1445 \r
1446 CFX_WideString Document::CutString(CFX_WideString cbFrom)\r
1447 {\r
1448         wchar_t* pFrom = NULL;\r
1449         int iLenth = cbFrom.GetLength();\r
1450         wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));\r
1451         memset(pResult, 0, (iLenth+1));\r
1452         pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);\r
1453 \r
1454         for (int i = 0; i < iLenth; i++)\r
1455         {\r
1456                 if (pFrom[i] == L'\\' || pFrom[i] == L'/')\r
1457                         break;\r
1458                 pResult[i] = pFrom[i];\r
1459         }\r
1460 \r
1461         cbFrom.ReleaseBuffer();\r
1462         CFX_WideString cbRet = CFX_WideString(pResult);\r
1463         free(pResult);\r
1464         pResult = NULL;\r
1465         return cbRet;\r
1466 }\r
1467 \r
1468 FX_BOOL Document::path(OBJ_PROP_PARAMS)\r
1469 {\r
1470         if (!vp.IsGetting()) return FALSE;\r
1471 \r
1472         vp << app::SysPathToPDFPath(m_pDocument->GetPath());\r
1473 \r
1474         return TRUE;\r
1475 }\r
1476 \r
1477 FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS)\r
1478 {\r
1479         return TRUE;\r
1480 }\r
1481 \r
1482 FX_BOOL Document::layout(OBJ_PROP_PARAMS)\r
1483 {       \r
1484         return TRUE;\r
1485 }\r
1486 \r
1487 FX_BOOL Document::addLink(OBJ_METHOD_PARAMS)\r
1488 {\r
1489         return TRUE;\r
1490 }\r
1491 \r
1492 FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS)\r
1493 {\r
1494         ASSERT(m_pDocument != NULL);\r
1495 \r
1496 \r
1497         \r
1498         \r
1499 \r
1500         return TRUE;\r
1501 }\r
1502 \r
1503 FX_BOOL Document::getPageBox(OBJ_METHOD_PARAMS)\r
1504 {\r
1505         return TRUE;\r
1506 }\r
1507 \r
1508 \r
1509 FX_BOOL Document::getAnnot(OBJ_METHOD_PARAMS)\r
1510 {\r
1511         return TRUE;\r
1512 }\r
1513 \r
1514 FX_BOOL Document::getAnnots(OBJ_METHOD_PARAMS)\r
1515 {\r
1516         vRet.SetNull();\r
1517         return TRUE;\r
1518 }\r
1519 \r
1520 FX_BOOL Document::getAnnot3D(OBJ_METHOD_PARAMS)\r
1521 {\r
1522         vRet.SetNull();\r
1523         return TRUE;\r
1524 }\r
1525 \r
1526 FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS)\r
1527 {\r
1528         vRet = VT_undefined;\r
1529         return TRUE;\r
1530 }\r
1531 \r
1532 FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS)\r
1533 {       \r
1534         return TRUE;\r
1535 }\r
1536 \r
1537 FX_BOOL Document::getLinks(OBJ_METHOD_PARAMS)\r
1538 {\r
1539         return TRUE;\r
1540 }\r
1541 \r
1542 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)\r
1543 {\r
1544         if (rect.left <= LinkRect.left\r
1545           && rect.top <= LinkRect.top\r
1546           && rect.right >= LinkRect.right\r
1547           && rect.bottom >= LinkRect.bottom)\r
1548                 return true;\r
1549         else\r
1550                 return false;\r
1551 }\r
1552 \r
1553 void IconTree::InsertIconElement(IconElement* pNewIcon)\r
1554 {\r
1555         if (!pNewIcon)return;\r
1556 \r
1557         if (m_pHead == NULL && m_pEnd == NULL)\r
1558         {\r
1559                 m_pHead = m_pEnd = pNewIcon;\r
1560                 m_iLength++;\r
1561         }\r
1562         else\r
1563         {\r
1564                 m_pEnd->NextIcon = pNewIcon;\r
1565                 m_pEnd = pNewIcon;\r
1566                 m_iLength++;\r
1567         }\r
1568 }\r
1569 \r
1570 void IconTree::DeleteIconTree()\r
1571 {\r
1572         if (!m_pHead || !m_pEnd)return;\r
1573         \r
1574         IconElement* pTemp = NULL;\r
1575         while(m_pEnd != m_pHead)\r
1576         {\r
1577                 pTemp = m_pHead;\r
1578                 m_pHead = m_pHead->NextIcon;\r
1579                 delete pTemp;\r
1580         }\r
1581 \r
1582         delete m_pEnd;\r
1583         m_pHead = NULL;\r
1584         m_pEnd = NULL;\r
1585 }\r
1586 \r
1587 int IconTree::GetLength()\r
1588 {\r
1589         return m_iLength;\r
1590 }\r
1591 \r
1592 IconElement* IconTree::operator [](int iIndex)\r
1593 {\r
1594         if (iIndex >= 0 && iIndex <= m_iLength)\r
1595         {\r
1596                 IconElement* pTemp = m_pHead;\r
1597                 for (int i = 0; i < iIndex; i++)\r
1598                 {\r
1599                         pTemp = pTemp->NextIcon;\r
1600                 }\r
1601                 return pTemp;\r
1602         }\r
1603         else\r
1604                 return NULL;\r
1605 }\r
1606 \r
1607 void IconTree::DeleteIconElement(CFX_WideString swIconName)\r
1608 {\r
1609         IconElement* pTemp = m_pHead;\r
1610         int iLoopCount = m_iLength; \r
1611         for (int i = 0; i < iLoopCount - 1; i++)\r
1612         {\r
1613                 if (pTemp == m_pEnd)\r
1614                         break;\r
1615         \r
1616                 if (m_pHead->IconName == swIconName)\r
1617                 {\r
1618                         m_pHead = m_pHead->NextIcon;\r
1619                         delete pTemp;\r
1620                         m_iLength--;\r
1621                         pTemp = m_pHead;\r
1622                 }\r
1623                 if (pTemp->NextIcon->IconName == swIconName)\r
1624                 {\r
1625                         if (pTemp->NextIcon == m_pEnd)\r
1626                         {\r
1627                                 m_pEnd = pTemp;\r
1628                                 delete pTemp->NextIcon;\r
1629                                 m_iLength--;\r
1630                                 pTemp->NextIcon = NULL;\r
1631                         }\r
1632                         else\r
1633                         {\r
1634                                 IconElement* pElement = pTemp->NextIcon;\r
1635                                 pTemp->NextIcon = pTemp->NextIcon->NextIcon;\r
1636                                 delete pElement;\r
1637                                 m_iLength--;\r
1638                                 pElement = NULL;\r
1639                         }\r
1640 \r
1641                         continue;\r
1642                 }\r
1643 \r
1644                 pTemp = pTemp->NextIcon;\r
1645         }\r
1646 }\r
1647 \r
1648 FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS)\r
1649 {\r
1650         if (params.size() != 2)return FALSE;\r
1651 \r
1652         CJS_Context* pContext = (CJS_Context*)cc;\r
1653         ASSERT(pContext != NULL);\r
1654         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
1655         ASSERT(pRuntime != NULL);\r
1656 \r
1657         CFX_WideString swIconName = params[0].operator CFX_WideString();\r
1658         \r
1659         JSFXObject pJSIcon = (JSFXObject)params[1];\r
1660         if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE;\r
1661 \r
1662         CJS_EmbedObj* pEmbedObj = ((CJS_Object*)params[1])->GetEmbedObject();\r
1663         if (!pEmbedObj)return FALSE;\r
1664         Icon* pIcon = (Icon*)pEmbedObj;\r
1665 \r
1666         if (!m_pIconTree)\r
1667                 m_pIconTree = new IconTree();\r
1668 \r
1669         IconElement* pNewIcon = new IconElement();\r
1670         pNewIcon->IconName = swIconName;\r
1671         pNewIcon->NextIcon = NULL;\r
1672         pNewIcon->IconStream = pIcon;\r
1673         m_pIconTree->InsertIconElement(pNewIcon);\r
1674         return TRUE;\r
1675 }\r
1676 \r
1677 FX_BOOL Document::icons(OBJ_PROP_PARAMS)\r
1678 {\r
1679         if (vp.IsSetting())\r
1680                 return FALSE;\r
1681 \r
1682         if (!m_pIconTree)\r
1683         {\r
1684                 vp.SetNull();\r
1685                 return TRUE;\r
1686         }\r
1687 \r
1688         CJS_Array Icons(m_isolate);\r
1689         IconElement* pIconElement = NULL;\r
1690         int iIconTreeLength = m_pIconTree->GetLength();\r
1691 \r
1692         CJS_Context* pContext = (CJS_Context *)cc;\r
1693         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
1694 \r
1695         for (int i = 0; i < iIconTreeLength; i++)\r
1696         {\r
1697                 pIconElement = (*m_pIconTree)[i];\r
1698                 \r
1699                 JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));\r
1700                 if (pObj.IsEmpty()) return FALSE;\r
1701                                 \r
1702                 CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);\r
1703                 if (!pJS_Icon) return FALSE;\r
1704 \r
1705                 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();\r
1706                 if (!pIcon)return FALSE;\r
1707 \r
1708                 pIcon->SetStream(pIconElement->IconStream->GetStream());\r
1709                 pIcon->SetIconName(pIconElement->IconName);\r
1710                 Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));\r
1711         }\r
1712 \r
1713         vp << Icons;\r
1714         return TRUE;\r
1715 }\r
1716 \r
1717 FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS)\r
1718 {\r
1719         if (params.size() != 1)return FALSE;\r
1720         if(!m_pIconTree)\r
1721                 return FALSE;\r
1722         CFX_WideString swIconName = params[0].operator CFX_WideString();\r
1723         int iIconCounts = m_pIconTree->GetLength();\r
1724 \r
1725         CJS_Context* pContext = (CJS_Context *)cc;\r
1726         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
1727 \r
1728         for (int i = 0; i < iIconCounts; i++)\r
1729         {\r
1730                 if ((*m_pIconTree)[i]->IconName == swIconName)\r
1731                 {\r
1732                         Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;\r
1733                                 \r
1734                         JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));\r
1735                         if (pObj.IsEmpty()) return FALSE;\r
1736                                         \r
1737                         CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);\r
1738                         if (!pJS_Icon) return FALSE;\r
1739 \r
1740                         Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();\r
1741                         if (!pIcon)return FALSE;\r
1742 \r
1743                         pIcon->SetIconName(swIconName);\r
1744                         pIcon->SetStream(pRetIcon->GetStream());\r
1745                         vRet = pJS_Icon;\r
1746                         return TRUE;\r
1747                 }\r
1748         }\r
1749 \r
1750         return FALSE;\r
1751 }\r
1752 \r
1753 FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS)\r
1754 {\r
1755         if (params.size() != 1)return FALSE;\r
1756         if(!m_pIconTree)\r
1757                 return FALSE;\r
1758         CFX_WideString swIconName = params[0].operator CFX_WideString();\r
1759 #ifndef FOXIT_CHROME_BUILD\r
1760         m_pIconTree->DeleteIconElement(swIconName);\r
1761 #endif\r
1762         return TRUE;\r
1763 }\r
1764 \r
1765 FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS)\r
1766 {\r
1767         if (IsSafeMode(cc)) return TRUE;\r
1768         ASSERT(m_pDocument != NULL);\r
1769 \r
1770         CFX_WideString swName = L"";\r
1771         CFX_ByteString sbName = "";\r
1772         CFX_WideString swValue = L"";\r
1773         CFX_WideString swMIMEType = L"";\r
1774         CFX_WideString swCryptFilter = L"";\r
1775         CFX_ByteString sbFileValue = "";\r
1776         \r
1777         int iParamSize = params.size();\r
1778         for (int i = 0; i < iParamSize; i++)\r
1779         {\r
1780                 if (i == 0)\r
1781                         swName = params[0];\r
1782                 if (i == 1)\r
1783                         swValue = params[1];\r
1784                 if (i == 2)\r
1785                         swMIMEType = params[2];\r
1786                 if (i == 3)\r
1787                         swCryptFilter = params[4];\r
1788         }\r
1789 \r
1790         FILE* pFile = NULL;\r
1791 \r
1792         //CFileStatus fileStatus;\r
1793         const int BUFSIZE = 17;\r
1794         FX_BYTE buf[BUFSIZE];\r
1795         FX_BYTE *pBuffer = NULL;\r
1796         char* pBuf = NULL;\r
1797         int nFileSize = 0;\r
1798         sbFileValue = CFX_ByteString::FromUnicode(swValue);\r
1799         sbName = CFX_ByteString::FromUnicode(swName);\r
1800         int iBufLength = sbFileValue.GetLength();\r
1801         pBuf = (char*)malloc(sizeof(char) * iBufLength);\r
1802         pBuf = sbFileValue.GetBuffer(iBufLength);\r
1803 \r
1804         if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) )\r
1805         {\r
1806                 return FALSE;\r
1807         }\r
1808 \r
1809         fwrite( pBuf, sizeof(char), iBufLength, pFile );\r
1810         fclose( pFile );\r
1811         pFile = NULL;\r
1812 \r
1813         pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" );\r
1814         fseek( pFile, 0, SEEK_END );\r
1815         nFileSize = ftell( pFile );\r
1816 \r
1817         pBuffer = new FX_BYTE[nFileSize];\r
1818         fseek( pFile, 0, SEEK_SET );\r
1819         size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile );\r
1820         if(s == 0)\r
1821         {\r
1822                 delete[] pBuffer;\r
1823                 return FALSE;\r
1824         }\r
1825 \r
1826         CRYPT_MD5Generate(pBuffer, nFileSize, buf);\r
1827         buf[BUFSIZE - 1] = 0;\r
1828         CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16);\r
1829         delete[] pBuffer;\r
1830 \r
1831         return TRUE;\r
1832 }\r
1833 \r
1834 FX_BOOL Document::media(OBJ_PROP_PARAMS)\r
1835 {\r
1836         return TRUE;\r
1837 }\r
1838 \r
1839 FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS)\r
1840 {\r
1841         ASSERT(m_pDocument != NULL);\r
1842 \r
1843         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
1844                 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
1845                 m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
1846 \r
1847         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
1848         ASSERT(pInterForm != NULL);\r
1849         pInterForm->OnCalculate();\r
1850         return TRUE;\r
1851 }\r
1852 \r
1853 FX_BOOL Document::Collab(OBJ_PROP_PARAMS)\r
1854 {\r
1855         return TRUE;\r
1856 }\r
1857 \r
1858 FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)\r
1859 {\r
1860         //if (IsSafeMode(cc)) return TRUE;\r
1861 \r
1862         ASSERT(m_pDocument != NULL);\r
1863 \r
1864         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
1865 \r
1866         int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;\r
1867         int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;\r
1868         bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;\r
1869 \r
1870         CPDF_Document* pDocument = m_pDocument->GetDocument();\r
1871         if (!pDocument) return FALSE;\r
1872 \r
1873         if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())\r
1874         {\r
1875                 //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);\r
1876                 return FALSE;\r
1877         }\r
1878 \r
1879         CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);\r
1880         if (!pPageDict) return FALSE;\r
1881 \r
1882         CPDF_Page page;\r
1883         page.Load(pDocument, pPageDict);\r
1884         page.StartParse();\r
1885         page.ParseContent();\r
1886 \r
1887         FX_POSITION pos = page.GetFirstObjectPosition();\r
1888 \r
1889         int nWords = 0;\r
1890 \r
1891         CFX_WideString swRet;\r
1892 \r
1893         while (pos)\r
1894         {\r
1895                 if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))\r
1896                 {\r
1897                         if (pPageObj->m_Type == PDFPAGE_TEXT)\r
1898                         {\r
1899                                 int nObjWords = CountWords((CPDF_TextObject*)pPageObj);\r
1900 \r
1901                                 if (nWords + nObjWords >= nWordNo)\r
1902                                 {\r
1903                                         swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);\r
1904                                         break;\r
1905                                 }\r
1906 \r
1907                                 nWords += nObjWords;\r
1908                         }\r
1909                 }\r
1910         }\r
1911 \r
1912         if (bStrip)\r
1913         {\r
1914                 swRet.TrimLeft();\r
1915                 swRet.TrimRight();\r
1916         }\r
1917 \r
1918         vRet = swRet;\r
1919         return TRUE;\r
1920 }\r
1921 \r
1922 FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS)\r
1923 {\r
1924         //if (IsSafeMode(cc)) return TRUE;\r
1925 \r
1926         ASSERT(m_pDocument != NULL);\r
1927 \r
1928         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
1929 \r
1930         return FALSE;\r
1931 }\r
1932 \r
1933 FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)\r
1934 {\r
1935         ASSERT(m_pDocument != NULL);\r
1936 \r
1937         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
1938 \r
1939         int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;\r
1940 \r
1941         CPDF_Document* pDocument = m_pDocument->GetDocument();\r
1942         ASSERT(pDocument != NULL);\r
1943 \r
1944         if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())\r
1945         {\r
1946                 //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);\r
1947                 return FALSE;\r
1948         }\r
1949 \r
1950         CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);\r
1951         if (!pPageDict) return FALSE;\r
1952 \r
1953         CPDF_Page page;\r
1954         page.Load(pDocument, pPageDict);\r
1955         page.StartParse();\r
1956         page.ParseContent();\r
1957 \r
1958         FX_POSITION pos = page.GetFirstObjectPosition();\r
1959 \r
1960         int nWords = 0;\r
1961 \r
1962         while (pos)\r
1963         {\r
1964                 if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))\r
1965                 {\r
1966                         if (pPageObj->m_Type == PDFPAGE_TEXT)\r
1967                         {\r
1968                                 CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;\r
1969                                 nWords += CountWords(pTextObj);\r
1970                         }\r
1971                 }\r
1972         }\r
1973 \r
1974         vRet = nWords;\r
1975 \r
1976         return TRUE;\r
1977 }\r
1978 \r
1979 FX_BOOL Document::getPrintParams(OBJ_METHOD_PARAMS)\r
1980 {\r
1981         CJS_Context* pContext = (CJS_Context*)cc;\r
1982         ASSERT(pContext != NULL);\r
1983         CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
1984         ASSERT(pRuntime != NULL);\r
1985         JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));\r
1986         //not implemented yet.\r
1987         vRet = pRetObj;\r
1988 \r
1989         return TRUE;\r
1990 }\r
1991 \r
1992 #define ISLATINWORD(u)  (u != 0x20 && u <= 0x28FF)\r
1993 \r
1994 int     Document::CountWords(CPDF_TextObject* pTextObj)\r
1995 {\r
1996         if (!pTextObj) return 0;\r
1997 \r
1998         int nWords = 0;\r
1999 \r
2000         CPDF_Font* pFont = pTextObj->GetFont();\r
2001         if (!pFont) return 0;\r
2002 \r
2003         FX_BOOL bIsLatin = FALSE;\r
2004 \r
2005         for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)\r
2006         {\r
2007                 FX_DWORD charcode = -1;\r
2008                 FX_FLOAT kerning;\r
2009 \r
2010                 pTextObj->GetCharInfo(i, charcode, kerning);\r
2011                 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);\r
2012 \r
2013                 FX_WORD unicode = 0;\r
2014                 if (swUnicode.GetLength() > 0)\r
2015                         unicode = swUnicode[0];\r
2016 \r
2017                 if (ISLATINWORD(unicode) && bIsLatin)\r
2018                         continue;\r
2019                 \r
2020                 bIsLatin = ISLATINWORD(unicode);\r
2021                 if (unicode != 0x20)\r
2022                         nWords++;\r
2023         }\r
2024 \r
2025         return nWords;\r
2026 }\r
2027 \r
2028 CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)\r
2029 {\r
2030         ASSERT(pTextObj != NULL);\r
2031 \r
2032         CFX_WideString swRet;\r
2033 \r
2034         CPDF_Font* pFont = pTextObj->GetFont();\r
2035         if (!pFont) return L"";\r
2036 \r
2037         int nWords = 0;\r
2038         FX_BOOL bIsLatin = FALSE;\r
2039 \r
2040         for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)\r
2041         {\r
2042                 FX_DWORD charcode = -1;\r
2043                 FX_FLOAT kerning;\r
2044 \r
2045                 pTextObj->GetCharInfo(i, charcode, kerning);\r
2046                 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);\r
2047 \r
2048                 FX_WORD unicode = 0;\r
2049                 if (swUnicode.GetLength() > 0)\r
2050                         unicode = swUnicode[0];\r
2051 \r
2052                 if (ISLATINWORD(unicode) && bIsLatin)\r
2053                 {\r
2054                 }\r
2055                 else\r
2056                 {               \r
2057                         bIsLatin = ISLATINWORD(unicode);\r
2058                         if (unicode != 0x20)\r
2059                                 nWords++;       \r
2060                 }\r
2061 \r
2062                 if (nWords-1 == nWordIndex)\r
2063                         swRet += unicode;\r
2064         }\r
2065 \r
2066         return swRet;\r
2067 }\r
2068 \r
2069 FX_BOOL Document::zoom(OBJ_PROP_PARAMS)\r
2070 {\r
2071 \r
2072         return TRUE;\r
2073 }\r
2074 \r
2075 /**\r
2076 (none,  NoVary)\r
2077 (fitP,  FitPage)\r
2078 (fitW,  FitWidth)\r
2079 (fitH,  FitHeight)\r
2080 (fitV,  FitVisibleWidth)\r
2081 (pref,  Preferred)\r
2082 (refW,  ReflowWidth)\r
2083 */\r
2084 \r
2085 FX_BOOL Document::zoomType(OBJ_PROP_PARAMS)\r
2086 {\r
2087         return TRUE;\r
2088 }\r
2089 \r
2090 FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS)\r
2091 {\r
2092         \r
2093 \r
2094         \r
2095         \r
2096 \r
2097 \r
2098         v8::Isolate* isolate = GetIsolate(cc);\r
2099 //      if (pEnv->GetAppName().Compare(PHANTOM) != 0)\r
2100 //              return TRUE;\r
2101 \r
2102         //if (IsSafeMode(cc)) return TRUE;\r
2103 \r
2104         ASSERT(m_pDocument != NULL);\r
2105 \r
2106         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
2107                 m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;\r
2108 \r
2109         int iSize = params.size();\r
2110         \r
2111         int nStart = 0;\r
2112         int nEnd = 0;\r
2113         \r
2114         if (iSize < 1)\r
2115         {\r
2116         }\r
2117         else if (iSize == 1)\r
2118         {\r
2119                 if (params[0].GetType() == VT_object)\r
2120                 {\r
2121                         JSObject  pObj = (JSObject )params[0];\r
2122                         v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
2123                                 nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2124 \r
2125                         pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
2126                                 nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2127                 }\r
2128                 else\r
2129                 {\r
2130                         nStart = (int)params[0];\r
2131                 }\r
2132         }\r
2133         else\r
2134         {\r
2135                 nStart = (int)params[0];\r
2136                 nEnd = (int)params[1];\r
2137         }\r
2138 \r
2139         int nTotal = m_pDocument->GetPageCount();\r
2140 \r
2141         if (nStart < 0) nStart = 0;\r
2142         if (nStart >= nTotal) nStart = nTotal - 1;\r
2143 \r
2144         if (nEnd < 0) nEnd = 0;\r
2145         if (nEnd >= nTotal) nEnd = nTotal - 1;\r
2146 \r
2147         if (nEnd < nStart) nEnd = nStart;\r
2148 \r
2149         \r
2150 \r
2151 #ifndef FOXIT_CHROME_BUILD\r
2152         return m_pDocument->DeletePages(nStart, nEnd - nStart + 1);\r
2153 #else\r
2154         return TRUE;\r
2155 #endif\r
2156 }\r
2157 \r
2158 FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS)\r
2159 {\r
2160         \r
2161 \r
2162         \r
2163         \r
2164         \r
2165 \r
2166         v8::Isolate* isolate = GetIsolate(cc);\r
2167 \r
2168         if (IsSafeMode(cc)) return TRUE;\r
2169 \r
2170         ASSERT(m_pDocument != NULL);\r
2171 \r
2172         if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE;\r
2173 \r
2174         int iSize = params.size();\r
2175         \r
2176         int nTotal = m_pDocument->GetPageCount();\r
2177         int nStart = 0;\r
2178         int nEnd = nTotal - 1;\r
2179 \r
2180         CFX_WideString swFilePath;\r
2181         \r
2182         if (iSize < 1)\r
2183         {\r
2184         }\r
2185         else if (iSize == 1)\r
2186         {\r
2187                 if (params[0].GetType() == VT_object)\r
2188                 {\r
2189                         JSObject  pObj = (JSObject )params[0];\r
2190                         v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
2191                                 nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2192 \r
2193                         pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
2194                                 nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2195 \r
2196                         pValue = JS_GetObjectElement(isolate,pObj, L"cPath");\r
2197                                 swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
2198                 }\r
2199                 else\r
2200                 {\r
2201                         nStart = (int)params[0];\r
2202                 }\r
2203         }\r
2204         else if (iSize == 2)\r
2205         {\r
2206                 nStart = (int)params[0];\r
2207                 nEnd = (int)params[1];\r
2208         }\r
2209         else\r
2210         {\r
2211                 nStart = (int)params[0];\r
2212                 nEnd = (int)params[1];\r
2213                 swFilePath = params[2].operator CFX_WideString();\r
2214         }\r
2215 \r
2216         if (nEnd < nStart)\r
2217                 nEnd = nStart;\r
2218 \r
2219         CPDF_Document *pNewDoc = new CPDF_Document;\r
2220         pNewDoc->CreateNewDoc();        \r
2221 \r
2222         CFX_WordArray array;\r
2223         for (int i=nStart; i<=nEnd; i++)\r
2224                 array.Add(i);\r
2225 \r
2226 //      m_pDocument->ExtractPages(array, pNewDoc);\r
2227 \r
2228         if (swFilePath.IsEmpty())\r
2229         {\r
2230 \r
2231         }\r
2232         else\r
2233         {\r
2234                 swFilePath = app::PDFPathToSysPath(swFilePath);\r
2235                 CPDF_Creator PDFCreater(pNewDoc);\r
2236                 PDFCreater.Create(swFilePath);\r
2237                 delete pNewDoc;\r
2238 //              pEnv->OpenDocument(swFilePath);\r
2239                 vRet.SetNull();\r
2240         }\r
2241 \r
2242         return TRUE;\r
2243 }\r
2244 \r
2245 FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS)\r
2246 {\r
2247 \r
2248 \r
2249         \r
2250 \r
2251 \r
2252 \r
2253         v8::Isolate* isolate = GetIsolate(cc);\r
2254 \r
2255         if (IsSafeMode(cc)) return TRUE;\r
2256 \r
2257         ASSERT(m_pDocument != NULL);\r
2258 \r
2259         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
2260                 m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;\r
2261 \r
2262         int iSize = params.size();\r
2263         \r
2264         int nStart = 0;\r
2265         int nEnd = 0;\r
2266         int nPage = 0;\r
2267 \r
2268         CFX_WideString swFilePath;\r
2269         \r
2270         if (iSize < 1)\r
2271         {\r
2272         }\r
2273         else if (iSize == 1)\r
2274         {\r
2275                 if (params[0].GetType() == VT_object)\r
2276                 {\r
2277                         JSObject  pObj = (JSObject )params[0];\r
2278 \r
2279                         v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");\r
2280                                 nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2281 \r
2282                         pValue = JS_GetObjectElement(isolate,pObj, L"cPath");\r
2283                                 swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
2284 \r
2285                         pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
2286                                 nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2287 \r
2288                         pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
2289                                 nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2290                 }\r
2291                 else\r
2292                 {\r
2293                         nPage = (int)params[0];\r
2294                 }\r
2295         }\r
2296         else \r
2297         {\r
2298                 nPage = (int)params[0];\r
2299 \r
2300                 if (iSize >= 2)\r
2301                         swFilePath = params[1].operator CFX_WideString();\r
2302 \r
2303                 if (iSize >= 3)\r
2304                         nStart = (int)params[2];\r
2305 \r
2306                 if (iSize >= 4)\r
2307                         nEnd = (int)params[3];\r
2308         }\r
2309 \r
2310         nPage++;\r
2311 \r
2312         if (nPage < 0)\r
2313                 nPage = 0;\r
2314 \r
2315         if (nPage > m_pDocument->GetPageCount())\r
2316                 nPage = m_pDocument->GetPageCount();\r
2317 \r
2318         if (swFilePath.IsEmpty()) return FALSE;\r
2319 \r
2320         swFilePath = app::PDFPathToSysPath(swFilePath);\r
2321 \r
2322         CPDF_Parser pdfParser;\r
2323         pdfParser.StartParse(swFilePath, FALSE);\r
2324         CPDF_Document* pSrcDoc = pdfParser.GetDocument();\r
2325 \r
2326         if (!pSrcDoc) \r
2327         {\r
2328                 pdfParser.CloseParser();\r
2329                 return FALSE;\r
2330         }\r
2331 \r
2332         int nTotal = pSrcDoc->GetPageCount();\r
2333 \r
2334         if (nStart < 0) nStart = 0;\r
2335         if (nStart >= nTotal) nStart = nTotal - 1;\r
2336 \r
2337         if (nEnd < 0) nEnd = 0;\r
2338         if (nEnd >= nTotal) nEnd = nTotal - 1;\r
2339 \r
2340         if (nEnd < nStart) nEnd = nStart;\r
2341 \r
2342         CFX_WordArray array;\r
2343         for (int i=nStart; i<=nEnd; i++)\r
2344                 array.Add(i);\r
2345 \r
2346 //      m_pDocument->InsertPages(nPage, pSrcDoc, array);\r
2347 \r
2348         pdfParser.CloseParser();\r
2349 \r
2350         return TRUE;\r
2351 }\r
2352 \r
2353 FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS)\r
2354 {\r
2355 \r
2356 \r
2357         \r
2358 \r
2359 \r
2360 \r
2361         v8::Isolate* isolate = GetIsolate(cc);\r
2362 \r
2363         if (IsSafeMode(cc)) return TRUE;\r
2364 \r
2365         ASSERT(m_pDocument != NULL);\r
2366 \r
2367         if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
2368                 m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;\r
2369 \r
2370         int iSize = params.size();\r
2371         \r
2372         int nStart = -1;\r
2373         int nEnd = -1;\r
2374         int nPage = 0;\r
2375 \r
2376         CFX_WideString swFilePath;\r
2377         \r
2378         if (iSize < 1)\r
2379         {\r
2380         }\r
2381         else if (iSize == 1)\r
2382         {\r
2383                 if (params[0].GetType() == VT_object)\r
2384                 {\r
2385                         JSObject  pObj = (JSObject )params[0];\r
2386 \r
2387                         v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");\r
2388                                 nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2389 \r
2390                         pValue = JS_GetObjectElement(isolate,pObj, L"cPath");\r
2391                                 swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
2392 \r
2393                         pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
2394                                 nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2395 \r
2396                         pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
2397                                 nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
2398                 }\r
2399                 else\r
2400                 {\r
2401                         nPage = (int)params[0];\r
2402                 }\r
2403         }\r
2404         else \r
2405         {\r
2406                 nPage = (int)params[0];\r
2407 \r
2408                 if (iSize >= 2)\r
2409                         swFilePath = params[1].operator CFX_WideString();\r
2410 \r
2411                 if (iSize >= 3)\r
2412                         nStart = (int)params[2];\r
2413 \r
2414                 if (iSize >= 4)\r
2415                         nEnd = (int)params[3];\r
2416         }\r
2417 \r
2418         if (nPage < 0)\r
2419                 nPage = 0;\r
2420 \r
2421         if (nPage >= m_pDocument->GetPageCount())\r
2422                 nPage = m_pDocument->GetPageCount() - 1;\r
2423 \r
2424         if (swFilePath.IsEmpty()) return FALSE;\r
2425 \r
2426         swFilePath = app::PDFPathToSysPath(swFilePath);\r
2427 \r
2428         CPDF_Parser pdfParser;\r
2429         pdfParser.StartParse(swFilePath, FALSE);\r
2430         CPDF_Document* pSrcDoc = pdfParser.GetDocument();\r
2431 \r
2432         if (!pSrcDoc) \r
2433         {\r
2434                 pdfParser.CloseParser();\r
2435                 return FALSE;\r
2436         }\r
2437 \r
2438         int nTotal = pSrcDoc->GetPageCount();\r
2439 \r
2440         if (nStart < 0)\r
2441         {\r
2442                 if (nEnd < 0)\r
2443                 {\r
2444                         nStart = 0;\r
2445                         nEnd = nTotal - 1;\r
2446                 }\r
2447                 else\r
2448                 {\r
2449                         nStart = 0;\r
2450                 }\r
2451         }\r
2452         else\r
2453         {\r
2454                 if (nEnd < 0)\r
2455                 {\r
2456                         nEnd = nStart;\r
2457                 }\r
2458                 else\r
2459                 {\r
2460                         if (nStart >= nTotal) nStart = nTotal - 1;\r
2461                         if (nEnd >= nTotal) nEnd = nTotal - 1;\r
2462 \r
2463                         if (nEnd < nStart) nEnd = nStart;\r
2464                 }\r
2465         }\r
2466 \r
2467         CFX_WordArray array;\r
2468         for (int i=nStart; i<=nEnd; i++)\r
2469                 array.Add(i);\r
2470 \r
2471 //      m_pDocument->ReplacePages(nPage, pSrcDoc, array);\r
2472 \r
2473         pdfParser.CloseParser();\r
2474 \r
2475         return TRUE;\r
2476 }\r
2477 \r
2478 FX_BOOL Document::getURL(OBJ_METHOD_PARAMS)\r
2479 {\r
2480         if (IsSafeMode(cc)) return TRUE;\r
2481 \r
2482         return TRUE;\r
2483 }\r
2484 \r
2485 void Document::AddDelayData(CJS_DelayData* pData)\r
2486 {\r
2487         m_DelayData.Add(pData);\r
2488 }\r
2489 \r
2490 void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)\r
2491 {\r
2492         CFX_DWordArray DelArray;\r
2493 \r
2494         for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)\r
2495         {\r
2496                 if (CJS_DelayData* pData = m_DelayData.GetAt(i))\r
2497                 {\r
2498                         if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)\r
2499                         {\r
2500                                 Field::DoDelay(m_pDocument, pData);\r
2501                                 delete pData;\r
2502                                 m_DelayData.SetAt(i, NULL);\r
2503                                 DelArray.Add(i);\r
2504                         }\r
2505                 }\r
2506         }\r
2507 \r
2508         for (int j=DelArray.GetSize()-1; j>=0; j--)\r
2509         {\r
2510                 m_DelayData.RemoveAt(DelArray[j]);\r
2511         }\r
2512 }\r
2513 \r
2514 void Document::AddDelayAnnotData(CJS_AnnotObj *pData)\r
2515 {\r
2516         m_DelayAnnotData.Add(pData);\r
2517 }\r
2518 \r
2519 void Document::DoAnnotDelay()\r
2520 {\r
2521         CFX_DWordArray DelArray;\r
2522         \r
2523         for (int j=DelArray.GetSize()-1; j>=0; j--)\r
2524         {\r
2525                 m_DelayData.RemoveAt(DelArray[j]);\r
2526         }\r
2527 }\r