Commit 6aa57fb2 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov

stable version source codes

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@59493 954022d7-b5bf-4e40-9824-e11837661b57
parent 6770d23b
......@@ -12,7 +12,7 @@
#endif
// TEST!!!
#define _LOG_ERRORS_TO_FILE_
//#define _LOG_ERRORS_TO_FILE_
#ifdef _LOG_ERRORS_TO_FILE_
......@@ -397,8 +397,10 @@ public:
if (m_strEditorType == _T("spreadsheet"))
strScript += _T("\n$.ready();");
#if 0
CTimeMeasurer oMeasurer;
oMeasurer.Reset();
#endif
CString strError = _T("");
BOOL bResult = ExecuteScript(strScript, strError);
......@@ -409,10 +411,12 @@ public:
*pbsError = sDestError.AllocSysString();
}
#if 0
int nTime = (int)(1000 * oMeasurer.GetTimeInterval());
CString strTime = _T("");
strTime.Format(_T("%d"), nTime);
_LOGGING_ERROR_(L"time_changes", strTime);
_LOGGING_ERROR_(L"time_doct_renderer", strTime);
#endif
return bResult ? S_OK : S_FALSE;
}
......@@ -547,411 +551,297 @@ private:
m_bIsInitTypedArrays = TRUE;
}
WCHAR* javascript = (WCHAR*)strScript.GetBuffer();
bool bIsBreak = false;
v8::Isolate* isolate = v8::Isolate::New();
isolate->Enter();
v8::Isolate::Scope isolate_cope(isolate);
v8::Locker isolate_locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::NewFromUtf8(isolate, "CreateNativeEngine"), v8::FunctionTemplate::New(isolate, CreateNativeObject));
global->Set(v8::String::NewFromUtf8(isolate, "CreateNativeMemoryStream"), v8::FunctionTemplate::New(isolate, CreateNativeMemoryStream));
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
context->Enter();
v8::Context::Scope context_scope(context);
v8::TryCatch try_catch;
v8::Local<v8::String> source = v8::String::NewFromTwoByte(isolate, (uint16_t*)javascript);
v8::Local<v8::Script> script = v8::Script::Compile(source);
if (try_catch.HasCaught())
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"compile", strException)
strError = _T("code=\"compile\"");
return FALSE;
}
v8::Local<v8::Value> result = script->Run();
if (try_catch.HasCaught())
if (true)
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"run", strException)
strError = _T("code=\"run\"");
return FALSE;
}
//---------------------------------------------------------------
v8::Local<v8::Object> global_js = context->Global();
v8::Handle<v8::Value> args[1];
args[0] = v8::Int32::New(isolate, 0);
// all
#if 0
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeOpenFile"));
#else
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeOpenFileData"));
#endif
v8::Handle<v8::Value> js_func_id = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeId"));
// changes
#if 0
v8::Handle<v8::Value> js_func_apply_changes = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeApplyChanges"));
#else
v8::Handle<v8::Value> js_func_apply_changes = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeApplyChangesData"));
#endif
// save T format
#if 0
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileString"));
#else
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileData"));
#endif
// pdf
v8::Handle<v8::Value> js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile"));
v8::Handle<v8::Value> js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages"));
v8::Handle<v8::Value> js_func_page = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativePageBase64"));
CString strDocumentId = _T("");
LONG lPagesCount = 0;
if (js_func_id->IsFunction())
{
v8::Handle<v8::Function> func_id = v8::Handle<v8::Function>::Cast(js_func_id);
v8::Local<v8::Value> js_result2 = func_id->Call(global_js, 1, args);
WCHAR* javascript = (WCHAR*)strScript.GetBuffer();
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
strException = to_cstring(try_catch.Message()->Get()); // ?
v8::Isolate::Scope isolate_cope(isolate);
v8::Locker isolate_locker(isolate);
strError = _T("code=\"run\"");
return FALSE;
}
v8::HandleScope handle_scope(isolate);
strDocumentId = to_cstring(js_result2);
}
CNativeControl* pNative = NULL;
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
global->Set(v8::String::NewFromUtf8(isolate, "CreateNativeEngine"), v8::FunctionTemplate::New(isolate, CreateNativeObject));
global->Set(v8::String::NewFromUtf8(isolate, "CreateNativeMemoryStream"), v8::FunctionTemplate::New(isolate, CreateNativeMemoryStream));
v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeEngine"));
v8::Local<v8::Object> objNative;
if (js_func_get_native->IsFunction())
{
v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native);
v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args);
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
strException = to_cstring(try_catch.Message()->Get()); // ?
isolate->Exit();
strError = _T("code=\"run\"");
return FALSE;
}
objNative = js_result2->ToObject();
v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0));
v8::Context::Scope context_scope(context);
v8::TryCatch try_catch;
v8::Local<v8::String> source = v8::String::NewFromTwoByte(isolate, (uint16_t*)javascript);
v8::Local<v8::Script> script = v8::Script::Compile(source);
pNative = static_cast<CNativeControl*>(field->Value());
}
// COMPILE
if (try_catch.HasCaught())
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get());
pNative->m_pChanges = &m_oParams.m_arChanges;
pNative->m_strFontsDirectory = m_oParams.m_strFontsDirectory;
pNative->m_strImagesDirectory = m_oParams.m_strImagesDirectory;
_LOGGING_ERROR_(L"compile", strException)
pNative->m_strEditorType = m_strEditorType;
pNative->SetFilePath(m_strFilePath);
strError = _T("code=\"compile\"");
bIsBreak = true;
}
pNative->m_nMaxChangesNumber = m_oParams.m_nCountChangesItems;
// RUN
if (!bIsBreak)
{
v8::Local<v8::Value> result = script->Run();
#if 1
if (try_catch.HasCaught())
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get());
if (js_func_open->IsFunction())
{
v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
_LOGGING_ERROR_(L"run", strException)
CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath());
strError = _T("code=\"run\"");
bIsBreak = true;
}
}
v8::Handle<v8::Value> args_changes[2];
args_changes[0] = oWorkerLoader.GetDataFull();
args_changes[1] = v8::Integer::New(isolate, nVersion);
//---------------------------------------------------------------
v8::Local<v8::Object> global_js = context->Global();
v8::Handle<v8::Value> args[1];
args[0] = v8::Int32::New(isolate, 0);
func_open->Call(global_js, 2, args_changes);
CNativeControl* pNative = NULL;
if (try_catch.HasCaught())
// GET_NATIVE_ENGINE
if (!bIsBreak)
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"open", strException)
strError = _T("code=\"open\"");
return FALSE;
}
}
v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeEngine"));
v8::Local<v8::Object> objNative;
if (js_func_get_native->IsFunction())
{
v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native);
v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args);
#else
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
strException = to_cstring(try_catch.Message()->Get());
if (js_func_open->IsFunction())
{
v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
strError = _T("code=\"run\"");
bIsBreak = true;
}
else
{
objNative = js_result2->ToObject();
v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0));
func_open->Call(global_js, 1, args);
pNative = static_cast<CNativeControl*>(field->Value());
}
}
}
if (try_catch.HasCaught())
if (pNative != NULL)
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
pNative->m_pChanges = &m_oParams.m_arChanges;
pNative->m_strFontsDirectory = m_oParams.m_strFontsDirectory;
pNative->m_strImagesDirectory = m_oParams.m_strImagesDirectory;
_LOGGING_ERROR_(L"open", strException)
strError = _T("code=\"open\"");
return FALSE;
}
}
pNative->m_strEditorType = m_strEditorType;
pNative->SetFilePath(m_strFilePath);
#endif
pNative->m_nMaxChangesNumber = m_oParams.m_nCountChangesItems;
}
// OPEN
if (!bIsBreak)
{
#if 1
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeOpenFileData"));
if (js_func_open->IsFunction())
{
v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
if (m_oParams.m_arChanges.GetCount() != 0)
{
//CTimeMeasurer oMeasurer;
//oMeasurer.Reset();
int nCurrentIndex = 0;
CChangesWorker oWorker;
int nFileType = 0;
if (m_strEditorType == _T("spreadsheet"))
nFileType = 1;
oWorker.SetFormatChanges(nFileType);
oWorker.CheckFiles(m_oParams.m_arChanges);
while (true)
{
nCurrentIndex = oWorker.Open(m_oParams.m_arChanges, nCurrentIndex);
bool bIsFull = (nCurrentIndex == m_oParams.m_arChanges.GetCount()) ? true : false;
CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath());
if (js_func_apply_changes->IsFunction())
{
v8::Handle<v8::Function> func_apply_changes = v8::Handle<v8::Function>::Cast(js_func_apply_changes);
v8::Handle<v8::Value> args_changes[2];
args_changes[0] = oWorker.GetData();
args_changes[1] = v8::Boolean::New(isolate, bIsFull);
v8::Handle<v8::Value> args_open[2];
args_open[0] = oWorkerLoader.GetDataFull();
args_open[1] = v8::Integer::New(isolate, nVersion);
func_apply_changes->Call(global_js, 2, args_changes);
func_open->Call(global_js, 2, args_open);
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"change_code", strCode)
_LOGGING_ERROR_(L"change", strException)
strError = _T("");
strError.Format(_T("index=\"%d\""), pNative->m_nCurrentChangesNumber);
return FALSE;
_LOGGING_ERROR_(L"open", strException)
strError = _T("code=\"open\"");
bIsBreak = true;
}
}
if (bIsFull)
break;
}
//int nTime = (oMeasurer.GetTimeInterval() * 1000);
//CString strTime = _T("");
//strTime.Format(_T("%d"), nTime);
//_LOGGING_ERROR_(L"time_changes", strTime);
}
#else
if (m_oParams.m_arChanges.GetCount() != 0)
{
if (js_func_apply_changes->IsFunction())
{
v8::Handle<v8::Function> func_apply_changes = v8::Handle<v8::Function>::Cast(js_func_apply_changes);
func_apply_changes->Call(global_js, 1, args);
if (try_catch.HasCaught())
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeOpenFile"));
if (js_func_open->IsFunction())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
_LOGGING_ERROR_(L"change_code", strCode)
_LOGGING_ERROR_(L"change", strException)
func_open->Call(global_js, 1, args);
strError = _T("");
strError.Format(_T("index=\"%d\""), pNative->m_nCurrentChangesNumber);
return FALSE;
if (try_catch.HasCaught())
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"open", strException)
strError = _T("code=\"open\"");
bIsBreak = true;
}
}
}
}
#endif
}
switch (m_oParams.m_eDstFormat)
{
case DoctRendererFormat::DOCT:
case DoctRendererFormat::PPTT:
case DoctRendererFormat::XLST:
// CHANGES
if (!bIsBreak)
{
#if 1
if (js_func_get_file_s->IsFunction())
v8::Handle<v8::Value> js_func_apply_changes = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeApplyChangesData"));
if (m_oParams.m_arChanges.GetCount() != 0)
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
//CTimeMeasurer oMeasurer;
//oMeasurer.Reset();
strError = _T("code=\"save\"");
int nCurrentIndex = 0;
CChangesWorker oWorker;
_LOGGING_ERROR_(L"save", strException)
int nFileType = 0;
if (m_strEditorType == _T("spreadsheet"))
nFileType = 1;
return FALSE;
}
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
oWorker.SetFormatChanges(nFileType);
oWorker.CheckFiles(m_oParams.m_arChanges);
CFile oFile;
if (S_OK == oFile.CreateFile(m_oParams.m_strDstFilePath))
while (!bIsBreak)
{
oFile.WriteFile((void*)pNative->m_sHeader.GetBuffer(), (DWORD)pNative->m_sHeader.GetLength());
int nLen64 = Base64EncodeGetRequiredLength((DWORD)pNative->m_nSaveBinaryLen, ATL_BASE64_FLAG_NOCRLF);
char* pDst64 = new char[nLen64];
int nDstLen = nLen64;
Base64Encode(pData, pNative->m_nSaveBinaryLen, pDst64, &nDstLen, ATL_BASE64_FLAG_NOCRLF);
oFile.WriteFile((void*)pDst64, (DWORD)nDstLen);
nCurrentIndex = oWorker.Open(m_oParams.m_arChanges, nCurrentIndex);
bool bIsFull = (nCurrentIndex == m_oParams.m_arChanges.GetCount()) ? true : false;
RELEASEARRAYOBJECTS(pDst64);
if (js_func_apply_changes->IsFunction())
{
v8::Handle<v8::Function> func_apply_changes = v8::Handle<v8::Function>::Cast(js_func_apply_changes);
v8::Handle<v8::Value> args_changes[2];
args_changes[0] = oWorker.GetData();
args_changes[1] = v8::Boolean::New(isolate, bIsFull);
func_apply_changes->Call(global_js, 2, args_changes);
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"change_code", strCode)
_LOGGING_ERROR_(L"change", strException)
strError = _T("");
strError.Format(_T("index=\"%d\""), pNative->m_nCurrentChangesNumber);
bIsBreak = true;
}
}
oFile.CloseFile();
return TRUE;
if (bIsFull)
break;
}
//int nTime = (oMeasurer.GetTimeInterval() * 1000);
//CString strTime = _T("");
//strTime.Format(_T("%d"), nTime);
//_LOGGING_ERROR_(L"time_changes", strTime);
}
#else
if (js_func_get_file_s->IsFunction())
#else
v8::Handle<v8::Value> js_func_apply_changes = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeApplyChanges"));
if (m_oParams.m_arChanges.GetCount() != 0)
{
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
if (js_func_apply_changes->IsFunction())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
strError = _T("code=\"save\"");
v8::Handle<v8::Function> func_apply_changes = v8::Handle<v8::Function>::Cast(js_func_apply_changes);
func_apply_changes->Call(global_js, 1, args);
_LOGGING_ERROR_(L"save", strException)
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
return FALSE;
}
_LOGGING_ERROR_(L"change_code", strCode)
_LOGGING_ERROR_(L"change", strException)
CStringA strSave = to_cstringA(js_result2);
CFile oFile;
if (S_OK == oFile.CreateFile(m_oParams.m_strDstFilePath))
{
oFile.WriteFile((void*)strSave.GetBuffer(), (DWORD)strSave.GetLength());
oFile.CloseFile();
return TRUE;
strError = _T("");
strError.Format(_T("index=\"%d\""), pNative->m_nCurrentChangesNumber);
bIsBreak = true;
}
}
}
#endif
break;
}
case DoctRendererFormat::PDF:
// SAVE
if (!bIsBreak)
{
if (js_func_calculate->IsFunction())
switch (m_oParams.m_eDstFormat)
{
v8::Handle<v8::Function> func_calculate = v8::Handle<v8::Function>::Cast(js_func_calculate);
func_calculate->Call(global_js, 1, args);
if (try_catch.HasCaught())
case DoctRendererFormat::DOCT:
case DoctRendererFormat::PPTT:
case DoctRendererFormat::XLST:
{
#if 1
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileData"));
if (js_func_get_file_s->IsFunction())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
strError = _T("code=\"calculate\"");
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"calculate", strException)
strError = _T("code=\"save\"");
return FALSE;
}
}
_LOGGING_ERROR_(L"save", strException)
bIsBreak = true;
}
else
{
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
LONG lPagesCount = 0;
if (js_func_pages_count->IsFunction())
{
v8::Handle<v8::Function> func_pages_count = v8::Handle<v8::Function>::Cast(js_func_pages_count);
v8::Local<v8::Value> js_result1 = func_pages_count->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
CFile oFile;
if (S_OK == oFile.CreateFile(m_oParams.m_strDstFilePath))
{
oFile.WriteFile((void*)pNative->m_sHeader.GetBuffer(), (DWORD)pNative->m_sHeader.GetLength());
strError = _T("code=\"calculate\"");
return FALSE;
}
int nLen64 = Base64EncodeGetRequiredLength((DWORD)pNative->m_nSaveBinaryLen, ATL_BASE64_FLAG_NOCRLF);
char* pDst64 = new char[nLen64];
int nDstLen = nLen64;
Base64Encode(pData, pNative->m_nSaveBinaryLen, pDst64, &nDstLen, ATL_BASE64_FLAG_NOCRLF);
v8::Local<v8::Int32> intValue = js_result1->ToInt32();
lPagesCount = (LONG)intValue->Value();
}
oFile.WriteFile((void*)pDst64, (DWORD)nDstLen);
if (js_func_page->IsFunction())
{
PDFWriter::IPDFWriter* pPDF = NULL;
CoCreateInstance(PDFWriter::CLSID_CPDFWriter, NULL, CLSCTX_ALL, PDFWriter::IID_IPDFWriter, (void**)&pPDF);
VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = m_oParams.m_strFontsDirectory.AllocSysString();
pPDF->SetAdditionalParam(L"InitializeFromFolder", var);
SysFreeString(var.bstrVal);
pPDF->CreatePDF();
pPDF->SetPDFCompressionMode(15);
RELEASEINTERFACE(m_pRenderer);
pPDF->QueryInterface(__uuidof(IASCRenderer), (void**)&m_pRenderer);
RELEASEARRAYOBJECTS(pDst64);
v8::Handle<v8::Function> func_page = v8::Handle<v8::Function>::Cast(js_func_page);
for (LONG i = 0; i < lPagesCount; i++)
oFile.CloseFile();
}
}
}
#else
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileString"));
if (js_func_get_file_s->IsFunction())
{
args[0] = v8::Int32::New(isolate, i);
v8::Local<v8::Value> js_result3 = func_page->Call(global_js, 1, args);
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
......@@ -959,49 +849,163 @@ private:
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"render", strException)
strError = _T("code=\"save\"");
strError = _T("code=\"render\"");
return FALSE;
}
_LOGGING_ERROR_(L"save", strException)
CMemoryStream* pPageStream = unwrap_memorystream(js_result3->ToObject());
ParsePageBinary(i, pPageStream->GetData(), pPageStream->GetSize(), true);
bIsBreak = true;
}
#if 0
CStringA strSave = to_cstringA(js_result2);
CFile oFile;
CString sPageSave = _T("");
sPageSave.Format(_T("C:\\test\\DOCTRENDERER\\page%d.pagebin"), i + 1);
oFile.CreateFile(sPageSave);
oFile.WriteFile(pPageStream->GetData(), pPageStream->GetSize());
oFile.CloseFile();
#endif
if (S_OK == oFile.CreateFile(m_oParams.m_strDstFilePath))
{
oFile.WriteFile((void*)strSave.GetBuffer(), (DWORD)strSave.GetLength());
oFile.CloseFile();
}
}
#endif
break;
}
case DoctRendererFormat::PDF:
{
v8::Handle<v8::Value> js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile"));
v8::Handle<v8::Value> js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages"));
v8::Handle<v8::Value> js_func_page = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativePageBase64"));
// CALCULATE
if (js_func_calculate->IsFunction())
{
v8::Handle<v8::Function> func_calculate = v8::Handle<v8::Function>::Cast(js_func_calculate);
func_calculate->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
strError = _T("code=\"calculate\"");
RELEASEINTERFACE(m_pRenderer);
_LOGGING_ERROR_(L"calculate", strException)
BSTR bsFileDst = m_oParams.m_strDstFilePath.AllocSysString();
HRESULT hr = pPDF->SaveToFile(bsFileDst);
SysFreeString(bsFileDst);
bIsBreak = true;
}
}
RELEASEINTERFACE(pPDF);
if (S_OK != hr)
LONG lPagesCount = 0;
// PAGESCOUNT
if (bIsBreak)
{
_LOGGING_ERROR_(L"save", L"pdfsave")
strError = _T("code=\"save\"");
if (js_func_pages_count->IsFunction())
{
v8::Handle<v8::Function> func_pages_count = v8::Handle<v8::Function>::Cast(js_func_pages_count);
v8::Local<v8::Value> js_result1 = func_pages_count->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
strError = _T("code=\"calculate\"");
bIsBreak = true;
}
else
{
v8::Local<v8::Int32> intValue = js_result1->ToInt32();
lPagesCount = (LONG)intValue->Value();
}
}
}
return (hr == S_OK) ? TRUE : FALSE;
}
// RENDER
if (!bIsBreak)
{
if (js_func_page->IsFunction())
{
PDFWriter::IPDFWriter* pPDF = NULL;
CoCreateInstance(PDFWriter::CLSID_CPDFWriter, NULL, CLSCTX_ALL, PDFWriter::IID_IPDFWriter, (void**)&pPDF);
VARIANT var;
var.vt = VT_BSTR;
var.bstrVal = m_oParams.m_strFontsDirectory.AllocSysString();
pPDF->SetAdditionalParam(L"InitializeFromFolder", var);
SysFreeString(var.bstrVal);
pPDF->CreatePDF();
pPDF->SetPDFCompressionMode(15);
RELEASEINTERFACE(m_pRenderer);
pPDF->QueryInterface(__uuidof(IASCRenderer), (void**)&m_pRenderer);
v8::Handle<v8::Function> func_page = v8::Handle<v8::Function>::Cast(js_func_page);
for (LONG i = 0; i < lPagesCount; i++)
{
args[0] = v8::Int32::New(isolate, i);
v8::Local<v8::Value> js_result3 = func_page->Call(global_js, 1, args);
if (try_catch.HasCaught())
{
int nLineError = try_catch.Message()->GetLineNumber();
CString strCode = to_cstring(try_catch.Message()->GetSourceLine());
strException = to_cstring(try_catch.Message()->Get()); // ?
_LOGGING_ERROR_(L"render", strException)
strError = _T("code=\"render\"");
bIsBreak = true;
break;
}
else
{
CMemoryStream* pPageStream = unwrap_memorystream(js_result3->ToObject());
ParsePageBinary(i, pPageStream->GetData(), pPageStream->GetSize(), true);
break;
#if 0
CFile oFile;
CString sPageSave = _T("");
sPageSave.Format(_T("C:\\test\\DOCTRENDERER\\page%d.pagebin"), i + 1);
oFile.CreateFile(sPageSave);
oFile.WriteFile(pPageStream->GetData(), pPageStream->GetSize());
oFile.CloseFile();
#endif
}
}
RELEASEINTERFACE(m_pRenderer);
HRESULT hr = S_FALSE;
if (!bIsBreak)
{
BSTR bsFileDst = m_oParams.m_strDstFilePath.AllocSysString();
hr = pPDF->SaveToFile(bsFileDst);
SysFreeString(bsFileDst);
}
RELEASEINTERFACE(pPDF);
if (S_OK != hr)
{
_LOGGING_ERROR_(L"save", L"pdfsave")
strError = _T("code=\"save\"");
bIsBreak = true;
}
}
}
break;
}
default:
break;
}
}
default:
break;
}
isolate->Dispose();
v8::V8::Dispose();
return FALSE;
return bIsBreak ? FALSE : TRUE;
}
void ParsePageBinary(LONG i, BYTE* pOutput, int lOutputLen, bool bIsPDF = false)
......
......@@ -389,77 +389,6 @@ v8::Handle<v8::ObjectTemplate> CreateNativeControlTemplate(v8::Isolate* isolate)
}
// --------------------------
// native object list (static)
class CNativeControlsList
{
private:
CAtlArray<CNativeControl*> m_arrControls;
public:
CNativeControlsList() : m_arrControls()
{
}
~CNativeControlsList()
{
m_arrControls.RemoveAll();
}
CString GreateGUID()
{
GUID guid;
CoCreateGuid(&guid);
OLECHAR szGuid[GUID_STRING_LEN];
memset(szGuid, 0, GUID_STRING_LEN * sizeof(OLECHAR));
int nCount = ::StringFromGUID2(guid, szGuid, GUID_STRING_LEN);
CString strRet(szGuid);
return strRet;
}
CNativeControl* CreateControl()
{
CString strGuid = GreateGUID();
CNativeControl* pControl = new CNativeControl();
pControl->SetFileId(strGuid);
m_arrControls.Add(pControl);
return pControl;
}
size_t GetCount()
{
return m_arrControls.GetCount();
}
CNativeControl* GetControlById(const CString& strId)
{
size_t count = m_arrControls.GetCount();
for (size_t i = 0; i < count; ++i)
{
if (strId == m_arrControls[i]->GetFileId())
{
return m_arrControls[i];
}
}
return NULL;
}
void DeleteControlById(const CString& strId)
{
size_t count = m_arrControls.GetCount();
for (size_t i = 0; i < count; ++i)
{
if (strId == m_arrControls[i]->GetFileId())
{
m_arrControls.RemoveAt(i);
return;
}
}
}
};
// create work with arraytypes
class MallocArrayBufferAllocator : public v8::ArrayBuffer::Allocator
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment