FX_BOOL util::scand(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { v8::Isolate* isolate = GetIsolate(cc); int iSize = params.size(); if (iSize < 2) return FALSE; CFX_WideString sFormat = params[0].ToCFXWideString(); CFX_WideString sDate = params[1].ToCFXWideString(); double dDate = JS_GetDateTime(); if (sDate.GetLength() > 0) { FX_BOOL bWrongFormat = FALSE; dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat); } if (!JS_PortIsNan(dDate)) { CJS_Date date(isolate,dDate); vRet = date; } else { vRet.SetNull(); } return TRUE; }
FX_BOOL Document::getField(IFXJS_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(); JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field")); v8::Isolate* isolate = GetIsolate(cc); CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj); Field* pField = (Field *)pJSField->GetEmbedObject(); pField->AttachField(this, wideName); vRet = pJSField; return TRUE; }
FX_BOOL util::scand(IJS_Context* cc, const std::vector<CJS_Value>& params, CJS_Value& vRet, CFX_WideString& sError) { int iSize = params.size(); if (iSize < 2) return FALSE; CFX_WideString sFormat = params[0].ToCFXWideString(); CFX_WideString sDate = params[1].ToCFXWideString(); double dDate = JS_GetDateTime(); if (sDate.GetLength() > 0) { FX_BOOL bWrongFormat = FALSE; dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, bWrongFormat); } if (!JS_PortIsNan(dDate)) { vRet = CJS_Date(CJS_Runtime::FromContext(cc), dDate); } else { vRet.SetNull(); } return TRUE; }
FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); CJS_Context* pContext = (CJS_Context*)cc; int nSize = params.size(); if (nSize < 1) { sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); return FALSE; } CFX_WideString strURL; FX_BOOL bFDF = TRUE; FX_BOOL bEmpty = FALSE; v8::Isolate* isolate = GetIsolate(cc); CJS_Array aFields(isolate); CJS_Value v = params[0]; if (v.GetType() == 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() == VT_object) { JSObject pObj = params[0].ToV8Object(); v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cURL"); if (!pValue.IsEmpty()) strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate, pObj, L"bFDF"); bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty"); bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); pValue = JS_GetObjectElement(isolate, pObj,L"aFields"); aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); } CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); ASSERT(pPDFInterForm != NULL); FX_BOOL bAll = (aFields.GetLength() == 0); if (bAll && bEmpty) { CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); if (pPDFInterForm->CheckRequiredFields()) { pRuntime->BeginBlock(); pInterForm->SubmitForm(strURL, FALSE); pRuntime->EndBlock(); } return TRUE; } else { CFX_PtrArray fieldObjects; for (int i=0,sz=aFields.GetLength(); i<sz; i++) { CJS_Value valName(isolate); aFields.GetElement(i, valName); CFX_WideString sName = valName.ToCFXWideString(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); ASSERT(pPDFForm != NULL); 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); } } CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) { pRuntime->BeginBlock(); pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); pRuntime->EndBlock(); } return TRUE; } }
FX_BOOL Document::getAnnot3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { vRet.SetNull(); return TRUE; }
void CJS_Value::operator=(CJS_Value value) { m_pValue = value.ToV8Value(); m_eType = value.m_eType; m_pJSRuntime = value.m_pJSRuntime; }
void CJS_Value::operator=(CJS_Value value) { m_pValue = value.ToV8Value(); m_eType = value.m_eType; m_isolate = value.m_isolate; }
void CJS_Value::operator = (CJS_Value value) { m_pValue = value.ToJSValue(); m_eType = value.m_eType; }