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(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::mailForm(IFXJS_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::addIcon(IFXJS_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(); JSFXObject pJSIcon = params[1].ToV8Object(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) { 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::resetForm(IFXJS_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); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); ASSERT(pPDFForm != NULL); v8::Isolate* isolate = GetIsolate(cc); CJS_Array aName(isolate); if (params.size() > 0) { switch (params[0].GetType()) { default: aName.Attach(params[0].ToV8Array()); break; case VT_string: aName.SetElement(0,params[0]); break; } CFX_PtrArray aFields; for (int i=0,isz=aName.GetLength(); i<isz; i++) { CJS_Value valElement(isolate); 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 console::println(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { if (params.size() < 1) { return FALSE; } return TRUE; }
FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { int iSize = params.size(); if (iSize == 0) return FALSE; int nByte = params[0].ToInt(); unsigned char cByte = (unsigned char)nByte; CFX_WideString csValue; csValue.Format(L"%c", cByte); vRet = csValue.c_str(); return TRUE; }
FX_BOOL Document::deletePages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { v8::Isolate* isolate = GetIsolate(cc); ASSERT(m_pDocument != NULL); if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE; int iSize = params.size(); int nStart = 0; int nEnd = 0; if (iSize < 1) { } else if (iSize == 1) { if (params[0].GetType() == VT_object) { JSObject pObj = params[0].ToV8Object(); v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"nStart"); nStart = CJS_Value(m_isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt(); pValue = JS_GetObjectElement(isolate, pObj, L"nEnd"); nEnd = CJS_Value(m_isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt(); } else { nStart = params[0].ToInt(); } } else { nStart = params[0].ToInt(); nEnd = params[1].ToInt(); } int nTotal = m_pDocument->GetPageCount(); if (nStart < 0) nStart = 0; if (nStart >= nTotal) nStart = nTotal - 1; if (nEnd < 0) nEnd = 0; if (nEnd >= nTotal) nEnd = nTotal - 1; if (nEnd < nStart) nEnd = nStart; return TRUE; }
FX_BOOL Document::removeIcon(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; } if(!m_pIconTree) return FALSE; CFX_WideString swIconName = params[0].ToCFXWideString(); return TRUE; }
FX_BOOL Document::removeField(IFXJS_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; }
FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { int iSize = params.size(); if (iSize<2) return FALSE; CFX_WideString sFormat = params[0].ToCFXWideString(); CFX_WideString sSource = params[1].ToCFXWideString(); std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); std::string cDest; printx(cFormat,cSource,cDest); vRet = cDest.c_str(); return TRUE; }
FX_BOOL color::equal(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { v8::Isolate* isolate = GetIsolate(cc); if (params.size() < 2) return FALSE; CJS_Array array1(isolate), array2(isolate); if (!params[0].ConvertToArray(array1)) return FALSE; if (!params[1].ConvertToArray(array2)) return FALSE; CPWL_Color color1; CPWL_Color color2; ConvertArrayToPWLColor(array1, color1); ConvertArrayToPWLColor(array2, color2); color1.ConvertColorType(color2.nColorType); vRet = color1 == color2; return TRUE; }
FX_BOOL color::convert(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; CJS_Array aSource(isolate); if (!params[0].ConvertToArray(aSource)) return FALSE; CPWL_Color crSource; ConvertArrayToPWLColor(aSource, crSource); CFX_ByteString sDestSpace = params[1].ToCFXByteString(); int nColorType = COLORTYPE_TRANSPARENT; if (sDestSpace == "T") { nColorType = COLORTYPE_TRANSPARENT; } else if (sDestSpace == "G") { nColorType = COLORTYPE_GRAY; } else if (sDestSpace == "RGB") { nColorType = COLORTYPE_RGB; } else if (sDestSpace == "CMYK") { nColorType = COLORTYPE_CMYK; } CJS_Array aDest(isolate); CPWL_Color crDest = crSource; crDest.ConvertColorType(nColorType); ConvertPWLColorToArray(crDest, aDest); vRet = aDest; return TRUE; }
FX_BOOL Document::getIcon(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; } 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; JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon")); if (pObj.IsEmpty()) return FALSE; CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(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; }
//Gets the name of the nth field in the document FX_BOOL Document::getNthFieldName(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; } 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::mailDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); 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(); v8::Isolate* isolate = GetIsolate(cc); if(params.size() >= 1 && params[0].GetType() == VT_object) { JSObject pObj = params[0].ToV8Object(); v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI"); bUI = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToInt(); pValue = JS_GetObjectElement(isolate,pObj, L"cTo"); cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cCc"); cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cBcc"); cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cSubject"); cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); pValue = JS_GetObjectElement(isolate,pObj, L"cMsg"); cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); } CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); 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::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::print(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { CJS_Context* pContext = (CJS_Context*)cc; ASSERT(pContext != NULL); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); ASSERT(pRuntime != NULL); 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() == VT_fxobject) { JSFXObject pObj = params[8].ToV8Object(); { if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")) { 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; }
FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) { int iSize = params.size(); if (iSize < 1) return FALSE; std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); std::vector<std::wstring> c_strConvers; int iOffset = 0; int iOffend = 0; c_ConvChar.insert(c_ConvChar.begin(),L'S'); while(iOffset != -1) { iOffend = c_ConvChar.find(L"%",iOffset+1); std::wstring strSub; if (iOffend == -1) strSub = c_ConvChar.substr(iOffset); else strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset); c_strConvers.push_back(strSub); iOffset = iOffend ; } std::wstring c_strResult; //for(int iIndex = 1;iIndex < params.size();iIndex++) std::wstring c_strFormat; for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++) { c_strFormat = c_strConvers[iIndex]; if (iIndex == 0) { c_strResult = c_strFormat; continue; } CFX_WideString strSegment; if (iIndex >= iSize) { c_strResult += c_strFormat; continue; } switch (ParstDataType(&c_strFormat)) { case UTIL_INT: strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt()); break; case UTIL_DOUBLE: strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble()); break; case UTIL_STRING: strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideString().c_str()); break; default: strSegment.Format(L"%S", c_strFormat.c_str()); break; } c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); } c_strResult.erase(c_strResult.begin()); vRet = c_strResult.c_str(); return TRUE; }
FX_BOOL util::printd(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; CJS_Value p1(isolate); p1 = params[0]; CJS_Value p2 = params[1]; CJS_Date jsDate(isolate); if (!p2.ConvertToDate(jsDate)) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1); return FALSE; } if (!jsDate.IsValidDate()) { sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); return FALSE; } if (p1.GetType() == VT_number) { int nFormat = p1.ToInt(); CFX_WideString swResult; switch (nFormat) { case 0: swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", jsDate.GetYear(), jsDate.GetMonth() + 1, jsDate.GetDay(), jsDate.GetHours(), jsDate.GetMinutes(), jsDate.GetSeconds()); break; case 1: swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", jsDate.GetYear(), jsDate.GetMonth() + 1, jsDate.GetDay(), jsDate.GetHours(), jsDate.GetMinutes(), jsDate.GetSeconds()); break; case 2: swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", jsDate.GetYear(), jsDate.GetMonth() + 1, jsDate.GetDay(), jsDate.GetHours(), jsDate.GetMinutes(), jsDate.GetSeconds()); break; default: return FALSE; } vRet = swResult.c_str(); return TRUE; } else if (p1.GetType() == VT_string) { std::basic_string<wchar_t> cFormat = p1.ToCFXWideString().c_str(); bool bXFAPicture = false; if (iSize > 2) { bXFAPicture = params[2].ToBool(); } if (bXFAPicture) { return FALSE; //currently, it doesn't support XFAPicture. } int iIndex; for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++) { int iStart = 0; int iEnd; while((iEnd = cFormat.find(fcTable[iIndex].lpszJSMark, iStart)) != -1) { cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), fcTable[iIndex].lpszCppMark); iStart = iEnd; } } int iYear,iMonth,iDay,iHour,iMin,iSec; iYear = jsDate.GetYear(); iMonth = jsDate.GetMonth(); iDay = jsDate.GetDay(); iHour = jsDate.GetHours(); iMin = jsDate.GetMinutes(); iSec = jsDate.GetSeconds(); struct tm time = {}; time.tm_year = iYear-1900; time.tm_mon = iMonth; time.tm_mday = iDay; time.tm_hour = iHour; time.tm_min = iMin; time.tm_sec = iSec; //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec); //CString strFormat = cppTm.Format(cFormat.c_str()); struct stru_TbConvertAd { const FX_WCHAR* lpszJSMark; int iValue; }; stru_TbConvertAd cTableAd[] ={ { L"m", iMonth+1 }, { L"d", iDay }, { L"H", iHour }, { L"h", iHour>12?iHour-12:iHour }, { L"M", iMin }, { L"s", iSec }, }; //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++) { wchar_t tszValue[10]; //_itot(cTableAd[iIndex].iValue,tszValue,10); CFX_WideString sValue; sValue.Format(L"%d",cTableAd[iIndex].iValue); memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1), (sValue.GetLength()+1)*sizeof(wchar_t)); //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d"); //strFormat.Format(strFormat,cTableAd[iIndex].iValue); int iStart = 0; int iEnd; while((iEnd = cFormat.find(cTableAd[iIndex].lpszJSMark, iStart)) != -1) { if (iEnd > 0) { if (cFormat[iEnd-1] == L'%') { iStart = iEnd+1; continue; } } cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue); iStart = iEnd; } } CFX_WideString strFormat; // strFormat.Format(L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec); // CString strFormat = cppTm.Format(cFormat.c_str()); wchar_t buf[64] = {}; strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; vRet = cFormat.c_str(); //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1); return TRUE; } return FALSE; }