Clean up CPDF_AnnotList.
[pdfium.git] / fpdfsdk / src / javascript / Document.cpp
index ec930b8..4c7e191 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/javascript/JavaScript.h"\r
-#include "../../include/javascript/IJavaScript.h"\r
-#include "../../include/javascript/JS_Define.h"\r
-#include "../../include/javascript/JS_Object.h"\r
-#include "../../include/javascript/JS_Value.h"\r
-#include "../../include/javascript/Document.h"\r
-#include "../../include/javascript/JS_EventHandler.h"\r
-#include "../../include/javascript/JS_Context.h"\r
-#include "../../include/javascript/JS_Runtime.h"\r
-#include "../../include/javascript/app.h"\r
-#include "../../include/javascript/Field.h"\r
-#include "../../include/javascript/Icon.h"\r
-#include "../../include/javascript/Field.h"\r
-\r
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)\r
-{\r
-       CJS_Context* pContext = (CJS_Context *)cc;\r
-       ASSERT(pContext != NULL);\r
-\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       return pRuntime->GetIsolate();\r
-}\r
-\r
-BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)\r
-END_JS_STATIC_CONST()\r
-\r
-BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)\r
-END_JS_STATIC_PROP()\r
-\r
-BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)\r
-END_JS_STATIC_METHOD()\r
-\r
-IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)\r
-\r
-PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)\r
-: CJS_EmbedObj(pJSObject)\r
-{\r
-       bUI = TRUE;\r
-       nStart = 0;\r
-       nEnd = 0;\r
-       bSilent = FALSE;\r
-       bShrinkToFit = FALSE;\r
-       bPrintAsImage = FALSE;\r
-       bReverse = FALSE;\r
-       bAnnotations = TRUE;\r
-}\r
-\r
-/* ---------------------- Document ---------------------- */\r
-\r
-#define MINWIDTH  5.0f\r
-#define MINHEIGHT 5.0f\r
-\r
-BEGIN_JS_STATIC_CONST(CJS_Document)\r
-END_JS_STATIC_CONST()\r
-\r
-BEGIN_JS_STATIC_PROP(CJS_Document)\r
-       JS_STATIC_PROP_ENTRY(ADBE)\r
-       JS_STATIC_PROP_ENTRY(author)\r
-       JS_STATIC_PROP_ENTRY(baseURL)\r
-       JS_STATIC_PROP_ENTRY(bookmarkRoot)\r
-       JS_STATIC_PROP_ENTRY(calculate)\r
-       JS_STATIC_PROP_ENTRY(Collab)\r
-       JS_STATIC_PROP_ENTRY(creationDate)\r
-       JS_STATIC_PROP_ENTRY(creator)\r
-       JS_STATIC_PROP_ENTRY(delay)\r
-       JS_STATIC_PROP_ENTRY(dirty)\r
-       JS_STATIC_PROP_ENTRY(documentFileName)\r
-       JS_STATIC_PROP_ENTRY(external)\r
-       JS_STATIC_PROP_ENTRY(filesize)\r
-       JS_STATIC_PROP_ENTRY(icons)\r
-       JS_STATIC_PROP_ENTRY(info)   \r
-       JS_STATIC_PROP_ENTRY(keywords)\r
-       JS_STATIC_PROP_ENTRY(layout)\r
-       JS_STATIC_PROP_ENTRY(media)\r
-       JS_STATIC_PROP_ENTRY(modDate)\r
-       JS_STATIC_PROP_ENTRY(mouseX)\r
-       JS_STATIC_PROP_ENTRY(mouseY)\r
-       JS_STATIC_PROP_ENTRY(numFields)\r
-       JS_STATIC_PROP_ENTRY(numPages)\r
-       JS_STATIC_PROP_ENTRY(pageNum)   \r
-       JS_STATIC_PROP_ENTRY(pageWindowRect)\r
-       JS_STATIC_PROP_ENTRY(path)\r
-       JS_STATIC_PROP_ENTRY(producer)\r
-       JS_STATIC_PROP_ENTRY(subject)\r
-       JS_STATIC_PROP_ENTRY(title)\r
-       JS_STATIC_PROP_ENTRY(zoom)\r
-       JS_STATIC_PROP_ENTRY(zoomType)\r
-END_JS_STATIC_PROP()\r
-\r
-BEGIN_JS_STATIC_METHOD(CJS_Document)\r
-       JS_STATIC_METHOD_ENTRY(addAnnot,0)\r
-       JS_STATIC_METHOD_ENTRY(addField, 4)\r
-       JS_STATIC_METHOD_ENTRY(addLink, 0)\r
-       JS_STATIC_METHOD_ENTRY(addIcon, 0)\r
-       JS_STATIC_METHOD_ENTRY(calculateNow, 0)\r
-       JS_STATIC_METHOD_ENTRY(closeDoc, 0)\r
-       JS_STATIC_METHOD_ENTRY(createDataObject, 0)\r
-       JS_STATIC_METHOD_ENTRY(deletePages, 2)\r
-       JS_STATIC_METHOD_ENTRY(exportAsText, 3)\r
-       JS_STATIC_METHOD_ENTRY(exportAsFDF, 6)\r
-       JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5)\r
-       JS_STATIC_METHOD_ENTRY(extractPages, 3)\r
-       JS_STATIC_METHOD_ENTRY(getAnnot, 0)\r
-       JS_STATIC_METHOD_ENTRY(getAnnots, 2)\r
-       JS_STATIC_METHOD_ENTRY(getAnnot3D, 2)\r
-       JS_STATIC_METHOD_ENTRY(getAnnots3D, 1)\r
-       JS_STATIC_METHOD_ENTRY(getField, 1)\r
-       JS_STATIC_METHOD_ENTRY(getIcon, 0)\r
-       JS_STATIC_METHOD_ENTRY(getLinks, 0)\r
-       JS_STATIC_METHOD_ENTRY(getNthFieldName, 1)\r
-       JS_STATIC_METHOD_ENTRY(getOCGs, 0)\r
-       JS_STATIC_METHOD_ENTRY(getPageBox, 0)\r
-       JS_STATIC_METHOD_ENTRY(getPageNthWord, 3)\r
-       JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2)\r
-       JS_STATIC_METHOD_ENTRY(getPageNumWords, 1)\r
-       JS_STATIC_METHOD_ENTRY(getPrintParams, 0)\r
-       JS_STATIC_METHOD_ENTRY(getURL, 2)\r
-       JS_STATIC_METHOD_ENTRY(importAnFDF, 1)\r
-       JS_STATIC_METHOD_ENTRY(importAnXFDF, 1)\r
-       JS_STATIC_METHOD_ENTRY(importTextData, 2)\r
-       JS_STATIC_METHOD_ENTRY(insertPages, 4)\r
-       JS_STATIC_METHOD_ENTRY(mailForm, 6)\r
-       JS_STATIC_METHOD_ENTRY(print, 9)\r
-       JS_STATIC_METHOD_ENTRY(removeField, 1)\r
-       JS_STATIC_METHOD_ENTRY(replacePages, 4)\r
-       JS_STATIC_METHOD_ENTRY(resetForm, 1)\r
-       JS_STATIC_METHOD_ENTRY(removeIcon, 0)\r
-       JS_STATIC_METHOD_ENTRY(saveAs, 5)\r
-       JS_STATIC_METHOD_ENTRY(submitForm, 23)\r
-       JS_STATIC_METHOD_ENTRY(mailDoc, 0)              \r
-END_JS_STATIC_METHOD()\r
-\r
-IMPLEMENT_JS_CLASS(CJS_Document, Document)\r
-\r
-FX_BOOL        CJS_Document::InitInstance(IFXJS_Context* cc)\r
-{\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-\r
-       Document* pDoc = (Document*)GetEmbedObject();\r
-       ASSERT(pDoc != NULL);\r
-       \r
-       pDoc->AttachDoc(pContext->GetReaderDocument());\r
-       pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());\r
-       return TRUE;\r
-};\r
-\r
-/* --------------------------------- Document --------------------------------- */\r
-\r
-Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),\r
-       m_cwBaseURL(L""),\r
-       m_pIconTree(NULL),\r
-       m_pDocument(NULL),\r
-       m_bDelay(FALSE),\r
-       m_isolate(NULL)\r
-{\r
-}\r
-\r
-Document::~Document()\r
-{\r
-       if (m_pIconTree)\r
-       {\r
-               m_pIconTree->DeleteIconTree();\r
-               delete m_pIconTree;\r
-               m_pIconTree = NULL;\r
-       }\r
-       for (int i=0; i<m_DelayData.GetSize(); i++)\r
-       {\r
-               if (CJS_DelayData* pData = m_DelayData.GetAt(i))\r
-               {\r
-                       delete pData;\r
-                       pData = NULL;\r
-                       m_DelayData.SetAt(i, NULL);\r
-                       \r
-               }\r
-       }\r
-\r
-       m_DelayData.RemoveAll();\r
-       m_DelayAnnotData.RemoveAll();\r
-}\r
-\r
-//the total number of fileds in document.\r
-FX_BOOL Document::numFields(OBJ_PROP_PARAMS)\r
-{\r
-       if (!vp.IsGetting()) return FALSE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();\r
-       ASSERT(pPDFForm != NULL);\r
-\r
-       vp << (int)pPDFForm->CountFields();\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::dirty(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               if (m_pDocument->GetChangeMark())\r
-                       vp << true;\r
-               else\r
-                       vp << false;\r
-       }\r
-       else\r
-       {\r
-               bool bChanged = false;\r
-\r
-               vp >> bChanged;\r
-\r
-               if (bChanged)\r
-                       m_pDocument->SetChangeMark();\r
-               else\r
-                       m_pDocument->ClearChangeMark();\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::ADBE(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp.SetNull();\r
-       }\r
-       else\r
-       {\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::pageNum(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (vp.IsGetting())\r
-       {                       \r
-               if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())\r
-               {\r
-                       vp << pPageView->GetPageIndex();\r
-               }\r
-       }\r
-       else\r
-       {               \r
-               int iPageCount = m_pDocument->GetPageCount();\r
-\r
-               int iPageNum = 0;\r
-               vp >> iPageNum;\r
-\r
-               CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-               if(!pEnv)\r
-                       return FALSE;\r
-\r
-               if (iPageNum >= 0 && iPageNum < iPageCount)\r
-               {\r
-                        pEnv->JS_docgotoPage(iPageNum);\r
-               }\r
-               else if (iPageNum >= iPageCount)\r
-               {\r
-                        pEnv->JS_docgotoPage(iPageCount-1);\r
-               }\r
-               else if (iPageNum < 0)\r
-               {\r
-                        pEnv->JS_docgotoPage(0);\r
-               }\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::addField(OBJ_METHOD_PARAMS)\r
-{\r
-       //Doesn't support.\r
-       return TRUE;\r
-}\r
-\r
-//exports form fields as a tab-delimited text file to a local hard disk.\r
-//comment: need reader support\r
-//note : watch the third parameter:cPath, for what case it can be safely saved?\r
-//int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath);\r
-//return value, int the index of the parameters illegal, the index is based on 1.\r
-\r
-FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-       return TRUE;\r
-}\r
-\r
-//exports form fields as a fdf file to the local hard drive\r
-//comment: need reader supports\r
-//note:the last parameter hasn't been confirmed.because the previous one blocks the way.\r
-//int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations);\r
-\r
-FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS)\r
-{\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE;\r
-       FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE;\r
-       FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE;\r
-       CJS_Array arrayFileds(isolate);\r
-       if (!bWhole)\r
-               arrayFileds.Attach(params[2]);\r
-       //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE;\r
-    CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
-\r
-       if (swFilePath.IsEmpty())\r
-       {\r
-               CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-               swFilePath = pEnv->JS_fieldBrowse();\r
-               if(swFilePath.IsEmpty())\r
-                       return TRUE;\r
-       }\r
-       else\r
-       {\r
-               swFilePath = app::PDFPathToSysPath(swFilePath);\r
-       }\r
-    \r
-       m_pDocument->SetFocusAnnot(NULL);\r
-   \r
-    CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
-       ASSERT(pPDFForm != NULL);\r
-\r
-       CFX_PtrArray aFields;\r
-\r
-       if (bWhole)\r
-       {\r
-               for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++)\r
-               {\r
-                       aFields.Add(pPDFForm->GetField(j));\r
-               }\r
-       }\r
-       else\r
-       {\r
-               for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++)\r
-               {\r
-                       CJS_Value valName(isolate);\r
-                       arrayFileds.GetElement(i,valName);\r
-                       CFX_WideString swName = valName.operator CFX_WideString();\r
-\r
-                       for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++)\r
-                       {\r
-                               aFields.Add(pPDFForm->GetField(j, swName));\r
-                       }\r
-               }\r
-       }\r
-\r
-       CFX_PtrArray fields;\r
-\r
-       for (int i=0,sz=aFields.GetSize(); i<sz; i++)\r
-       {\r
-           CPDF_FormField* pField = (CPDF_FormField*)aFields[i];\r
-               \r
-               if (!bAllFields)\r
-                       if (pField->GetValue() == L"")\r
-                               continue;\r
-\r
-               if (bNoPassWord)\r
-                       if (pField->GetFieldFlags() & 0x2000)\r
-                               continue;\r
-\r
-        fields.Add((void*)pField);\r
-       }    \r
-\r
-    return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE);\r
-}\r
-\r
-//exports form fields an XFDF file to the local hard drive\r
-//comment: need reder supports\r
-//note:the last parameter can't be test\r
-//int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL  bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations);\r
-\r
-FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       return TRUE;\r
-}\r
-\r
-//Maps a field object in PDF document to a JavaScript variable\r
-//comment:\r
-//note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document\r
-\r
-FX_BOOL Document::getField(OBJ_METHOD_PARAMS)\r
-{\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (params.size() < 1) return FALSE;\r
-\r
-       CFX_WideString wideName = params[0].operator CFX_WideString();\r
-\r
-    CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
-       ASSERT(pPDFForm != NULL);\r
-\r
-       if (pPDFForm->CountFields(wideName) <= 0) \r
-       {\r
-               vRet.SetNull();\r
-               return TRUE;\r
-       }\r
-\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       JSFXObject  pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));\r
-\r
-       CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);\r
-       ASSERT(pJSField != NULL);\r
-\r
-       Field * pField = (Field *)pJSField->GetEmbedObject(); \r
-       ASSERT(pField != NULL);\r
-\r
-       pField->AttachField(this, wideName);\r
-       vRet = pJSField;\r
-\r
-       return TRUE;\r
-}\r
-\r
-//Gets the name of the nth field in the document \r
-//comment:\r
-//note: the parameter nIndex, if it is not available\r
-\r
-FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       int nIndex = params.size() > 0 ? (int)params[0] : -1;\r
-       if (nIndex == -1) return FALSE;\r
-\r
-       CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
-       ASSERT(pPDFForm != NULL);\r
-\r
-       CPDF_FormField* pField = pPDFForm->GetField(nIndex);\r
-       if (!pField)\r
-               return FALSE;\r
-\r
-       vRet = pField->GetFullName();\r
-       return TRUE;    \r
-}\r
-\r
-//imports the specified fdf file.\r
-//comments: need reader suppport\r
-//note:once the cpath is illigl  then a file dialog box pops up in order to ask user to chooose the file\r
-//int CPDFSDK_Document::importAnFDF(String cPath);\r
-\r
-FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
-               m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
-\r
-\r
-       CFX_WideString swPath;\r
-       \r
-       if (params.size() > 0)\r
-               swPath = params[0];\r
-    \r
-       if (swPath.IsEmpty())\r
-       {\r
-               CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-               swPath = pEnv->JS_fieldBrowse();\r
-               if(swPath.IsEmpty())\r
-                       return TRUE;\r
-       }\r
-       else\r
-       {\r
-               swPath = app::PDFPathToSysPath(swPath);\r
-       }\r
-\r
-       m_pDocument->SetFocusAnnot(NULL);\r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE))\r
-               return FALSE;\r
-\r
-       m_pDocument->SetChangeMark();\r
-//     CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();\r
-//     ASSERT(pEnv != NULL);\r
-//     IUndo* pUndo = IUndo::GetUndo(pEnv);\r
-//     ASSERT(pUndo != NULL);\r
-//     pUndo->Reset(m_pDocument);\r
-\r
-       return TRUE;\r
-}\r
-\r
-//imports and specified XFDF file containing XML form data\r
-//comment: need reader supports\r
-//note: same as up\r
-//int CPDFSDK_Document::importAnFDF(String cPath)\r
-\r
-FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
-               m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
-\r
-       return TRUE;\r
-}\r
-\r
-//imports and specified text file \r
-//commnet: need reader supports\r
-//note: same as up,when nRow is not rational,adobe is dumb for it.\r
-//int CPDFSDK_Document::importTextData(String cPath,int nRow);\r
-\r
-FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
-               m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
-\r
-       return TRUE;\r
-}\r
-\r
-//exports the form data and mails the resulting fdf file as an attachment to all recipients.\r
-//comment: need reader supports\r
-//note:\r
-//int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);\r
-\r
-FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       int iLength = params.size();\r
-\r
-       FX_BOOL bUI = iLength > 0 ? (FX_BOOL)params[0] : TRUE;\r
-       CFX_WideString cTo = iLength > 1 ? (FX_LPCWSTR)params[1].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
-       CFX_WideString cCc = iLength > 2 ? (FX_LPCWSTR)params[2].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
-       CFX_WideString cBcc = iLength > 3 ? (FX_LPCWSTR)params[3].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
-       CFX_WideString cSubject = iLength > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
-       CFX_WideString cMsg = iLength > 5 ? (FX_LPCWSTR)params[5].operator CFX_WideString() : (FX_LPCWSTR)L"";\r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CFX_ByteTextBuf textBuf;\r
-       if (!pInterForm->ExportFormToFDFTextBuf(textBuf))\r
-               return FALSE;\r
-\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CPDFDoc_Environment* pEnv = pContext->GetReaderApp();\r
-       ASSERT(pEnv != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       pRuntime->BeginBlock();\r
-    pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);\r
-       pRuntime->EndBlock();\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::print(OBJ_METHOD_PARAMS)\r
-{\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       FX_BOOL bUI = TRUE;\r
-       int nStart = 0;\r
-       int nEnd = 0;\r
-       FX_BOOL bSilent = FALSE;\r
-       FX_BOOL bShrinkToFit = FALSE;\r
-       FX_BOOL bPrintAsImage = FALSE;\r
-       FX_BOOL bReverse = FALSE;\r
-       FX_BOOL bAnnotations = FALSE;\r
-\r
-       int nlength = params.size();\r
-       if(nlength ==9)\r
-       {\r
-               if (params[8].GetType() == VT_fxobject)\r
-               {\r
-                       JSFXObject pObj = (JSFXObject)params[8];\r
-                       {\r
-                               if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))\r
-                               {\r
-                                       if (CJS_Object* pJSObj = (CJS_Object*)params[8])\r
-                                       {\r
-                                                       if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())\r
-                                                       {\r
-                                                               bUI = pprintparamsObj->bUI;\r
-                                                               nStart = pprintparamsObj->nStart;\r
-                                                               nEnd = pprintparamsObj->nEnd;\r
-                                                               bSilent = pprintparamsObj->bSilent;\r
-                                                               bShrinkToFit = pprintparamsObj->bShrinkToFit;\r
-                                                               bPrintAsImage = pprintparamsObj->bPrintAsImage;\r
-                                                               bReverse = pprintparamsObj->bReverse;\r
-                                                               bAnnotations = pprintparamsObj->bAnnotations;\r
-                                                       }\r
-                                       }\r
-                               }\r
-                       }       \r
-               }\r
-       }\r
-       else\r
-       {\r
-               if(nlength >= 1)\r
-                        bUI = params[0];\r
-               if(nlength >= 2)\r
-                        nStart = (int)params[1];\r
-               if(nlength >= 3)\r
-                   nEnd = (int)params[2];\r
-               if(nlength >= 4)\r
-                       bSilent = params[3];\r
-               if(nlength >= 5)\r
-                   bShrinkToFit = params[4];\r
-               if(nlength >= 6)\r
-                       bPrintAsImage = params[5];\r
-               if(nlength >= 7)\r
-                       bReverse = params[6];\r
-               if(nlength >= 8)\r
-                       bAnnotations = params[7];\r
-       }\r
-\r
-       ASSERT(m_pDocument != NULL);\r
\r
-       if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())\r
-       {\r
-               pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);\r
-               return TRUE;\r
-       }\r
-       return FALSE;\r
-}\r
-\r
-//removes the specified field from the document.\r
-//comment:\r
-//note: if the filed name is not retional, adobe is dumb for it.\r
-\r
-FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;\r
-\r
-       if (params.size() < 1)\r
-               return TRUE;\r
-\r
-       CFX_WideString sFieldName = params[0].operator CFX_WideString();\r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CFX_PtrArray widgets;\r
-       pInterForm->GetWidgets(sFieldName, widgets);\r
-\r
-       int nSize = widgets.GetSize();\r
-\r
-       if (nSize > 0)\r
-       {\r
-               for (int i=0; i<nSize; i++)\r
-               {\r
-                       CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];\r
-                       ASSERT(pWidget != NULL);\r
-\r
-                       CPDF_Rect rcAnnot = pWidget->GetRect();\r
-                       rcAnnot.left -= 1;\r
-                       rcAnnot.bottom -= 1;\r
-                       rcAnnot.right += 1;\r
-                       rcAnnot.top += 1;\r
-\r
-                       CFX_RectArray aRefresh;\r
-                       aRefresh.Add(rcAnnot);\r
-\r
-                       CPDF_Page* pPage = pWidget->GetPDFPage();\r
-                       ASSERT(pPage != NULL);\r
-                       \r
-                       CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);\r
-                       pPageView->DeleteAnnot(pWidget);\r
-\r
-                       pPageView->UpdateRects(aRefresh);\r
-               }\r
-               m_pDocument->SetChangeMark();\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-//reset filed values within a document.\r
-//comment:\r
-//note: if the fields names r not rational, aodbe is dumb for it.\r
-\r
-FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
-               m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
-       ASSERT(pPDFForm != NULL);\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-       CJS_Array aName(isolate);\r
-\r
-       if (params.size() > 0)\r
-       {\r
-               switch (params[0].GetType())\r
-               {\r
-               default:\r
-                       aName.Attach(params[0]);\r
-                       break;\r
-               case VT_string:\r
-                       aName.SetElement(0,params[0]);\r
-                       break;\r
-               }\r
-\r
-               CFX_PtrArray aFields;\r
-\r
-               for (int i=0,isz=aName.GetLength(); i<isz; i++)\r
-               {\r
-                       CJS_Value valElement(isolate);\r
-                       aName.GetElement(i,valElement);\r
-                       CFX_WideString swVal = valElement.operator CFX_WideString();    \r
-                       \r
-                       for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)\r
-                       {\r
-                               aFields.Add((void*)pPDFForm->GetField(j,swVal));\r
-                       }               \r
-               }\r
-\r
-               if (aFields.GetSize() > 0)\r
-               {\r
-                       pPDFForm->ResetForm(aFields, TRUE, TRUE);\r
-                       m_pDocument->SetChangeMark();\r
-\r
-               }\r
-       }\r
-       else\r
-       {\r
-               pPDFForm->ResetForm(TRUE);\r
-               m_pDocument->SetChangeMark();\r
-\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-\r
-FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS)\r
-{\r
-\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-//     m_pDocument->DoSaveAs();\r
-\r
-       return TRUE;\r
-}\r
-\r
-\r
-FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-//     if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       int nSize = params.size();\r
-       if (nSize < 1) return FALSE;\r
-\r
-       CFX_WideString strURL;\r
-       FX_BOOL bFDF = TRUE;\r
-       FX_BOOL bEmpty = FALSE;\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-       CJS_Array aFields(isolate);\r
-\r
-       CJS_Value v = params[0];\r
-       if (v.GetType() == VT_string)\r
-       {\r
-               strURL = params[0].operator CFX_WideString();\r
-               if (nSize > 1)\r
-                       bFDF = params[1];\r
-               if (nSize > 2)\r
-                       bEmpty = params[2];\r
-               if (nSize > 3)\r
-                       aFields.Attach(params[3]);\r
-       }\r
-       else if (v.GetType() == VT_object)\r
-       {\r
-               JSObject pObj = (JSObject)params[0];\r
-               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cURL");\r
-               if (!pValue.IsEmpty())\r
-                       strURL = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"bFDF");\r
-                       bFDF = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"bEmpty");\r
-                       bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));\r
-               pValue = JS_GetObjectElement(isolate,pObj,L"aFields");\r
-                       aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)));\r
-       }               \r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-       CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();\r
-       ASSERT(pPDFInterForm != NULL);\r
-\r
-       FX_BOOL bAll = (aFields.GetLength() == 0);\r
-\r
-       if (bAll && bEmpty)\r
-       {\r
-               CJS_Context* pContext = (CJS_Context*)cc;\r
-               ASSERT(pContext != NULL);\r
-               CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-               ASSERT(pRuntime != NULL);\r
-\r
-               \r
-               if (pPDFInterForm->CheckRequiredFields())\r
-               {\r
-                       pRuntime->BeginBlock();\r
-                       pInterForm->SubmitForm(strURL, FALSE);\r
-                       pRuntime->EndBlock();\r
-               }\r
-\r
-               return TRUE;\r
-       }\r
-       else\r
-       {       \r
-               CFX_PtrArray fieldObjects;\r
-\r
-               for (int i=0,sz=aFields.GetLength(); i<sz; i++)\r
-               {\r
-                       CJS_Value valName(isolate);\r
-                       aFields.GetElement(i, valName);\r
-                       CFX_WideString sName = valName.operator CFX_WideString();\r
-\r
-                       CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();\r
-                       ASSERT(pPDFForm != NULL);\r
-\r
-                       for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j++)\r
-                       {\r
-                               CPDF_FormField* pField = pPDFForm->GetField(j, sName);\r
-                               if (!bEmpty && pField->GetValue().IsEmpty())\r
-                                       continue;\r
-\r
-                               fieldObjects.Add(pField);\r
-                       }\r
-               }\r
-\r
-               CJS_Context* pContext = (CJS_Context*)cc;\r
-               ASSERT(pContext != NULL);\r
-               CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-               ASSERT(pRuntime != NULL);\r
-\r
-               \r
-               if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))\r
-               {\r
-                       pRuntime->BeginBlock();\r
-                       pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);\r
-                       pRuntime->EndBlock();\r
-               }\r
-\r
-               return TRUE;\r
-       }\r
-\r
-}\r
-\r
-//////////////////////////////////////////////////////////////////////////////////////////////\r
-\r
-void Document::AttachDoc(CPDFSDK_Document *pDoc)\r
-{\r
-       m_pDocument = pDoc;\r
-}\r
-\r
-CPDFSDK_Document * Document::GetReaderDoc()\r
-{\r
-       return m_pDocument;\r
-}\r
-\r
-FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS)\r
-{      \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       FX_BOOL bUI = TRUE;\r
-       CFX_WideString cTo = L"";\r
-       CFX_WideString cCc = L"";\r
-       CFX_WideString cBcc = L"";\r
-       CFX_WideString cSubject = L"";\r
-       CFX_WideString cMsg = L"";\r
-       \r
-\r
-       bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE;\r
-       cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L"";\r
-       cCc = params.size()>=3?(const wchar_t*)params[2].operator CFX_WideString():L"";\r
-       cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L"";\r
-       cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L"";\r
-       cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L"";\r
-       \r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       if(params.size()>=1 && params[0].GetType() == VT_object)\r
-       {\r
-               JSObject  pObj = (JSObject )params[0];\r
-\r
-               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");\r
-                       bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cTo");\r
-                       cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cCc");\r
-                       cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");\r
-                       cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");\r
-                       cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");\r
-                       cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-       \r
-       }\r
-\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       pRuntime->BeginBlock();\r
-       CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();\r
-       pEnv->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);\r
-       pRuntime->EndBlock();\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::author(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("Author");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString csAuthor;\r
-               vp >> csAuthor;\r
-               pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::info(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       CFX_WideString cwAuthor                 = pDictionary->GetUnicodeText("Author");\r
-       CFX_WideString cwTitle                  = pDictionary->GetUnicodeText("Title");\r
-       CFX_WideString cwSubject                = pDictionary->GetUnicodeText("Subject");\r
-       CFX_WideString cwKeywords               = pDictionary->GetUnicodeText("Keywords");\r
-       CFX_WideString cwCreator                = pDictionary->GetUnicodeText("Creator");\r
-       CFX_WideString cwProducer               = pDictionary->GetUnicodeText("Producer");\r
-       CFX_WideString cwCreationDate   = pDictionary->GetUnicodeText("CreationDate");\r
-       CFX_WideString cwModDate                = pDictionary->GetUnicodeText("ModDate");\r
-       CFX_WideString cwTrapped                = pDictionary->GetUnicodeText("Trapped");\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-       if (!vp.IsSetting())\r
-       {\r
-               CJS_Context* pContext = (CJS_Context *)cc;\r
-               CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-\r
-               JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);\r
-\r
-               JS_PutObjectString(isolate,pObj, L"Author", cwAuthor);\r
-               JS_PutObjectString(isolate,pObj, L"Title", cwTitle);\r
-               JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);\r
-               JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);\r
-               JS_PutObjectString(isolate,pObj, L"Creator", cwCreator);\r
-               JS_PutObjectString(isolate,pObj, L"Producer", cwProducer);\r
-               JS_PutObjectString(isolate,pObj, L"CreationDate", cwCreationDate);\r
-               JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate);\r
-               JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped);\r
-\r
-// It's to be compatible to non-standard info dictionary.      \r
-               FX_POSITION pos = pDictionary->GetStartPos();\r
-               while(pos)\r
-               {\r
-                       CFX_ByteString bsKey;\r
-                       CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);\r
-                       CFX_WideString wsKey  = CFX_WideString::FromUTF8(bsKey);\r
-                       if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )\r
-                                       JS_PutObjectString(isolate,pObj, wsKey, pValueObj->GetUnicodeText());\r
-                       if(pValueObj->GetType()==PDFOBJ_NUMBER)\r
-                               JS_PutObjectNumber(isolate,pObj, wsKey, (float)pValueObj->GetNumber());\r
-                       if(pValueObj->GetType()==PDFOBJ_BOOLEAN)\r
-                               JS_PutObjectBoolean(isolate,pObj, wsKey, (bool)pValueObj->GetInteger());\r
-               }\r
-\r
-               vp << pObj;\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("CreationDate");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString csCreationDate;\r
-               vp >> csCreationDate;\r
-               pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));\r
-               m_pDocument->SetChangeMark();\r
-\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::creator(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("Creator");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString csCreator;\r
-               vp >> csCreator;\r
-               pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::delay(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << m_bDelay;\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               ASSERT(m_pDocument != NULL);\r
-\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               bool b;\r
-               vp >> b;\r
-\r
-               m_bDelay = b;\r
-\r
-               if (m_bDelay) \r
-               {\r
-                       for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)\r
-                               delete m_DelayData.GetAt(i);\r
-\r
-                       m_DelayData.RemoveAll();\r
-               }\r
-               else\r
-               {\r
-                       for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)\r
-                       {\r
-                               if (CJS_DelayData* pData = m_DelayData.GetAt(i))\r
-                               {\r
-                                       Field::DoDelay(m_pDocument, pData);\r
-                                       delete m_DelayData.GetAt(i);\r
-                               }\r
-                       }\r
-                       m_DelayData.RemoveAll();\r
-               }\r
-\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::keywords(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("Keywords");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString csKeywords;\r
-               vp >> csKeywords;\r
-               pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::modDate(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("ModDate");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString csmodDate;\r
-               vp >> csmodDate;\r
-               pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::producer(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("Producer");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString csproducer;\r
-               vp >> csproducer;\r
-               pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::subject(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("Subject");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString cssubject;\r
-               vp >> cssubject;\r
-               pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::title(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)\r
-               return FALSE;\r
-\r
-       CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();\r
-       if (!pDictionary)return FALSE;\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << pDictionary->GetUnicodeText("Title");\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;\r
-\r
-               CFX_WideString cstitle;\r
-               vp >> cstitle;\r
-               pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));\r
-               m_pDocument->SetChangeMark();\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::numPages(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               ASSERT(m_pDocument != NULL);\r
-               vp << m_pDocument->GetPageCount();\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               return FALSE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::external(OBJ_PROP_PARAMS)\r
-{\r
-       //In Chrome case,should always return true.\r
-       vp << TRUE;\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::filesize(OBJ_PROP_PARAMS)\r
-{\r
-       if (!vp.IsGetting())return FALSE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-//     CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);\r
-//     vp << (double)file.GetLength();\r
-//     file.Close();\r
-\r
-       if ( m_pDocument->GetPath().IsEmpty() == FALSE)\r
-       {\r
-               CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() );\r
-               FILE * pFile = NULL;\r
-               pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" );\r
-               if ( pFile )\r
-               {\r
-                       fseek( pFile, 0, SEEK_END );\r
-                       long lSize = ftell( pFile );\r
-                       fclose( pFile );\r
-                       pFile = NULL;\r
-\r
-                       vp << (FX_INT32)(lSize);\r
-                       return TRUE;\r
-               }\r
-       }\r
-\r
-       vp << 0;\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::mouseX(OBJ_PROP_PARAMS)\r
-{\r
-       return TRUE;    \r
-}\r
-\r
-FX_BOOL Document::mouseY(OBJ_PROP_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::baseURL(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << m_cwBaseURL;\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               vp >> m_cwBaseURL;\r
-               return TRUE;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::calculate(OBJ_PROP_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               if (pInterForm->IsCalculateEnabled())\r
-                       vp << true;\r
-               else\r
-                       vp << false;\r
-       }\r
-       else\r
-       {\r
-               bool bCalculate;\r
-               vp >> bCalculate;\r
-\r
-               pInterForm->EnableCalculate(bCalculate);\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::documentFileName(OBJ_PROP_PARAMS)\r
-{\r
-       if (!vp.IsGetting())\r
-               return FALSE;\r
-\r
-       CFX_WideString wsFilePath = m_pDocument->GetPath();\r
-\r
-       FX_INT32 i = wsFilePath.GetLength() - 1;\r
-       for ( ; i >= 0; i-- )\r
-       {\r
-               if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )\r
-                       break;\r
-       }\r
-       if ( i >= 0 && i < wsFilePath.GetLength() - 1 )\r
-       {\r
-               vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );\r
-       }else{\r
-               vp << L"";\r
-       }\r
-       return TRUE;\r
-}\r
-\r
-CFX_WideString Document::ReversalStr(CFX_WideString cbFrom)\r
-{\r
-       wchar_t* pFrom = NULL;\r
-       int iLenth = cbFrom.GetLength();\r
-       wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));\r
-       memset(pResult, 0, (iLenth+1));\r
-       pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);\r
-\r
-       for (int i = 0; i < iLenth; i++)\r
-       {\r
-               pResult[i] = *(pFrom + iLenth - i - 1);\r
-       }\r
-\r
-       cbFrom.ReleaseBuffer();\r
-       CFX_WideString cbRet = CFX_WideString(pResult);\r
-       free(pResult);\r
-       pResult = NULL;\r
-       return cbRet;\r
-}\r
-\r
-CFX_WideString Document::CutString(CFX_WideString cbFrom)\r
-{\r
-       wchar_t* pFrom = NULL;\r
-       int iLenth = cbFrom.GetLength();\r
-       wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));\r
-       memset(pResult, 0, (iLenth+1));\r
-       pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);\r
-\r
-       for (int i = 0; i < iLenth; i++)\r
-       {\r
-               if (pFrom[i] == L'\\' || pFrom[i] == L'/')\r
-                       break;\r
-               pResult[i] = pFrom[i];\r
-       }\r
-\r
-       cbFrom.ReleaseBuffer();\r
-       CFX_WideString cbRet = CFX_WideString(pResult);\r
-       free(pResult);\r
-       pResult = NULL;\r
-       return cbRet;\r
-}\r
-\r
-FX_BOOL Document::path(OBJ_PROP_PARAMS)\r
-{\r
-       if (!vp.IsGetting()) return FALSE;\r
-\r
-       vp << app::SysPathToPDFPath(m_pDocument->GetPath());\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::layout(OBJ_PROP_PARAMS)\r
-{      \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::addLink(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-\r
-       \r
-       \r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getPageBox(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-\r
-FX_BOOL Document::getAnnot(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getAnnots(OBJ_METHOD_PARAMS)\r
-{\r
-       vRet.SetNull();\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getAnnot3D(OBJ_METHOD_PARAMS)\r
-{\r
-       vRet.SetNull();\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS)\r
-{\r
-       vRet = VT_undefined;\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS)\r
-{      \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getLinks(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)\r
-{\r
-       if (rect.left <= LinkRect.left\r
-         && rect.top <= LinkRect.top\r
-         && rect.right >= LinkRect.right\r
-         && rect.bottom >= LinkRect.bottom)\r
-               return true;\r
-       else\r
-               return false;\r
-}\r
-\r
-void IconTree::InsertIconElement(IconElement* pNewIcon)\r
-{\r
-       if (!pNewIcon)return;\r
-\r
-       if (m_pHead == NULL && m_pEnd == NULL)\r
-       {\r
-               m_pHead = m_pEnd = pNewIcon;\r
-               m_iLength++;\r
-       }\r
-       else\r
-       {\r
-               m_pEnd->NextIcon = pNewIcon;\r
-               m_pEnd = pNewIcon;\r
-               m_iLength++;\r
-       }\r
-}\r
-\r
-void IconTree::DeleteIconTree()\r
-{\r
-       if (!m_pHead || !m_pEnd)return;\r
-       \r
-       IconElement* pTemp = NULL;\r
-       while(m_pEnd != m_pHead)\r
-       {\r
-               pTemp = m_pHead;\r
-               m_pHead = m_pHead->NextIcon;\r
-               delete pTemp;\r
-       }\r
-\r
-       delete m_pEnd;\r
-       m_pHead = NULL;\r
-       m_pEnd = NULL;\r
-}\r
-\r
-int IconTree::GetLength()\r
-{\r
-       return m_iLength;\r
-}\r
-\r
-IconElement* IconTree::operator [](int iIndex)\r
-{\r
-       if (iIndex >= 0 && iIndex <= m_iLength)\r
-       {\r
-               IconElement* pTemp = m_pHead;\r
-               for (int i = 0; i < iIndex; i++)\r
-               {\r
-                       pTemp = pTemp->NextIcon;\r
-               }\r
-               return pTemp;\r
-       }\r
-       else\r
-               return NULL;\r
-}\r
-\r
-void IconTree::DeleteIconElement(CFX_WideString swIconName)\r
-{\r
-       IconElement* pTemp = m_pHead;\r
-       int iLoopCount = m_iLength; \r
-       for (int i = 0; i < iLoopCount - 1; i++)\r
-       {\r
-               if (pTemp == m_pEnd)\r
-                       break;\r
-       \r
-               if (m_pHead->IconName == swIconName)\r
-               {\r
-                       m_pHead = m_pHead->NextIcon;\r
-                       delete pTemp;\r
-                       m_iLength--;\r
-                       pTemp = m_pHead;\r
-               }\r
-               if (pTemp->NextIcon->IconName == swIconName)\r
-               {\r
-                       if (pTemp->NextIcon == m_pEnd)\r
-                       {\r
-                               m_pEnd = pTemp;\r
-                               delete pTemp->NextIcon;\r
-                               m_iLength--;\r
-                               pTemp->NextIcon = NULL;\r
-                       }\r
-                       else\r
-                       {\r
-                               IconElement* pElement = pTemp->NextIcon;\r
-                               pTemp->NextIcon = pTemp->NextIcon->NextIcon;\r
-                               delete pElement;\r
-                               m_iLength--;\r
-                               pElement = NULL;\r
-                       }\r
-\r
-                       continue;\r
-               }\r
-\r
-               pTemp = pTemp->NextIcon;\r
-       }\r
-}\r
-\r
-FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS)\r
-{\r
-       if (params.size() != 2)return FALSE;\r
-\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       CFX_WideString swIconName = params[0].operator CFX_WideString();\r
-       \r
-       JSFXObject pJSIcon = (JSFXObject)params[1];\r
-       if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE;\r
-\r
-       CJS_EmbedObj* pEmbedObj = ((CJS_Object*)params[1])->GetEmbedObject();\r
-       if (!pEmbedObj)return FALSE;\r
-       Icon* pIcon = (Icon*)pEmbedObj;\r
-\r
-       if (!m_pIconTree)\r
-               m_pIconTree = new IconTree();\r
-\r
-       IconElement* pNewIcon = new IconElement();\r
-       pNewIcon->IconName = swIconName;\r
-       pNewIcon->NextIcon = NULL;\r
-       pNewIcon->IconStream = pIcon;\r
-       m_pIconTree->InsertIconElement(pNewIcon);\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::icons(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsSetting())\r
-               return FALSE;\r
-\r
-       if (!m_pIconTree)\r
-       {\r
-               vp.SetNull();\r
-               return TRUE;\r
-       }\r
-\r
-       CJS_Array Icons(m_isolate);\r
-       IconElement* pIconElement = NULL;\r
-       int iIconTreeLength = m_pIconTree->GetLength();\r
-\r
-       CJS_Context* pContext = (CJS_Context *)cc;\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-\r
-       for (int i = 0; i < iIconTreeLength; i++)\r
-       {\r
-               pIconElement = (*m_pIconTree)[i];\r
-               \r
-               JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));\r
-               if (pObj.IsEmpty()) return FALSE;\r
-                               \r
-               CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);\r
-               if (!pJS_Icon) return FALSE;\r
-\r
-               Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();\r
-               if (!pIcon)return FALSE;\r
-\r
-               pIcon->SetStream(pIconElement->IconStream->GetStream());\r
-               pIcon->SetIconName(pIconElement->IconName);\r
-               Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));\r
-       }\r
-\r
-       vp << Icons;\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS)\r
-{\r
-       if (params.size() != 1)return FALSE;\r
-       if(!m_pIconTree)\r
-               return FALSE;\r
-       CFX_WideString swIconName = params[0].operator CFX_WideString();\r
-       int iIconCounts = m_pIconTree->GetLength();\r
-\r
-       CJS_Context* pContext = (CJS_Context *)cc;\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-\r
-       for (int i = 0; i < iIconCounts; i++)\r
-       {\r
-               if ((*m_pIconTree)[i]->IconName == swIconName)\r
-               {\r
-                       Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;\r
-                               \r
-                       JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));\r
-                       if (pObj.IsEmpty()) return FALSE;\r
-                                       \r
-                       CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);\r
-                       if (!pJS_Icon) return FALSE;\r
-\r
-                       Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();\r
-                       if (!pIcon)return FALSE;\r
-\r
-                       pIcon->SetIconName(swIconName);\r
-                       pIcon->SetStream(pRetIcon->GetStream());\r
-                       vRet = pJS_Icon;\r
-                       return TRUE;\r
-               }\r
-       }\r
-\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS)\r
-{\r
-       if (params.size() != 1)return FALSE;\r
-       if(!m_pIconTree)\r
-               return FALSE;\r
-       CFX_WideString swIconName = params[0].operator CFX_WideString();\r
-#ifndef FOXIT_CHROME_BUILD\r
-       m_pIconTree->DeleteIconElement(swIconName);\r
-#endif\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       CFX_WideString swName = L"";\r
-       CFX_ByteString sbName = "";\r
-       CFX_WideString swValue = L"";\r
-       CFX_WideString swMIMEType = L"";\r
-       CFX_WideString swCryptFilter = L"";\r
-       CFX_ByteString sbFileValue = "";\r
-       \r
-       int iParamSize = params.size();\r
-       for (int i = 0; i < iParamSize; i++)\r
-       {\r
-               if (i == 0)\r
-                       swName = params[0];\r
-               if (i == 1)\r
-                       swValue = params[1];\r
-               if (i == 2)\r
-                       swMIMEType = params[2];\r
-               if (i == 3)\r
-                       swCryptFilter = params[4];\r
-       }\r
-\r
-       FILE* pFile = NULL;\r
-\r
-       //CFileStatus fileStatus;\r
-       const int BUFSIZE = 17;\r
-       FX_BYTE buf[BUFSIZE];\r
-       FX_BYTE *pBuffer = NULL;\r
-       char* pBuf = NULL;\r
-       int nFileSize = 0;\r
-       sbFileValue = CFX_ByteString::FromUnicode(swValue);\r
-       sbName = CFX_ByteString::FromUnicode(swName);\r
-       int iBufLength = sbFileValue.GetLength();\r
-       pBuf = (char*)malloc(sizeof(char) * iBufLength);\r
-       pBuf = sbFileValue.GetBuffer(iBufLength);\r
-\r
-       if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) )\r
-       {\r
-               return FALSE;\r
-       }\r
-\r
-       fwrite( pBuf, sizeof(char), iBufLength, pFile );\r
-       fclose( pFile );\r
-       pFile = NULL;\r
-\r
-       pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" );\r
-       fseek( pFile, 0, SEEK_END );\r
-       nFileSize = ftell( pFile );\r
-\r
-       pBuffer = new FX_BYTE[nFileSize];\r
-       fseek( pFile, 0, SEEK_SET );\r
-       size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile );\r
-       if(s == 0)\r
-       {\r
-               delete[] pBuffer;\r
-               return FALSE;\r
-       }\r
-\r
-       CRYPT_MD5Generate(pBuffer, nFileSize, buf);\r
-       buf[BUFSIZE - 1] = 0;\r
-       CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16);\r
-       delete[] pBuffer;\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::media(OBJ_PROP_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||\r
-               m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;\r
-\r
-       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();\r
-       ASSERT(pInterForm != NULL);\r
-       pInterForm->OnCalculate();\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::Collab(OBJ_PROP_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)\r
-{\r
-       //if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;\r
-       int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;\r
-       bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;\r
-\r
-       CPDF_Document* pDocument = m_pDocument->GetDocument();\r
-       if (!pDocument) return FALSE;\r
-\r
-       if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())\r
-       {\r
-               //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);\r
-               return FALSE;\r
-       }\r
-\r
-       CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);\r
-       if (!pPageDict) return FALSE;\r
-\r
-       CPDF_Page page;\r
-       page.Load(pDocument, pPageDict);\r
-       page.StartParse();\r
-       page.ParseContent();\r
-\r
-       FX_POSITION pos = page.GetFirstObjectPosition();\r
-\r
-       int nWords = 0;\r
-\r
-       CFX_WideString swRet;\r
-\r
-       while (pos)\r
-       {\r
-               if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))\r
-               {\r
-                       if (pPageObj->m_Type == PDFPAGE_TEXT)\r
-                       {\r
-                               int nObjWords = CountWords((CPDF_TextObject*)pPageObj);\r
-\r
-                               if (nWords + nObjWords >= nWordNo)\r
-                               {\r
-                                       swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);\r
-                                       break;\r
-                               }\r
-\r
-                               nWords += nObjWords;\r
-                       }\r
-               }\r
-       }\r
-\r
-       if (bStrip)\r
-       {\r
-               swRet.TrimLeft();\r
-               swRet.TrimRight();\r
-       }\r
-\r
-       vRet = swRet;\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS)\r
-{\r
-       //if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)\r
-{\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;\r
-\r
-       int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;\r
-\r
-       CPDF_Document* pDocument = m_pDocument->GetDocument();\r
-       ASSERT(pDocument != NULL);\r
-\r
-       if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())\r
-       {\r
-               //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);\r
-               return FALSE;\r
-       }\r
-\r
-       CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);\r
-       if (!pPageDict) return FALSE;\r
-\r
-       CPDF_Page page;\r
-       page.Load(pDocument, pPageDict);\r
-       page.StartParse();\r
-       page.ParseContent();\r
-\r
-       FX_POSITION pos = page.GetFirstObjectPosition();\r
-\r
-       int nWords = 0;\r
-\r
-       while (pos)\r
-       {\r
-               if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))\r
-               {\r
-                       if (pPageObj->m_Type == PDFPAGE_TEXT)\r
-                       {\r
-                               CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;\r
-                               nWords += CountWords(pTextObj);\r
-                       }\r
-               }\r
-       }\r
-\r
-       vRet = nWords;\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getPrintParams(OBJ_METHOD_PARAMS)\r
-{\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-       JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));\r
-       //not implemented yet.\r
-       vRet = pRetObj;\r
-\r
-       return TRUE;\r
-}\r
-\r
-#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)\r
-\r
-int    Document::CountWords(CPDF_TextObject* pTextObj)\r
-{\r
-       if (!pTextObj) return 0;\r
-\r
-       int nWords = 0;\r
-\r
-       CPDF_Font* pFont = pTextObj->GetFont();\r
-       if (!pFont) return 0;\r
-\r
-       FX_BOOL bIsLatin = FALSE;\r
-\r
-       for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)\r
-       {\r
-               FX_DWORD charcode = -1;\r
-               FX_FLOAT kerning;\r
-\r
-               pTextObj->GetCharInfo(i, charcode, kerning);\r
-               CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);\r
-\r
-               FX_WORD unicode = 0;\r
-               if (swUnicode.GetLength() > 0)\r
-                       unicode = swUnicode[0];\r
-\r
-               if (ISLATINWORD(unicode) && bIsLatin)\r
-                       continue;\r
-               \r
-               bIsLatin = ISLATINWORD(unicode);\r
-               if (unicode != 0x20)\r
-                       nWords++;\r
-       }\r
-\r
-       return nWords;\r
-}\r
-\r
-CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)\r
-{\r
-       ASSERT(pTextObj != NULL);\r
-\r
-       CFX_WideString swRet;\r
-\r
-       CPDF_Font* pFont = pTextObj->GetFont();\r
-       if (!pFont) return L"";\r
-\r
-       int nWords = 0;\r
-       FX_BOOL bIsLatin = FALSE;\r
-\r
-       for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)\r
-       {\r
-               FX_DWORD charcode = -1;\r
-               FX_FLOAT kerning;\r
-\r
-               pTextObj->GetCharInfo(i, charcode, kerning);\r
-               CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);\r
-\r
-               FX_WORD unicode = 0;\r
-               if (swUnicode.GetLength() > 0)\r
-                       unicode = swUnicode[0];\r
-\r
-               if (ISLATINWORD(unicode) && bIsLatin)\r
-               {\r
-               }\r
-               else\r
-               {               \r
-                       bIsLatin = ISLATINWORD(unicode);\r
-                       if (unicode != 0x20)\r
-                               nWords++;       \r
-               }\r
-\r
-               if (nWords-1 == nWordIndex)\r
-                       swRet += unicode;\r
-       }\r
-\r
-       return swRet;\r
-}\r
-\r
-FX_BOOL Document::zoom(OBJ_PROP_PARAMS)\r
-{\r
-\r
-       return TRUE;\r
-}\r
-\r
-/**\r
-(none, NoVary)\r
-(fitP, FitPage)\r
-(fitW, FitWidth)\r
-(fitH, FitHeight)\r
-(fitV, FitVisibleWidth)\r
-(pref, Preferred)\r
-(refW, ReflowWidth)\r
-*/\r
-\r
-FX_BOOL Document::zoomType(OBJ_PROP_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS)\r
-{\r
-       \r
-\r
-       \r
-       \r
-\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-//     if (pEnv->GetAppName().Compare(PHANTOM) != 0)\r
-//             return TRUE;\r
-\r
-       //if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;\r
-\r
-       int iSize = params.size();\r
-       \r
-       int nStart = 0;\r
-       int nEnd = 0;\r
-       \r
-       if (iSize < 1)\r
-       {\r
-       }\r
-       else if (iSize == 1)\r
-       {\r
-               if (params[0].GetType() == VT_object)\r
-               {\r
-                       JSObject  pObj = (JSObject )params[0];\r
-                       v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
-                               nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
-                               nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-               }\r
-               else\r
-               {\r
-                       nStart = (int)params[0];\r
-               }\r
-       }\r
-       else\r
-       {\r
-               nStart = (int)params[0];\r
-               nEnd = (int)params[1];\r
-       }\r
-\r
-       int nTotal = m_pDocument->GetPageCount();\r
-\r
-       if (nStart < 0) nStart = 0;\r
-       if (nStart >= nTotal) nStart = nTotal - 1;\r
-\r
-       if (nEnd < 0) nEnd = 0;\r
-       if (nEnd >= nTotal) nEnd = nTotal - 1;\r
-\r
-       if (nEnd < nStart) nEnd = nStart;\r
-\r
-       \r
-\r
-#ifndef FOXIT_CHROME_BUILD\r
-       return m_pDocument->DeletePages(nStart, nEnd - nStart + 1);\r
-#else\r
-       return TRUE;\r
-#endif\r
-}\r
-\r
-FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS)\r
-{\r
-       \r
-\r
-       \r
-       \r
-       \r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE;\r
-\r
-       int iSize = params.size();\r
-       \r
-       int nTotal = m_pDocument->GetPageCount();\r
-       int nStart = 0;\r
-       int nEnd = nTotal - 1;\r
-\r
-       CFX_WideString swFilePath;\r
-       \r
-       if (iSize < 1)\r
-       {\r
-       }\r
-       else if (iSize == 1)\r
-       {\r
-               if (params[0].GetType() == VT_object)\r
-               {\r
-                       JSObject  pObj = (JSObject )params[0];\r
-                       v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
-                               nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
-                               nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"cPath");\r
-                               swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-               }\r
-               else\r
-               {\r
-                       nStart = (int)params[0];\r
-               }\r
-       }\r
-       else if (iSize == 2)\r
-       {\r
-               nStart = (int)params[0];\r
-               nEnd = (int)params[1];\r
-       }\r
-       else\r
-       {\r
-               nStart = (int)params[0];\r
-               nEnd = (int)params[1];\r
-               swFilePath = params[2].operator CFX_WideString();\r
-       }\r
-\r
-       if (nEnd < nStart)\r
-               nEnd = nStart;\r
-\r
-       CPDF_Document *pNewDoc = new CPDF_Document;\r
-       pNewDoc->CreateNewDoc();        \r
-\r
-       CFX_WordArray array;\r
-       for (int i=nStart; i<=nEnd; i++)\r
-               array.Add(i);\r
-\r
-//     m_pDocument->ExtractPages(array, pNewDoc);\r
-\r
-       if (swFilePath.IsEmpty())\r
-       {\r
-\r
-       }\r
-       else\r
-       {\r
-               swFilePath = app::PDFPathToSysPath(swFilePath);\r
-               CPDF_Creator PDFCreater(pNewDoc);\r
-               PDFCreater.Create(swFilePath);\r
-               delete pNewDoc;\r
-//             pEnv->OpenDocument(swFilePath);\r
-               vRet.SetNull();\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS)\r
-{\r
-\r
-\r
-       \r
-\r
-\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;\r
-\r
-       int iSize = params.size();\r
-       \r
-       int nStart = 0;\r
-       int nEnd = 0;\r
-       int nPage = 0;\r
-\r
-       CFX_WideString swFilePath;\r
-       \r
-       if (iSize < 1)\r
-       {\r
-       }\r
-       else if (iSize == 1)\r
-       {\r
-               if (params[0].GetType() == VT_object)\r
-               {\r
-                       JSObject  pObj = (JSObject )params[0];\r
-\r
-                       v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");\r
-                               nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"cPath");\r
-                               swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
-                               nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
-                               nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-               }\r
-               else\r
-               {\r
-                       nPage = (int)params[0];\r
-               }\r
-       }\r
-       else \r
-       {\r
-               nPage = (int)params[0];\r
-\r
-               if (iSize >= 2)\r
-                       swFilePath = params[1].operator CFX_WideString();\r
-\r
-               if (iSize >= 3)\r
-                       nStart = (int)params[2];\r
-\r
-               if (iSize >= 4)\r
-                       nEnd = (int)params[3];\r
-       }\r
-\r
-       nPage++;\r
-\r
-       if (nPage < 0)\r
-               nPage = 0;\r
-\r
-       if (nPage > m_pDocument->GetPageCount())\r
-               nPage = m_pDocument->GetPageCount();\r
-\r
-       if (swFilePath.IsEmpty()) return FALSE;\r
-\r
-       swFilePath = app::PDFPathToSysPath(swFilePath);\r
-\r
-       CPDF_Parser pdfParser;\r
-       pdfParser.StartParse(swFilePath, FALSE);\r
-       CPDF_Document* pSrcDoc = pdfParser.GetDocument();\r
-\r
-       if (!pSrcDoc) \r
-       {\r
-               pdfParser.CloseParser();\r
-               return FALSE;\r
-       }\r
-\r
-       int nTotal = pSrcDoc->GetPageCount();\r
-\r
-       if (nStart < 0) nStart = 0;\r
-       if (nStart >= nTotal) nStart = nTotal - 1;\r
-\r
-       if (nEnd < 0) nEnd = 0;\r
-       if (nEnd >= nTotal) nEnd = nTotal - 1;\r
-\r
-       if (nEnd < nStart) nEnd = nStart;\r
-\r
-       CFX_WordArray array;\r
-       for (int i=nStart; i<=nEnd; i++)\r
-               array.Add(i);\r
-\r
-//     m_pDocument->InsertPages(nPage, pSrcDoc, array);\r
-\r
-       pdfParser.CloseParser();\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS)\r
-{\r
-\r
-\r
-       \r
-\r
-\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       ASSERT(m_pDocument != NULL);\r
-\r
-       if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || \r
-               m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;\r
-\r
-       int iSize = params.size();\r
-       \r
-       int nStart = -1;\r
-       int nEnd = -1;\r
-       int nPage = 0;\r
-\r
-       CFX_WideString swFilePath;\r
-       \r
-       if (iSize < 1)\r
-       {\r
-       }\r
-       else if (iSize == 1)\r
-       {\r
-               if (params[0].GetType() == VT_object)\r
-               {\r
-                       JSObject  pObj = (JSObject )params[0];\r
-\r
-                       v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");\r
-                               nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"cPath");\r
-                               swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"nStart");\r
-                               nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-                       pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");\r
-                               nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));\r
-               }\r
-               else\r
-               {\r
-                       nPage = (int)params[0];\r
-               }\r
-       }\r
-       else \r
-       {\r
-               nPage = (int)params[0];\r
-\r
-               if (iSize >= 2)\r
-                       swFilePath = params[1].operator CFX_WideString();\r
-\r
-               if (iSize >= 3)\r
-                       nStart = (int)params[2];\r
-\r
-               if (iSize >= 4)\r
-                       nEnd = (int)params[3];\r
-       }\r
-\r
-       if (nPage < 0)\r
-               nPage = 0;\r
-\r
-       if (nPage >= m_pDocument->GetPageCount())\r
-               nPage = m_pDocument->GetPageCount() - 1;\r
-\r
-       if (swFilePath.IsEmpty()) return FALSE;\r
-\r
-       swFilePath = app::PDFPathToSysPath(swFilePath);\r
-\r
-       CPDF_Parser pdfParser;\r
-       pdfParser.StartParse(swFilePath, FALSE);\r
-       CPDF_Document* pSrcDoc = pdfParser.GetDocument();\r
-\r
-       if (!pSrcDoc) \r
-       {\r
-               pdfParser.CloseParser();\r
-               return FALSE;\r
-       }\r
-\r
-       int nTotal = pSrcDoc->GetPageCount();\r
-\r
-       if (nStart < 0)\r
-       {\r
-               if (nEnd < 0)\r
-               {\r
-                       nStart = 0;\r
-                       nEnd = nTotal - 1;\r
-               }\r
-               else\r
-               {\r
-                       nStart = 0;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               if (nEnd < 0)\r
-               {\r
-                       nEnd = nStart;\r
-               }\r
-               else\r
-               {\r
-                       if (nStart >= nTotal) nStart = nTotal - 1;\r
-                       if (nEnd >= nTotal) nEnd = nTotal - 1;\r
-\r
-                       if (nEnd < nStart) nEnd = nStart;\r
-               }\r
-       }\r
-\r
-       CFX_WordArray array;\r
-       for (int i=nStart; i<=nEnd; i++)\r
-               array.Add(i);\r
-\r
-//     m_pDocument->ReplacePages(nPage, pSrcDoc, array);\r
-\r
-       pdfParser.CloseParser();\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL Document::getURL(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       return TRUE;\r
-}\r
-\r
-void Document::AddDelayData(CJS_DelayData* pData)\r
-{\r
-       m_DelayData.Add(pData);\r
-}\r
-\r
-void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)\r
-{\r
-       CFX_DWordArray DelArray;\r
-\r
-       for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)\r
-       {\r
-               if (CJS_DelayData* pData = m_DelayData.GetAt(i))\r
-               {\r
-                       if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)\r
-                       {\r
-                               Field::DoDelay(m_pDocument, pData);\r
-                               delete pData;\r
-                               m_DelayData.SetAt(i, NULL);\r
-                               DelArray.Add(i);\r
-                       }\r
-               }\r
-       }\r
-\r
-       for (int j=DelArray.GetSize()-1; j>=0; j--)\r
-       {\r
-               m_DelayData.RemoveAt(DelArray[j]);\r
-       }\r
-}\r
-\r
-void Document::AddDelayAnnotData(CJS_AnnotObj *pData)\r
-{\r
-       m_DelayAnnotData.Add(pData);\r
-}\r
-\r
-void Document::DoAnnotDelay()\r
-{\r
-       CFX_DWordArray DelArray;\r
-       \r
-       for (int j=DelArray.GetSize()-1; j>=0; j--)\r
-       {\r
-               m_DelayData.RemoveAt(DelArray[j]);\r
-       }\r
-}\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "Document.h"
+
+#include "../../../third_party/base/numerics/safe_math.h"
+#include "../../include/fsdk_mgr.h"  // For CPDFDoc_Environment.
+#include "../../include/javascript/IJavaScript.h"
+#include "Field.h"
+#include "Icon.h"
+#include "JS_Context.h"
+#include "JS_Define.h"
+#include "JS_EventHandler.h"
+#include "JS_Object.h"
+#include "JS_Runtime.h"
+#include "JS_Value.h"
+#include "app.h"
+#include "resource.h"
+
+static v8::Isolate* GetIsolate(IJS_Context* cc) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  ASSERT(pContext != NULL);
+
+  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  ASSERT(pRuntime != NULL);
+
+  return pRuntime->GetIsolate();
+}
+
+BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
+
+PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
+    : CJS_EmbedObj(pJSObject) {
+  bUI = TRUE;
+  nStart = 0;
+  nEnd = 0;
+  bSilent = FALSE;
+  bShrinkToFit = FALSE;
+  bPrintAsImage = FALSE;
+  bReverse = FALSE;
+  bAnnotations = TRUE;
+}
+
+/* ---------------------- Document ---------------------- */
+
+#define MINWIDTH 5.0f
+#define MINHEIGHT 5.0f
+
+BEGIN_JS_STATIC_CONST(CJS_Document)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Document)
+JS_STATIC_PROP_ENTRY(ADBE)
+JS_STATIC_PROP_ENTRY(author)
+JS_STATIC_PROP_ENTRY(baseURL)
+JS_STATIC_PROP_ENTRY(bookmarkRoot)
+JS_STATIC_PROP_ENTRY(calculate)
+JS_STATIC_PROP_ENTRY(Collab)
+JS_STATIC_PROP_ENTRY(creationDate)
+JS_STATIC_PROP_ENTRY(creator)
+JS_STATIC_PROP_ENTRY(delay)
+JS_STATIC_PROP_ENTRY(dirty)
+JS_STATIC_PROP_ENTRY(documentFileName)
+JS_STATIC_PROP_ENTRY(external)
+JS_STATIC_PROP_ENTRY(filesize)
+JS_STATIC_PROP_ENTRY(icons)
+JS_STATIC_PROP_ENTRY(info)
+JS_STATIC_PROP_ENTRY(keywords)
+JS_STATIC_PROP_ENTRY(layout)
+JS_STATIC_PROP_ENTRY(media)
+JS_STATIC_PROP_ENTRY(modDate)
+JS_STATIC_PROP_ENTRY(mouseX)
+JS_STATIC_PROP_ENTRY(mouseY)
+JS_STATIC_PROP_ENTRY(numFields)
+JS_STATIC_PROP_ENTRY(numPages)
+JS_STATIC_PROP_ENTRY(pageNum)
+JS_STATIC_PROP_ENTRY(pageWindowRect)
+JS_STATIC_PROP_ENTRY(path)
+JS_STATIC_PROP_ENTRY(producer)
+JS_STATIC_PROP_ENTRY(subject)
+JS_STATIC_PROP_ENTRY(title)
+JS_STATIC_PROP_ENTRY(zoom)
+JS_STATIC_PROP_ENTRY(zoomType)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Document)
+JS_STATIC_METHOD_ENTRY(addAnnot)
+JS_STATIC_METHOD_ENTRY(addField)
+JS_STATIC_METHOD_ENTRY(addLink)
+JS_STATIC_METHOD_ENTRY(addIcon)
+JS_STATIC_METHOD_ENTRY(calculateNow)
+JS_STATIC_METHOD_ENTRY(closeDoc)
+JS_STATIC_METHOD_ENTRY(createDataObject)
+JS_STATIC_METHOD_ENTRY(deletePages)
+JS_STATIC_METHOD_ENTRY(exportAsText)
+JS_STATIC_METHOD_ENTRY(exportAsFDF)
+JS_STATIC_METHOD_ENTRY(exportAsXFDF)
+JS_STATIC_METHOD_ENTRY(extractPages)
+JS_STATIC_METHOD_ENTRY(getAnnot)
+JS_STATIC_METHOD_ENTRY(getAnnots)
+JS_STATIC_METHOD_ENTRY(getAnnot3D)
+JS_STATIC_METHOD_ENTRY(getAnnots3D)
+JS_STATIC_METHOD_ENTRY(getField)
+JS_STATIC_METHOD_ENTRY(getIcon)
+JS_STATIC_METHOD_ENTRY(getLinks)
+JS_STATIC_METHOD_ENTRY(getNthFieldName)
+JS_STATIC_METHOD_ENTRY(getOCGs)
+JS_STATIC_METHOD_ENTRY(getPageBox)
+JS_STATIC_METHOD_ENTRY(getPageNthWord)
+JS_STATIC_METHOD_ENTRY(getPageNthWordQuads)
+JS_STATIC_METHOD_ENTRY(getPageNumWords)
+JS_STATIC_METHOD_ENTRY(getPrintParams)
+JS_STATIC_METHOD_ENTRY(getURL)
+JS_STATIC_METHOD_ENTRY(importAnFDF)
+JS_STATIC_METHOD_ENTRY(importAnXFDF)
+JS_STATIC_METHOD_ENTRY(importTextData)
+JS_STATIC_METHOD_ENTRY(insertPages)
+JS_STATIC_METHOD_ENTRY(mailForm)
+JS_STATIC_METHOD_ENTRY(print)
+JS_STATIC_METHOD_ENTRY(removeField)
+JS_STATIC_METHOD_ENTRY(replacePages)
+JS_STATIC_METHOD_ENTRY(resetForm)
+JS_STATIC_METHOD_ENTRY(removeIcon)
+JS_STATIC_METHOD_ENTRY(saveAs)
+JS_STATIC_METHOD_ENTRY(submitForm)
+JS_STATIC_METHOD_ENTRY(mailDoc)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Document, Document)
+
+void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) {
+  CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
+  Document* pDoc = static_cast<Document*>(GetEmbedObject());
+  pDoc->AttachDoc(pRuntime->GetReaderDocument());
+  pDoc->SetIsolate(pRuntime->GetIsolate());
+}
+
+/* --------------------------------- Document ---------------------------------
+ */
+
+Document::Document(CJS_Object* pJSObject)
+    : CJS_EmbedObj(pJSObject),
+      m_isolate(NULL),
+      m_pIconTree(NULL),
+      m_pDocument(NULL),
+      m_cwBaseURL(L""),
+      m_bDelay(FALSE) {}
+
+Document::~Document() {
+  if (m_pIconTree) {
+    m_pIconTree->DeleteIconTree();
+    delete m_pIconTree;
+    m_pIconTree = NULL;
+  }
+  for (int i = 0; i < m_DelayData.GetSize(); i++) {
+    if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
+      delete pData;
+      pData = NULL;
+      m_DelayData.SetAt(i, NULL);
+    }
+  }
+
+  m_DelayData.RemoveAll();
+  m_DelayAnnotData.RemoveAll();
+}
+
+// the total number of fileds in document.
+FX_BOOL Document::numFields(IJS_Context* cc,
+                            CJS_PropValue& vp,
+                            CFX_WideString& sError) {
+  if (vp.IsSetting()) {
+    CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+    return FALSE;
+  }
+  CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+  CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+  vp << (int)pPDFForm->CountFields();
+  return TRUE;
+}
+
+FX_BOOL Document::dirty(IJS_Context* cc,
+                        CJS_PropValue& vp,
+                        CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (vp.IsGetting()) {
+    if (m_pDocument->GetChangeMark())
+      vp << true;
+    else
+      vp << false;
+  } else {
+    bool bChanged = false;
+
+    vp >> bChanged;
+
+    if (bChanged)
+      m_pDocument->SetChangeMark();
+    else
+      m_pDocument->ClearChangeMark();
+  }
+
+  return TRUE;
+}
+
+FX_BOOL Document::ADBE(IJS_Context* cc,
+                       CJS_PropValue& vp,
+                       CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (vp.IsGetting()) {
+    vp.SetNull();
+  } else {
+  }
+
+  return TRUE;
+}
+
+FX_BOOL Document::pageNum(IJS_Context* cc,
+                          CJS_PropValue& vp,
+                          CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (vp.IsGetting()) {
+    if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) {
+      vp << pPageView->GetPageIndex();
+    }
+  } else {
+    int iPageCount = m_pDocument->GetPageCount();
+    int iPageNum = 0;
+    vp >> iPageNum;
+
+    CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+    if (iPageNum >= 0 && iPageNum < iPageCount) {
+      pEnv->JS_docgotoPage(iPageNum);
+    } else if (iPageNum >= iPageCount) {
+      pEnv->JS_docgotoPage(iPageCount - 1);
+    } else if (iPageNum < 0) {
+      pEnv->JS_docgotoPage(0);
+    }
+  }
+
+  return TRUE;
+}
+
+FX_BOOL Document::addAnnot(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  // Not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::addField(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  // Not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::exportAsText(IJS_Context* cc,
+                               const CJS_Parameters& params,
+                               CJS_Value& vRet,
+                               CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::exportAsFDF(IJS_Context* cc,
+                              const CJS_Parameters& params,
+                              CJS_Value& vRet,
+                              CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::exportAsXFDF(IJS_Context* cc,
+                               const CJS_Parameters& params,
+                               CJS_Value& vRet,
+                               CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+// Maps a field object in PDF document to a JavaScript variable
+// comment:
+// note: the paremter cName, this is clue how to treat if the cName is not a
+// valiable filed name in this document
+
+FX_BOOL Document::getField(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  if (params.size() < 1) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+    return FALSE;
+  }
+
+  CFX_WideString wideName = params[0].ToCFXWideString();
+
+  CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+  CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+  if (pPDFForm->CountFields(wideName) <= 0) {
+    vRet.SetNull();
+    return TRUE;
+  }
+
+  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
+
+  v8::Isolate* isolate = GetIsolate(cc);
+  CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
+  Field* pField = (Field*)pJSField->GetEmbedObject();
+  pField->AttachField(this, wideName);
+
+  vRet = pJSField;
+  return TRUE;
+}
+
+// Gets the name of the nth field in the document
+FX_BOOL Document::getNthFieldName(IJS_Context* cc,
+                                  const CJS_Parameters& params,
+                                  CJS_Value& vRet,
+                                  CFX_WideString& sError) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  if (params.size() != 1) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+    return FALSE;
+  }
+
+  int nIndex = params[0].ToInt();
+  if (nIndex < 0) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+    return FALSE;
+  }
+
+  CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+  CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+  CPDF_FormField* pField = pPDFForm->GetField(nIndex);
+  if (!pField)
+    return FALSE;
+
+  vRet = pField->GetFullName().c_str();
+  return TRUE;
+}
+
+FX_BOOL Document::importAnFDF(IJS_Context* cc,
+                              const CJS_Parameters& params,
+                              CJS_Value& vRet,
+                              CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::importAnXFDF(IJS_Context* cc,
+                               const CJS_Parameters& params,
+                               CJS_Value& vRet,
+                               CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::importTextData(IJS_Context* cc,
+                                 const CJS_Parameters& params,
+                                 CJS_Value& vRet,
+                                 CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+// exports the form data and mails the resulting fdf file as an attachment to
+// all recipients.
+// comment: need reader supports
+// note:
+// int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string
+// cbcc,string cSubject,string cms);
+
+FX_BOOL Document::mailForm(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
+    return FALSE;
+
+  int iLength = params.size();
+
+  FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE;
+  CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L"";
+  CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L"";
+  CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L"";
+  CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L"";
+  CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L"";
+
+  CPDFSDK_InterForm* pInterForm =
+      (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+  ASSERT(pInterForm != NULL);
+
+  CFX_ByteTextBuf textBuf;
+  if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
+    return FALSE;
+
+  CJS_Context* pContext = (CJS_Context*)cc;
+  ASSERT(pContext != NULL);
+  CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
+  ASSERT(pEnv != NULL);
+  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  ASSERT(pRuntime != NULL);
+
+  pRuntime->BeginBlock();
+  pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI,
+                       cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(),
+                       cMsg.c_str());
+  pRuntime->EndBlock();
+  return TRUE;
+}
+
+FX_BOOL Document::print(IJS_Context* cc,
+                        const CJS_Parameters& params,
+                        CJS_Value& vRet,
+                        CFX_WideString& sError) {
+  FX_BOOL bUI = TRUE;
+  int nStart = 0;
+  int nEnd = 0;
+  FX_BOOL bSilent = FALSE;
+  FX_BOOL bShrinkToFit = FALSE;
+  FX_BOOL bPrintAsImage = FALSE;
+  FX_BOOL bReverse = FALSE;
+  FX_BOOL bAnnotations = FALSE;
+
+  int nlength = params.size();
+  if (nlength == 9) {
+    if (params[8].GetType() == CJS_Value::VT_fxobject) {
+      v8::Local<v8::Object> pObj = params[8].ToV8Object();
+      {
+        if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) {
+          if (CJS_Object* pJSObj = params[8].ToCJSObject()) {
+            if (PrintParamsObj* pprintparamsObj =
+                    (PrintParamsObj*)pJSObj->GetEmbedObject()) {
+              bUI = pprintparamsObj->bUI;
+              nStart = pprintparamsObj->nStart;
+              nEnd = pprintparamsObj->nEnd;
+              bSilent = pprintparamsObj->bSilent;
+              bShrinkToFit = pprintparamsObj->bShrinkToFit;
+              bPrintAsImage = pprintparamsObj->bPrintAsImage;
+              bReverse = pprintparamsObj->bReverse;
+              bAnnotations = pprintparamsObj->bAnnotations;
+            }
+          }
+        }
+      }
+    }
+  } else {
+    if (nlength >= 1)
+      bUI = params[0].ToBool();
+    if (nlength >= 2)
+      nStart = params[1].ToInt();
+    if (nlength >= 3)
+      nEnd = params[2].ToInt();
+    if (nlength >= 4)
+      bSilent = params[3].ToBool();
+    if (nlength >= 5)
+      bShrinkToFit = params[4].ToBool();
+    if (nlength >= 6)
+      bPrintAsImage = params[5].ToBool();
+    if (nlength >= 7)
+      bReverse = params[6].ToBool();
+    if (nlength >= 8)
+      bAnnotations = params[7].ToBool();
+  }
+
+  ASSERT(m_pDocument != NULL);
+
+  if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) {
+    pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage,
+                      bReverse, bAnnotations);
+    return TRUE;
+  }
+  return FALSE;
+}
+
+// removes the specified field from the document.
+// comment:
+// note: if the filed name is not retional, adobe is dumb for it.
+
+FX_BOOL Document::removeField(IJS_Context* cc,
+                              const CJS_Parameters& params,
+                              CJS_Value& vRet,
+                              CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+        m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM)))
+    return FALSE;
+
+  CJS_Context* pContext = (CJS_Context*)cc;
+  if (params.size() != 1) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+    return FALSE;
+  }
+
+  CFX_WideString sFieldName = params[0].ToCFXWideString();
+  CPDFSDK_InterForm* pInterForm =
+      (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+  ASSERT(pInterForm != NULL);
+
+  CFX_PtrArray widgets;
+  pInterForm->GetWidgets(sFieldName, widgets);
+
+  int nSize = widgets.GetSize();
+
+  if (nSize > 0) {
+    for (int i = 0; i < nSize; i++) {
+      CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];
+      ASSERT(pWidget != NULL);
+
+      CPDF_Rect rcAnnot = pWidget->GetRect();
+      rcAnnot.left -= 1;
+      rcAnnot.bottom -= 1;
+      rcAnnot.right += 1;
+      rcAnnot.top += 1;
+
+      CFX_RectArray aRefresh;
+      aRefresh.Add(rcAnnot);
+
+      CPDF_Page* pPage = pWidget->GetPDFPage();
+      ASSERT(pPage != NULL);
+
+      CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
+      pPageView->DeleteAnnot(pWidget);
+
+      pPageView->UpdateRects(aRefresh);
+    }
+    m_pDocument->SetChangeMark();
+  }
+
+  return TRUE;
+}
+
+// reset filed values within a document.
+// comment:
+// note: if the fields names r not rational, aodbe is dumb for it.
+
+FX_BOOL Document::resetForm(IJS_Context* cc,
+                            const CJS_Parameters& params,
+                            CJS_Value& vRet,
+                            CFX_WideString& sError) {
+  if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+        m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+        m_pDocument->GetPermissions(FPDFPERM_FILL_FORM)))
+    return FALSE;
+
+  CPDFSDK_InterForm* pInterForm =
+      (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+  CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Array aName(pRuntime);
+
+  if (params.size() > 0) {
+    switch (params[0].GetType()) {
+      default:
+        aName.Attach(params[0].ToV8Array());
+        break;
+      case CJS_Value::VT_string:
+        aName.SetElement(0, params[0]);
+        break;
+    }
+
+    CFX_PtrArray aFields;
+
+    for (int i = 0, isz = aName.GetLength(); i < isz; i++) {
+      CJS_Value valElement(pRuntime);
+      aName.GetElement(i, valElement);
+      CFX_WideString swVal = valElement.ToCFXWideString();
+      for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; j++) {
+        aFields.Add((void*)pPDFForm->GetField(j, swVal));
+      }
+    }
+
+    if (aFields.GetSize() > 0) {
+      pPDFForm->ResetForm(aFields, TRUE, TRUE);
+      m_pDocument->SetChangeMark();
+    }
+  } else {
+    pPDFForm->ResetForm(TRUE);
+    m_pDocument->SetChangeMark();
+  }
+
+  return TRUE;
+}
+
+FX_BOOL Document::saveAs(IJS_Context* cc,
+                         const CJS_Parameters& params,
+                         CJS_Value& vRet,
+                         CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::submitForm(IJS_Context* cc,
+                             const CJS_Parameters& params,
+                             CJS_Value& vRet,
+                             CFX_WideString& sError) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  int nSize = params.size();
+  if (nSize < 1) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+    return FALSE;
+  }
+
+  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  v8::Isolate* isolate = pRuntime->GetIsolate();
+  CJS_Array aFields(pRuntime);
+  CFX_WideString strURL;
+  FX_BOOL bFDF = TRUE;
+  FX_BOOL bEmpty = FALSE;
+
+  CJS_Value v = params[0];
+  if (v.GetType() == CJS_Value::VT_string) {
+    strURL = params[0].ToCFXWideString();
+    if (nSize > 1)
+      bFDF = params[1].ToBool();
+    if (nSize > 2)
+      bEmpty = params[2].ToBool();
+    if (nSize > 3)
+      aFields.Attach(params[3].ToV8Array());
+  } else if (v.GetType() == CJS_Value::VT_object) {
+    v8::Local<v8::Object> pObj = params[0].ToV8Object();
+    v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL");
+    if (!pValue.IsEmpty())
+      strURL =
+          CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF");
+    bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty");
+    bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields");
+    aFields.Attach(
+        CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array());
+  }
+
+  CPDFSDK_InterForm* pInterForm =
+      (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+  CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+  FX_BOOL bAll = (aFields.GetLength() == 0);
+  if (bAll && bEmpty) {
+    if (pPDFInterForm->CheckRequiredFields()) {
+      pRuntime->BeginBlock();
+      pInterForm->SubmitForm(strURL, FALSE);
+      pRuntime->EndBlock();
+    }
+    return TRUE;
+  }
+
+  CFX_PtrArray fieldObjects;
+  for (int i = 0, sz = aFields.GetLength(); i < sz; i++) {
+    CJS_Value valName(pRuntime);
+    aFields.GetElement(i, valName);
+
+    CFX_WideString sName = valName.ToCFXWideString();
+    CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+    for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) {
+      CPDF_FormField* pField = pPDFForm->GetField(j, sName);
+      if (!bEmpty && pField->GetValue().IsEmpty())
+        continue;
+
+      fieldObjects.Add(pField);
+    }
+  }
+
+  if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) {
+    pRuntime->BeginBlock();
+    pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
+    pRuntime->EndBlock();
+  }
+  return TRUE;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+void Document::AttachDoc(CPDFSDK_Document* pDoc) {
+  m_pDocument = pDoc;
+}
+
+CPDFSDK_Document* Document::GetReaderDoc() {
+  return m_pDocument;
+}
+
+FX_BOOL Document::ExtractFileName(CPDFSDK_Document* pDoc,
+                                  CFX_ByteString& strFileName) {
+  return FALSE;
+}
+
+FX_BOOL Document::ExtractFolderName(CPDFSDK_Document* pDoc,
+                                    CFX_ByteString& strFolderName) {
+  return FALSE;
+}
+
+FX_BOOL Document::bookmarkRoot(IJS_Context* cc,
+                               CJS_PropValue& vp,
+                               CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::mailDoc(IJS_Context* cc,
+                          const CJS_Parameters& params,
+                          CJS_Value& vRet,
+                          CFX_WideString& sError) {
+  FX_BOOL bUI = TRUE;
+  CFX_WideString cTo = L"";
+  CFX_WideString cCc = L"";
+  CFX_WideString cBcc = L"";
+  CFX_WideString cSubject = L"";
+  CFX_WideString cMsg = L"";
+
+  if (params.size() >= 1)
+    bUI = params[0].ToBool();
+  if (params.size() >= 2)
+    cTo = params[1].ToCFXWideString();
+  if (params.size() >= 3)
+    cCc = params[2].ToCFXWideString();
+  if (params.size() >= 4)
+    cBcc = params[3].ToCFXWideString();
+  if (params.size() >= 5)
+    cSubject = params[4].ToCFXWideString();
+  if (params.size() >= 6)
+    cMsg = params[5].ToCFXWideString();
+
+  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  v8::Isolate* isolate = pRuntime->GetIsolate();
+
+  if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) {
+    v8::Local<v8::Object> pObj = params[0].ToV8Object();
+
+    v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
+    bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
+    cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
+    cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
+    cBcc =
+        CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
+    cSubject =
+        CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+    pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
+    cMsg =
+        CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+  }
+
+  pRuntime->BeginBlock();
+  CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
+  pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(),
+                       cBcc.c_str(), cMsg.c_str());
+  pRuntime->EndBlock();
+
+  return TRUE;
+}
+
+FX_BOOL Document::author(IJS_Context* cc,
+                         CJS_PropValue& vp,
+                         CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("Author");
+    return TRUE;
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString csAuthor;
+    vp >> csAuthor;
+    pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
+    m_pDocument->SetChangeMark();
+    return TRUE;
+  }
+}
+
+FX_BOOL Document::info(IJS_Context* cc,
+                       CJS_PropValue& vp,
+                       CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
+  CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title");
+  CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject");
+  CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords");
+  CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator");
+  CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
+  CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
+  CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
+  CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
+
+  v8::Isolate* isolate = GetIsolate(cc);
+  if (vp.IsGetting()) {
+    CJS_Context* pContext = (CJS_Context*)cc;
+    CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+    v8::Local<v8::Object> pObj =
+        FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1);
+    FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"CreationDate",
+                         cwCreationDate.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
+    FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
+
+    // It's to be compatible to non-standard info dictionary.
+    FX_POSITION pos = pDictionary->GetStartPos();
+    while (pos) {
+      CFX_ByteString bsKey;
+      CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
+      CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
+
+      if (pValueObj->IsString() || pValueObj->IsName()) {
+        FXJS_PutObjectString(isolate, pObj, wsKey.c_str(),
+                             pValueObj->GetUnicodeText().c_str());
+      } else if (pValueObj->IsNumber()) {
+        FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(),
+                             (float)pValueObj->GetNumber());
+      } else if (pValueObj->IsBoolean()) {
+        FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(),
+                              (bool)pValueObj->GetInteger());
+      }
+    }
+    vp << pObj;
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::creationDate(IJS_Context* cc,
+                               CJS_PropValue& vp,
+                               CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("CreationDate");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString csCreationDate;
+    vp >> csCreationDate;
+    pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::creator(IJS_Context* cc,
+                          CJS_PropValue& vp,
+                          CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("Creator");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString csCreator;
+    vp >> csCreator;
+    pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::delay(IJS_Context* cc,
+                        CJS_PropValue& vp,
+                        CFX_WideString& sError) {
+  if (vp.IsGetting()) {
+    vp << m_bDelay;
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    vp >> m_bDelay;
+    if (m_bDelay) {
+      for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++)
+        delete m_DelayData.GetAt(i);
+
+      m_DelayData.RemoveAll();
+    } else {
+      CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess;
+      for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) {
+        if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
+          DelayDataToProcess.Add(pData);
+          m_DelayData.SetAt(i, NULL);
+        }
+      }
+      m_DelayData.RemoveAll();
+      for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) {
+        CJS_DelayData* pData = DelayDataToProcess.GetAt(i);
+        Field::DoDelay(m_pDocument, pData);
+        DelayDataToProcess.SetAt(i, NULL);
+        delete pData;
+      }
+    }
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::keywords(IJS_Context* cc,
+                           CJS_PropValue& vp,
+                           CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("Keywords");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString csKeywords;
+    vp >> csKeywords;
+    pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::modDate(IJS_Context* cc,
+                          CJS_PropValue& vp,
+                          CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("ModDate");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString csmodDate;
+    vp >> csmodDate;
+    pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::producer(IJS_Context* cc,
+                           CJS_PropValue& vp,
+                           CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("Producer");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString csproducer;
+    vp >> csproducer;
+    pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::subject(IJS_Context* cc,
+                          CJS_PropValue& vp,
+                          CFX_WideString& sError) {
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("Subject");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString cssubject;
+    vp >> cssubject;
+    pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::title(IJS_Context* cc,
+                        CJS_PropValue& vp,
+                        CFX_WideString& sError) {
+  if (m_pDocument == NULL || m_pDocument->GetPDFDocument() == NULL)
+    return FALSE;
+
+  CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo();
+  if (!pDictionary)
+    return FALSE;
+
+  if (vp.IsGetting()) {
+    vp << pDictionary->GetUnicodeText("Title");
+  } else {
+    if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY))
+      return FALSE;
+
+    CFX_WideString cstitle;
+    vp >> cstitle;
+    pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
+    m_pDocument->SetChangeMark();
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::numPages(IJS_Context* cc,
+                           CJS_PropValue& vp,
+                           CFX_WideString& sError) {
+  if (vp.IsSetting()) {
+    CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+    return FALSE;
+  }
+  vp << m_pDocument->GetPageCount();
+  return TRUE;
+}
+
+FX_BOOL Document::external(IJS_Context* cc,
+                           CJS_PropValue& vp,
+                           CFX_WideString& sError) {
+  // In Chrome case,should always return true.
+  if (vp.IsGetting()) {
+    vp << true;
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::filesize(IJS_Context* cc,
+                           CJS_PropValue& vp,
+                           CFX_WideString& sError) {
+  if (vp.IsSetting()) {
+    CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+    return FALSE;
+  }
+  vp << 0;
+  return TRUE;
+}
+
+FX_BOOL Document::mouseX(IJS_Context* cc,
+                         CJS_PropValue& vp,
+                         CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::mouseY(IJS_Context* cc,
+                         CJS_PropValue& vp,
+                         CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::baseURL(IJS_Context* cc,
+                          CJS_PropValue& vp,
+                          CFX_WideString& sError) {
+  if (vp.IsGetting()) {
+    vp << m_cwBaseURL;
+  } else {
+    vp >> m_cwBaseURL;
+  }
+  return TRUE;
+}
+
+FX_BOOL Document::calculate(IJS_Context* cc,
+                            CJS_PropValue& vp,
+                            CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  CPDFSDK_InterForm* pInterForm =
+      (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+  ASSERT(pInterForm != NULL);
+
+  if (vp.IsGetting()) {
+    if (pInterForm->IsCalculateEnabled())
+      vp << true;
+    else
+      vp << false;
+  } else {
+    bool bCalculate;
+    vp >> bCalculate;
+
+    pInterForm->EnableCalculate(bCalculate);
+  }
+
+  return TRUE;
+}
+
+FX_BOOL Document::documentFileName(IJS_Context* cc,
+                                   CJS_PropValue& vp,
+                                   CFX_WideString& sError) {
+  if (vp.IsSetting()) {
+    CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+    return FALSE;
+  }
+  CFX_WideString wsFilePath = m_pDocument->GetPath();
+  int32_t i = wsFilePath.GetLength() - 1;
+  for (; i >= 0; i--) {
+    if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/')
+      break;
+  }
+  if (i >= 0 && i < wsFilePath.GetLength() - 1) {
+    vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1);
+  } else {
+    vp << L"";
+  }
+  return TRUE;
+}
+
+CFX_WideString Document::ReversalStr(CFX_WideString cbFrom) {
+  size_t iLength = cbFrom.GetLength();
+  pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
+  iSize *= (iLength + 1);
+  wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
+  wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
+
+  for (size_t i = 0; i < iLength; i++) {
+    pResult[i] = *(pFrom + iLength - i - 1);
+  }
+  pResult[iLength] = L'\0';
+
+  cbFrom.ReleaseBuffer();
+  CFX_WideString cbRet = CFX_WideString(pResult);
+  free(pResult);
+  pResult = NULL;
+  return cbRet;
+}
+
+CFX_WideString Document::CutString(CFX_WideString cbFrom) {
+  size_t iLength = cbFrom.GetLength();
+  pdfium::base::CheckedNumeric<size_t> iSize = sizeof(wchar_t);
+  iSize *= (iLength + 1);
+  wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie());
+  wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength);
+
+  for (size_t i = 0; i < iLength; i++) {
+    if (pFrom[i] == L'\\' || pFrom[i] == L'/') {
+      pResult[i] = L'\0';
+      break;
+    }
+    pResult[i] = pFrom[i];
+  }
+  pResult[iLength] = L'\0';
+
+  cbFrom.ReleaseBuffer();
+  CFX_WideString cbRet = CFX_WideString(pResult);
+  free(pResult);
+  pResult = NULL;
+  return cbRet;
+}
+
+FX_BOOL Document::path(IJS_Context* cc,
+                       CJS_PropValue& vp,
+                       CFX_WideString& sError) {
+  if (vp.IsSetting()) {
+    CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+    return FALSE;
+  }
+  vp << app::SysPathToPDFPath(m_pDocument->GetPath());
+  return TRUE;
+}
+
+FX_BOOL Document::pageWindowRect(IJS_Context* cc,
+                                 CJS_PropValue& vp,
+                                 CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::layout(IJS_Context* cc,
+                         CJS_PropValue& vp,
+                         CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::addLink(IJS_Context* cc,
+                          const CJS_Parameters& params,
+                          CJS_Value& vRet,
+                          CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::closeDoc(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+  return TRUE;
+}
+
+FX_BOOL Document::getPageBox(IJS_Context* cc,
+                             const CJS_Parameters& params,
+                             CJS_Value& vRet,
+                             CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::getAnnot(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::getAnnots(IJS_Context* cc,
+                            const CJS_Parameters& params,
+                            CJS_Value& vRet,
+                            CFX_WideString& sError) {
+  vRet.SetNull();
+  return TRUE;
+}
+
+FX_BOOL Document::getAnnot3D(IJS_Context* cc,
+                             const CJS_Parameters& params,
+                             CJS_Value& vRet,
+                             CFX_WideString& sError) {
+  vRet.SetNull();
+  return TRUE;
+}
+
+FX_BOOL Document::getAnnots3D(IJS_Context* cc,
+                              const CJS_Parameters& params,
+                              CJS_Value& vRet,
+                              CFX_WideString& sError) {
+  vRet = CJS_Value::VT_undefined;
+  return TRUE;
+}
+
+FX_BOOL Document::getOCGs(IJS_Context* cc,
+                          const CJS_Parameters& params,
+                          CJS_Value& vRet,
+                          CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::getLinks(IJS_Context* cc,
+                           const CJS_Parameters& params,
+                           CJS_Value& vRet,
+                           CFX_WideString& sError) {
+  return TRUE;
+}
+
+bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) {
+  return (rect.left <= LinkRect.left && rect.top <= LinkRect.top &&
+          rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom);
+}
+
+void IconTree::InsertIconElement(IconElement* pNewIcon) {
+  if (!pNewIcon)
+    return;
+
+  if (m_pHead == NULL && m_pEnd == NULL) {
+    m_pHead = m_pEnd = pNewIcon;
+    m_iLength++;
+  } else {
+    m_pEnd->NextIcon = pNewIcon;
+    m_pEnd = pNewIcon;
+    m_iLength++;
+  }
+}
+
+void IconTree::DeleteIconTree() {
+  if (!m_pHead || !m_pEnd)
+    return;
+
+  IconElement* pTemp = NULL;
+  while (m_pEnd != m_pHead) {
+    pTemp = m_pHead;
+    m_pHead = m_pHead->NextIcon;
+    delete pTemp;
+  }
+
+  delete m_pEnd;
+  m_pHead = NULL;
+  m_pEnd = NULL;
+}
+
+int IconTree::GetLength() {
+  return m_iLength;
+}
+
+IconElement* IconTree::operator[](int iIndex) {
+  if (iIndex >= 0 && iIndex <= m_iLength) {
+    IconElement* pTemp = m_pHead;
+    for (int i = 0; i < iIndex; i++) {
+      pTemp = pTemp->NextIcon;
+    }
+    return pTemp;
+  }
+  return NULL;
+}
+
+FX_BOOL Document::addIcon(IJS_Context* cc,
+                          const CJS_Parameters& params,
+                          CJS_Value& vRet,
+                          CFX_WideString& sError) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  if (params.size() != 2) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+    return FALSE;
+  }
+  CFX_WideString swIconName = params[0].ToCFXWideString();
+
+  if (params[1].GetType() != CJS_Value::VT_object) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+    return FALSE;
+  }
+
+  v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
+  if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+    return FALSE;
+  }
+
+  CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
+  if (!pEmbedObj) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
+    return FALSE;
+  }
+
+  Icon* pIcon = (Icon*)pEmbedObj;
+  if (!m_pIconTree)
+    m_pIconTree = new IconTree();
+
+  IconElement* pNewIcon = new IconElement();
+  pNewIcon->IconName = swIconName;
+  pNewIcon->NextIcon = NULL;
+  pNewIcon->IconStream = pIcon;
+  m_pIconTree->InsertIconElement(pNewIcon);
+  return TRUE;
+}
+
+FX_BOOL Document::icons(IJS_Context* cc,
+                        CJS_PropValue& vp,
+                        CFX_WideString& sError) {
+  if (vp.IsSetting()) {
+    CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
+    return FALSE;
+  }
+
+  if (!m_pIconTree) {
+    vp.SetNull();
+    return TRUE;
+  }
+
+  CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+  CJS_Array Icons(pRuntime);
+  IconElement* pIconElement = NULL;
+  int iIconTreeLength = m_pIconTree->GetLength();
+  for (int i = 0; i < iIconTreeLength; i++) {
+    pIconElement = (*m_pIconTree)[i];
+
+    v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
+        pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
+    if (pObj.IsEmpty())
+      return FALSE;
+
+    CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
+    if (!pJS_Icon)
+      return FALSE;
+
+    Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+    if (!pIcon)
+      return FALSE;
+
+    pIcon->SetStream(pIconElement->IconStream->GetStream());
+    pIcon->SetIconName(pIconElement->IconName);
+    Icons.SetElement(i, CJS_Value(pRuntime, pJS_Icon));
+  }
+
+  vp << Icons;
+  return TRUE;
+}
+
+FX_BOOL Document::getIcon(IJS_Context* cc,
+                          const CJS_Parameters& params,
+                          CJS_Value& vRet,
+                          CFX_WideString& sError) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  if (params.size() != 1) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+    return FALSE;
+  }
+
+  if (!m_pIconTree)
+    return FALSE;
+  CFX_WideString swIconName = params[0].ToCFXWideString();
+  int iIconCounts = m_pIconTree->GetLength();
+
+  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+  for (int i = 0; i < iIconCounts; i++) {
+    if ((*m_pIconTree)[i]->IconName == swIconName) {
+      Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
+
+      v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
+          pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
+      if (pObj.IsEmpty())
+        return FALSE;
+
+      CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
+      if (!pJS_Icon)
+        return FALSE;
+
+      Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+      if (!pIcon)
+        return FALSE;
+
+      pIcon->SetIconName(swIconName);
+      pIcon->SetStream(pRetIcon->GetStream());
+      vRet = pJS_Icon;
+      return TRUE;
+    }
+  }
+
+  return FALSE;
+}
+
+FX_BOOL Document::removeIcon(IJS_Context* cc,
+                             const CJS_Parameters& params,
+                             CJS_Value& vRet,
+                             CFX_WideString& sError) {
+  // Unsafe, no supported.
+  return TRUE;
+}
+
+FX_BOOL Document::createDataObject(IJS_Context* cc,
+                                   const CJS_Parameters& params,
+                                   CJS_Value& vRet,
+                                   CFX_WideString& sError) {
+  // Unsafe, not implemented.
+  return TRUE;
+}
+
+FX_BOOL Document::media(IJS_Context* cc,
+                        CJS_PropValue& vp,
+                        CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::calculateNow(IJS_Context* cc,
+                               const CJS_Parameters& params,
+                               CJS_Value& vRet,
+                               CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+        m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+        m_pDocument->GetPermissions(FPDFPERM_FILL_FORM)))
+    return FALSE;
+
+  CPDFSDK_InterForm* pInterForm =
+      (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+  ASSERT(pInterForm != NULL);
+  pInterForm->OnCalculate();
+  return TRUE;
+}
+
+FX_BOOL Document::Collab(IJS_Context* cc,
+                         CJS_PropValue& vp,
+                         CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::getPageNthWord(IJS_Context* cc,
+                                 const CJS_Parameters& params,
+                                 CJS_Value& vRet,
+                                 CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
+    return FALSE;
+
+  int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
+  int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0;
+  bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true;
+
+  CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
+  if (!pDocument)
+    return FALSE;
+
+  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+  if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+    return FALSE;
+  }
+
+  CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+  if (!pPageDict)
+    return FALSE;
+
+  CPDF_Page page;
+  page.Load(pDocument, pPageDict);
+  page.StartParse();
+  page.ParseContent();
+
+  FX_POSITION pos = page.GetFirstObjectPosition();
+
+  int nWords = 0;
+
+  CFX_WideString swRet;
+
+  while (pos) {
+    if (CPDF_PageObject* pPageObj = page.GetNextObject(pos)) {
+      if (pPageObj->m_Type == PDFPAGE_TEXT) {
+        int nObjWords = CountWords((CPDF_TextObject*)pPageObj);
+
+        if (nWords + nObjWords >= nWordNo) {
+          swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
+          break;
+        }
+
+        nWords += nObjWords;
+      }
+    }
+  }
+
+  if (bStrip) {
+    swRet.TrimLeft();
+    swRet.TrimRight();
+  }
+
+  vRet = swRet.c_str();
+  return TRUE;
+}
+
+FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc,
+                                      const CJS_Parameters& params,
+                                      CJS_Value& vRet,
+                                      CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
+    return FALSE;
+
+  return FALSE;
+}
+
+FX_BOOL Document::getPageNumWords(IJS_Context* cc,
+                                  const CJS_Parameters& params,
+                                  CJS_Value& vRet,
+                                  CFX_WideString& sError) {
+  ASSERT(m_pDocument != NULL);
+
+  if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS))
+    return FALSE;
+
+  int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0;
+
+  CPDF_Document* pDocument = m_pDocument->GetPDFDocument();
+  ASSERT(pDocument != NULL);
+
+  CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+  if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) {
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
+    return FALSE;
+  }
+
+  CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+  if (!pPageDict)
+    return FALSE;
+
+  CPDF_Page page;
+  page.Load(pDocument, pPageDict);
+  page.StartParse();
+  page.ParseContent();
+
+  FX_POSITION pos = page.GetFirstObjectPosition();
+
+  int nWords = 0;
+
+  while (pos) {
+    if (CPDF_PageObject* pPageObj = page.GetNextObject(pos)) {
+      if (pPageObj->m_Type == PDFPAGE_TEXT) {
+        CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
+        nWords += CountWords(pTextObj);
+      }
+    }
+  }
+
+  vRet = nWords;
+
+  return TRUE;
+}
+
+FX_BOOL Document::getPrintParams(IJS_Context* cc,
+                                 const CJS_Parameters& params,
+                                 CJS_Value& vRet,
+                                 CFX_WideString& sError) {
+  CJS_Context* pContext = (CJS_Context*)cc;
+  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+  v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID);
+
+  // Not implemented yet.
+
+  vRet = pRetObj;
+  return TRUE;
+}
+
+#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
+
+int Document::CountWords(CPDF_TextObject* pTextObj) {
+  if (!pTextObj)
+    return 0;
+
+  int nWords = 0;
+
+  CPDF_Font* pFont = pTextObj->GetFont();
+  if (!pFont)
+    return 0;
+
+  FX_BOOL bIsLatin = FALSE;
+
+  for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) {
+    FX_DWORD charcode = -1;
+    FX_FLOAT kerning;
+
+    pTextObj->GetCharInfo(i, charcode, kerning);
+    CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
+
+    FX_WORD unicode = 0;
+    if (swUnicode.GetLength() > 0)
+      unicode = swUnicode[0];
+
+    if (ISLATINWORD(unicode) && bIsLatin)
+      continue;
+
+    bIsLatin = ISLATINWORD(unicode);
+    if (unicode != 0x20)
+      nWords++;
+  }
+
+  return nWords;
+}
+
+CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj,
+                                       int nWordIndex) {
+  ASSERT(pTextObj != NULL);
+
+  CFX_WideString swRet;
+
+  CPDF_Font* pFont = pTextObj->GetFont();
+  if (!pFont)
+    return L"";
+
+  int nWords = 0;
+  FX_BOOL bIsLatin = FALSE;
+
+  for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) {
+    FX_DWORD charcode = -1;
+    FX_FLOAT kerning;
+
+    pTextObj->GetCharInfo(i, charcode, kerning);
+    CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
+
+    FX_WORD unicode = 0;
+    if (swUnicode.GetLength() > 0)
+      unicode = swUnicode[0];
+
+    if (ISLATINWORD(unicode) && bIsLatin) {
+    } else {
+      bIsLatin = ISLATINWORD(unicode);
+      if (unicode != 0x20)
+        nWords++;
+    }
+
+    if (nWords - 1 == nWordIndex)
+      swRet += unicode;
+  }
+
+  return swRet;
+}
+
+FX_BOOL Document::zoom(IJS_Context* cc,
+                       CJS_PropValue& vp,
+                       CFX_WideString& sError) {
+  return TRUE;
+}
+
+/**
+(none,  NoVary)
+(fitP,  FitPage)
+(fitW,  FitWidth)
+(fitH,  FitHeight)
+(fitV,  FitVisibleWidth)
+(pref,  Preferred)
+(refW,  ReflowWidth)
+*/
+
+FX_BOOL Document::zoomType(IJS_Context* cc,
+                           CJS_PropValue& vp,
+                           CFX_WideString& sError) {
+  return TRUE;
+}
+
+FX_BOOL Document::deletePages(IJS_Context* cc,
+                              const CJS_Parameters& params,
+                              CJS_Value& vRet,
+                              CFX_WideString& sError) {
+  // Unsafe, no supported.
+  return TRUE;
+}
+
+FX_BOOL Document::extractPages(IJS_Context* cc,
+                               const CJS_Parameters& params,
+                               CJS_Value& vRet,
+                               CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::insertPages(IJS_Context* cc,
+                              const CJS_Parameters& params,
+                              CJS_Value& vRet,
+                              CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::replacePages(IJS_Context* cc,
+                               const CJS_Parameters& params,
+                               CJS_Value& vRet,
+                               CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL Document::getURL(IJS_Context* cc,
+                         const CJS_Parameters& params,
+                         CJS_Value& vRet,
+                         CFX_WideString& sError) {
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+void Document::AddDelayData(CJS_DelayData* pData) {
+  m_DelayData.Add(pData);
+}
+
+void Document::DoFieldDelay(const CFX_WideString& sFieldName,
+                            int nControlIndex) {
+  CFX_DWordArray DelArray;
+  CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex;
+
+  for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) {
+    if (CJS_DelayData* pData = m_DelayData.GetAt(i)) {
+      if (pData->sFieldName == sFieldName &&
+          pData->nControlIndex == nControlIndex) {
+        DelayDataForFieldAndControlIndex.Add(pData);
+        m_DelayData.SetAt(i, NULL);
+        DelArray.Add(i);
+      }
+    }
+  }
+
+  for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
+    m_DelayData.RemoveAt(DelArray[j]);
+  }
+
+  for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz;
+       i++) {
+    CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i);
+    Field::DoDelay(m_pDocument, pData);
+    DelayDataForFieldAndControlIndex.SetAt(i, NULL);
+    delete pData;
+  }
+}
+
+void Document::AddDelayAnnotData(CJS_AnnotObj* pData) {
+  m_DelayAnnotData.Add(pData);
+}
+
+void Document::DoAnnotDelay() {
+  CFX_DWordArray DelArray;
+
+  for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
+    m_DelayData.RemoveAt(DelArray[j]);
+  }
+}
+
+CJS_Document* Document::GetCJSDoc() const {
+  return static_cast<CJS_Document*>(m_pJSObject);
+}