Commit a70087e1 authored by Oleg Korshul's avatar Oleg Korshul

no base 64 data

parent c3da9a66
/* /*
* (c) Copyright Ascensio System SIA 2010-2017 * (c) Copyright Ascensio System SIA 2010-2017
* *
* This program is a free software product. You can redistribute it and/or * This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL) * modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with * version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement * that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights. * of any third-party rights.
* *
* This program is distributed WITHOUT ANY WARRANTY; without even the implied * This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
* *
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021. * EU, LV-1021.
* *
* The interactive user interfaces in modified source and object code versions * The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under * of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3. * Section 5 of the GNU AGPL version 3.
* *
* Pursuant to Section 7(b) of the License you must retain the original Product * Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to * logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks. * grant you any rights under trademark law for use of our trademarks.
* *
* All the Product's GUI elements, including illustrations and icon sets, as * All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the * well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License * Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
* *
*/ */
#include "doctrenderer.h" #include "doctrenderer.h"
#include "docbuilder.h" #include "docbuilder.h"
#ifdef BOOL #ifdef BOOL
#undef BOOL #undef BOOL
#endif #endif
#include "nativecontrol.h" #include "nativecontrol.h"
#include "../xml/include/xmlutils.h" #include "../xml/include/xmlutils.h"
#include <iostream> #include <iostream>
namespace NSDoctRenderer namespace NSDoctRenderer
{ {
class CExecuteParams class CExecuteParams
{ {
public: public:
DoctRendererFormat::FormatFile m_eSrcFormat; DoctRendererFormat::FormatFile m_eSrcFormat;
DoctRendererFormat::FormatFile m_eDstFormat; DoctRendererFormat::FormatFile m_eDstFormat;
std::wstring m_strFontsDirectory; std::wstring m_strFontsDirectory;
std::wstring m_strImagesDirectory; std::wstring m_strImagesDirectory;
std::wstring m_strThemesDirectory; std::wstring m_strThemesDirectory;
std::wstring m_strSrcFilePath; std::wstring m_strSrcFilePath;
std::wstring m_strDstFilePath; std::wstring m_strDstFilePath;
CArray<std::wstring> m_arChanges; CArray<std::wstring> m_arChanges;
int m_nCountChangesItems; int m_nCountChangesItems;
std::wstring m_strMailMergeDatabasePath; std::wstring m_strMailMergeDatabasePath;
std::wstring m_strMailMergeField; std::wstring m_strMailMergeField;
int m_nMailMergeIndexStart; int m_nMailMergeIndexStart;
int m_nMailMergeIndexEnd; int m_nMailMergeIndexEnd;
bool m_bIsRetina; bool m_bIsRetina;
int m_nSaveToPDFParams; int m_nSaveToPDFParams;
bool m_bIsOnlyOnePage; bool m_bIsOnlyOnePage;
bool m_bIsCachedScripts; bool m_bIsCachedScripts;
public: public:
CExecuteParams() : m_arChanges() CExecuteParams() : m_arChanges()
{ {
m_eSrcFormat = DoctRendererFormat::INVALID; m_eSrcFormat = DoctRendererFormat::INVALID;
m_eDstFormat = DoctRendererFormat::INVALID; m_eDstFormat = DoctRendererFormat::INVALID;
m_strFontsDirectory = L""; m_strFontsDirectory = L"";
m_strImagesDirectory = L""; m_strImagesDirectory = L"";
m_strThemesDirectory = L""; m_strThemesDirectory = L"";
m_strSrcFilePath = L""; m_strSrcFilePath = L"";
m_strDstFilePath = L""; m_strDstFilePath = L"";
m_nCountChangesItems = -1; m_nCountChangesItems = -1;
m_strMailMergeDatabasePath = L""; m_strMailMergeDatabasePath = L"";
m_strMailMergeField = L""; m_strMailMergeField = L"";
m_nMailMergeIndexStart = -1; m_nMailMergeIndexStart = -1;
m_nMailMergeIndexEnd = -1; m_nMailMergeIndexEnd = -1;
m_bIsRetina = false; m_bIsRetina = false;
m_nSaveToPDFParams = 0; m_nSaveToPDFParams = 0;
m_bIsOnlyOnePage = false; m_bIsOnlyOnePage = false;
m_bIsCachedScripts = true; m_bIsCachedScripts = true;
} }
~CExecuteParams() ~CExecuteParams()
{ {
m_arChanges.RemoveAll(); m_arChanges.RemoveAll();
} }
public: public:
bool FromXml(const std::wstring& strXml) bool FromXml(const std::wstring& strXml)
{ {
XmlUtils::CXmlNode oNode; XmlUtils::CXmlNode oNode;
if (!oNode.FromXmlString(strXml)) if (!oNode.FromXmlString(strXml))
return false; return false;
m_strSrcFilePath = oNode.ReadValueString(L"SrcFilePath"); m_strSrcFilePath = oNode.ReadValueString(L"SrcFilePath");
m_strDstFilePath = oNode.ReadValueString(L"DstFilePath"); m_strDstFilePath = oNode.ReadValueString(L"DstFilePath");
m_eSrcFormat = (DoctRendererFormat::FormatFile)(oNode.ReadValueInt(L"SrcFileType")); m_eSrcFormat = (DoctRendererFormat::FormatFile)(oNode.ReadValueInt(L"SrcFileType"));
m_eDstFormat = (DoctRendererFormat::FormatFile)(oNode.ReadValueInt(L"DstFileType")); m_eDstFormat = (DoctRendererFormat::FormatFile)(oNode.ReadValueInt(L"DstFileType"));
m_strFontsDirectory = oNode.ReadValueString(L"FontsDirectory"); m_strFontsDirectory = oNode.ReadValueString(L"FontsDirectory");
m_strImagesDirectory = oNode.ReadValueString(L"ImagesDirectory"); m_strImagesDirectory = oNode.ReadValueString(L"ImagesDirectory");
m_strThemesDirectory = oNode.ReadValueString(L"ThemesDirectory"); m_strThemesDirectory = oNode.ReadValueString(L"ThemesDirectory");
XmlUtils::CXmlNode oNodeChanges; XmlUtils::CXmlNode oNodeChanges;
if (oNode.GetNode(L"Changes", oNodeChanges)) if (oNode.GetNode(L"Changes", oNodeChanges))
{ {
m_nCountChangesItems = oNodeChanges.ReadAttributeInt(L"TopItem", -1); m_nCountChangesItems = oNodeChanges.ReadAttributeInt(L"TopItem", -1);
XmlUtils::CXmlNodes oNodes; XmlUtils::CXmlNodes oNodes;
oNodeChanges.GetNodes(L"Change", oNodes); oNodeChanges.GetNodes(L"Change", oNodes);
int nCount = oNodes.GetCount(); int nCount = oNodes.GetCount();
for (int i = 0; i < nCount; ++i) for (int i = 0; i < nCount; ++i)
{ {
XmlUtils::CXmlNode _node; XmlUtils::CXmlNode _node;
oNodes.GetAt(i, _node); oNodes.GetAt(i, _node);
m_arChanges.Add(_node.GetText()); m_arChanges.Add(_node.GetText());
} }
} }
XmlUtils::CXmlNode oNodeMailMerge; XmlUtils::CXmlNode oNodeMailMerge;
if (oNode.GetNode(L"MailMergeData", oNodeMailMerge)) if (oNode.GetNode(L"MailMergeData", oNodeMailMerge))
{ {
m_strMailMergeDatabasePath = oNodeMailMerge.ReadAttribute(L"DatabasePath"); m_strMailMergeDatabasePath = oNodeMailMerge.ReadAttribute(L"DatabasePath");
m_nMailMergeIndexStart = oNodeMailMerge.ReadAttributeInt(L"Start", -1); m_nMailMergeIndexStart = oNodeMailMerge.ReadAttributeInt(L"Start", -1);
m_nMailMergeIndexEnd = oNodeMailMerge.ReadAttributeInt(L"End", -1); m_nMailMergeIndexEnd = oNodeMailMerge.ReadAttributeInt(L"End", -1);
m_strMailMergeField = oNodeMailMerge.ReadAttribute(L"Field"); m_strMailMergeField = oNodeMailMerge.ReadAttribute(L"Field");
} }
int nParams = oNode.ReadValueInt(L"DoctParams", 0); int nParams = oNode.ReadValueInt(L"DoctParams", 0);
if (nParams & 0x01) if (nParams & 0x01)
m_bIsRetina = true; m_bIsRetina = true;
if (nParams & 0x02) if (nParams & 0x02)
m_nSaveToPDFParams = 1; m_nSaveToPDFParams = 1;
if (nParams & 0x04) if (nParams & 0x04)
m_bIsCachedScripts = false; m_bIsCachedScripts = false;
m_bIsOnlyOnePage = (oNode.ReadValueInt(L"OnlyOnePage", 0) == 1) ? true : false; m_bIsOnlyOnePage = (oNode.ReadValueInt(L"OnlyOnePage", 0) == 1) ? true : false;
return true; return true;
} }
}; };
} }
void CreateNativeObject(const v8::FunctionCallbackInfo<v8::Value>& args) void CreateNativeObject(const v8::FunctionCallbackInfo<v8::Value>& args)
{ {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Handle<v8::ObjectTemplate> NativeObjectTemplate = CreateNativeControlTemplate(isolate); v8::Handle<v8::ObjectTemplate> NativeObjectTemplate = CreateNativeControlTemplate(isolate);
CNativeControl* pNativeObject = new CNativeControl(); CNativeControl* pNativeObject = new CNativeControl();
v8::Local<v8::Object> obj = NativeObjectTemplate->NewInstance(); v8::Local<v8::Object> obj = NativeObjectTemplate->NewInstance();
obj->SetInternalField(0, v8::External::New(v8::Isolate::GetCurrent(), pNativeObject)); obj->SetInternalField(0, v8::External::New(v8::Isolate::GetCurrent(), pNativeObject));
args.GetReturnValue().Set(obj); args.GetReturnValue().Set(obj);
} }
void CreateNativeObjectBuilder(const v8::FunctionCallbackInfo<v8::Value>& args) void CreateNativeObjectBuilder(const v8::FunctionCallbackInfo<v8::Value>& args)
{ {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Handle<v8::ObjectTemplate> NativeObjectTemplate = CreateNativeControlTemplateBuilder(isolate); v8::Handle<v8::ObjectTemplate> NativeObjectTemplate = CreateNativeControlTemplateBuilder(isolate);
CNativeControl* pNativeObject = new CNativeControl(); CNativeControl* pNativeObject = new CNativeControl();
v8::Local<v8::Object> obj = NativeObjectTemplate->NewInstance(); v8::Local<v8::Object> obj = NativeObjectTemplate->NewInstance();
obj->SetInternalField(0, v8::External::New(v8::Isolate::GetCurrent(), pNativeObject)); obj->SetInternalField(0, v8::External::New(v8::Isolate::GetCurrent(), pNativeObject));
args.GetReturnValue().Set(obj); args.GetReturnValue().Set(obj);
} }
void CreateNativeMemoryStream(const v8::FunctionCallbackInfo<v8::Value>& args) void CreateNativeMemoryStream(const v8::FunctionCallbackInfo<v8::Value>& args)
{ {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Handle<v8::ObjectTemplate> MemoryObjectTemplate = CreateMemoryStreamTemplate(isolate); v8::Handle<v8::ObjectTemplate> MemoryObjectTemplate = CreateMemoryStreamTemplate(isolate);
CMemoryStream* pMemoryObject = new CMemoryStream(); CMemoryStream* pMemoryObject = new CMemoryStream();
v8::Local<v8::Object> obj = MemoryObjectTemplate->NewInstance(); v8::Local<v8::Object> obj = MemoryObjectTemplate->NewInstance();
obj->SetInternalField(0, v8::External::New(v8::Isolate::GetCurrent(), pMemoryObject)); obj->SetInternalField(0, v8::External::New(v8::Isolate::GetCurrent(), pMemoryObject));
args.GetReturnValue().Set(obj); args.GetReturnValue().Set(obj);
} }
namespace NSDoctRenderer namespace NSDoctRenderer
{ {
std::wstring string_replaceAll(std::wstring str, const std::wstring& from, const std::wstring& to) std::wstring string_replaceAll(std::wstring str, const std::wstring& from, const std::wstring& to)
{ {
size_t start_pos = 0; size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::wstring::npos) while((start_pos = str.find(from, start_pos)) != std::wstring::npos)
{ {
str.replace(start_pos, from.length(), to); str.replace(start_pos, from.length(), to);
start_pos += to.length(); start_pos += to.length();
} }
return str; return str;
} }
} }
namespace NSDoctRenderer namespace NSDoctRenderer
{ {
static void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo) static void string_replace(std::wstring& text, const std::wstring& replaceFrom, const std::wstring& replaceTo)
{ {
size_t posn = 0; size_t posn = 0;
while (std::wstring::npos != (posn = text.find(replaceFrom, posn))) while (std::wstring::npos != (posn = text.find(replaceFrom, posn)))
{ {
text.replace(posn, replaceFrom.length(), replaceTo); text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length(); posn += replaceTo.length();
} }
} }
static void replace_for_xml(std::wstring& text) static void replace_for_xml(std::wstring& text)
{ {
string_replace(text, L"&", L"&amp;"); string_replace(text, L"&", L"&amp;");
string_replace(text, L"'", L"&apos;"); string_replace(text, L"'", L"&apos;");
string_replace(text, L"<", L"&lt;"); string_replace(text, L"<", L"&lt;");
string_replace(text, L">", L"&gt;"); string_replace(text, L">", L"&gt;");
string_replace(text, L"\"", L"&quot;"); string_replace(text, L"\"", L"&quot;");
} }
class CDoctRenderer_Private class CDoctRenderer_Private
{ {
public: public:
CExecuteParams m_oParams; CExecuteParams m_oParams;
std::wstring m_strConfigDir; std::wstring m_strConfigDir;
std::wstring m_strConfigPath; std::wstring m_strConfigPath;
CArray<std::wstring> m_arrFiles; CArray<std::wstring> m_arrFiles;
std::vector<std::wstring> m_arDoctSDK; std::vector<std::wstring> m_arDoctSDK;
std::vector<std::wstring> m_arPpttSDK; std::vector<std::wstring> m_arPpttSDK;
std::vector<std::wstring> m_arXlstSDK; std::vector<std::wstring> m_arXlstSDK;
std::wstring m_strEditorType; std::wstring m_strEditorType;
std::wstring m_strFilePath; std::wstring m_strFilePath;
std::vector<std::wstring> m_arImagesInChanges; std::vector<std::wstring> m_arImagesInChanges;
std::wstring m_sConsoleLogFile; std::wstring m_sConsoleLogFile;
std::wstring m_sErrorsLogFile; std::wstring m_sErrorsLogFile;
public: public:
CDoctRenderer_Private(const std::wstring& sAllFontsPath = L"") CDoctRenderer_Private(const std::wstring& sAllFontsPath = L"")
{ {
m_strConfigDir = NSFile::GetProcessDirectory() + L"/"; m_strConfigDir = NSFile::GetProcessDirectory() + L"/";
m_strConfigPath = m_strConfigDir + L"DoctRenderer.config"; m_strConfigPath = m_strConfigDir + L"DoctRenderer.config";
XmlUtils::CXmlNode oNode; XmlUtils::CXmlNode oNode;
if (oNode.FromXmlFile(m_strConfigPath)) if (oNode.FromXmlFile(m_strConfigPath))
{ {
XmlUtils::CXmlNodes oNodes; XmlUtils::CXmlNodes oNodes;
if (oNode.GetNodes(L"file", oNodes)) if (oNode.GetNodes(L"file", oNodes))
{ {
int nCount = oNodes.GetCount(); int nCount = oNodes.GetCount();
XmlUtils::CXmlNode _node; XmlUtils::CXmlNode _node;
for (int i = 0; i < nCount; ++i) for (int i = 0; i < nCount; ++i)
{ {
oNodes.GetAt(i, _node); oNodes.GetAt(i, _node);
std::wstring strFilePath = _node.GetText(); std::wstring strFilePath = _node.GetText();
if (!sAllFontsPath.empty()) if (!sAllFontsPath.empty())
{ {
std::wstring::size_type nPos = strFilePath.rfind(L"AllFonts.js"); std::wstring::size_type nPos = strFilePath.rfind(L"AllFonts.js");
if (nPos != std::wstring::npos && ((nPos + 11) == strFilePath.length())) // 11 = std::wstring(L"AllFonts.js").length(); if (nPos != std::wstring::npos && ((nPos + 11) == strFilePath.length())) // 11 = std::wstring(L"AllFonts.js").length();
strFilePath = sAllFontsPath; strFilePath = sAllFontsPath;
} }
if (NSFile::CFileBinary::Exists(strFilePath) && if (NSFile::CFileBinary::Exists(strFilePath) &&
!NSFile::CFileBinary::Exists(m_strConfigDir + strFilePath)) !NSFile::CFileBinary::Exists(m_strConfigDir + strFilePath))
m_arrFiles.Add(strFilePath); m_arrFiles.Add(strFilePath);
else else
m_arrFiles.Add(m_strConfigDir + strFilePath); m_arrFiles.Add(m_strConfigDir + strFilePath);
} }
} }
} }
XmlUtils::CXmlNode oNodeSdk = oNode.ReadNode(L"DoctSdk"); XmlUtils::CXmlNode oNodeSdk = oNode.ReadNode(L"DoctSdk");
if (oNodeSdk.IsValid()) if (oNodeSdk.IsValid())
LoadSDK_scripts(oNodeSdk, m_arDoctSDK); LoadSDK_scripts(oNodeSdk, m_arDoctSDK);
oNodeSdk = oNode.ReadNode(L"PpttSdk"); oNodeSdk = oNode.ReadNode(L"PpttSdk");
if (oNodeSdk.IsValid()) if (oNodeSdk.IsValid())
LoadSDK_scripts(oNodeSdk, m_arPpttSDK); LoadSDK_scripts(oNodeSdk, m_arPpttSDK);
oNodeSdk = oNode.ReadNode(L"XlstSdk"); oNodeSdk = oNode.ReadNode(L"XlstSdk");
if (oNodeSdk.IsValid()) if (oNodeSdk.IsValid())
LoadSDK_scripts(oNodeSdk, m_arXlstSDK); LoadSDK_scripts(oNodeSdk, m_arXlstSDK);
m_sConsoleLogFile = L""; m_sConsoleLogFile = L"";
m_sErrorsLogFile = L""; m_sErrorsLogFile = L"";
XmlUtils::CXmlNode oNodeConsoleLogFile = oNode.ReadNode(L"LogFileConsoleLog"); XmlUtils::CXmlNode oNodeConsoleLogFile = oNode.ReadNode(L"LogFileConsoleLog");
if (oNodeConsoleLogFile.IsValid()) if (oNodeConsoleLogFile.IsValid())
{ {
m_sConsoleLogFile = oNodeConsoleLogFile.GetText(); m_sConsoleLogFile = oNodeConsoleLogFile.GetText();
if (!NSFile::CFileBinary::Exists(m_sConsoleLogFile)) if (!NSFile::CFileBinary::Exists(m_sConsoleLogFile))
m_sConsoleLogFile = m_strConfigDir + m_sConsoleLogFile; m_sConsoleLogFile = m_strConfigDir + m_sConsoleLogFile;
} }
XmlUtils::CXmlNode oNodeErrorsLogFile = oNode.ReadNode(L"LogFileErrors"); XmlUtils::CXmlNode oNodeErrorsLogFile = oNode.ReadNode(L"LogFileErrors");
if (oNodeErrorsLogFile.IsValid()) if (oNodeErrorsLogFile.IsValid())
{ {
m_sErrorsLogFile = oNodeErrorsLogFile.GetText(); m_sErrorsLogFile = oNodeErrorsLogFile.GetText();
if (!NSFile::CFileBinary::Exists(m_sErrorsLogFile)) if (!NSFile::CFileBinary::Exists(m_sErrorsLogFile))
m_sErrorsLogFile = m_strConfigDir + m_sErrorsLogFile; m_sErrorsLogFile = m_strConfigDir + m_sErrorsLogFile;
} }
} }
~CDoctRenderer_Private() ~CDoctRenderer_Private()
{ {
} }
void LoadSDK_scripts(XmlUtils::CXmlNode& oNode, std::vector<std::wstring>& _files) void LoadSDK_scripts(XmlUtils::CXmlNode& oNode, std::vector<std::wstring>& _files)
{ {
XmlUtils::CXmlNodes oNodes; XmlUtils::CXmlNodes oNodes;
if (oNode.GetNodes(L"file", oNodes)) if (oNode.GetNodes(L"file", oNodes))
{ {
int nCount = oNodes.GetCount(); int nCount = oNodes.GetCount();
XmlUtils::CXmlNode _node; XmlUtils::CXmlNode _node;
for (int i = 0; i < nCount; ++i) for (int i = 0; i < nCount; ++i)
{ {
oNodes.GetAt(i, _node); oNodes.GetAt(i, _node);
std::wstring strFilePath = _node.GetText(); std::wstring strFilePath = _node.GetText();
if (NSFile::CFileBinary::Exists(strFilePath) && if (NSFile::CFileBinary::Exists(strFilePath) &&
!NSFile::CFileBinary::Exists(m_strConfigDir + strFilePath)) !NSFile::CFileBinary::Exists(m_strConfigDir + strFilePath))
_files.push_back(strFilePath); _files.push_back(strFilePath);
else else
_files.push_back(m_strConfigDir + strFilePath); _files.push_back(m_strConfigDir + strFilePath);
} }
} }
else else
{ {
std::wstring strFilePath = oNode.GetText(); std::wstring strFilePath = oNode.GetText();
if (NSFile::CFileBinary::Exists(strFilePath) && if (NSFile::CFileBinary::Exists(strFilePath) &&
!NSFile::CFileBinary::Exists(m_strConfigDir + strFilePath)) !NSFile::CFileBinary::Exists(m_strConfigDir + strFilePath))
_files.push_back(strFilePath); _files.push_back(strFilePath);
else else
_files.push_back(m_strConfigDir + strFilePath); _files.push_back(m_strConfigDir + strFilePath);
} }
} }
public: public:
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError) static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
{ {
#if 0 #if 0
if (m_sErrorsLogFile.empty()) if (m_sErrorsLogFile.empty())
return; return;
FILE* f = NSFile::CFileBinary::OpenFileNative(m_sErrorsLogFile, L"a+"); FILE* f = NSFile::CFileBinary::OpenFileNative(m_sErrorsLogFile, L"a+");
std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType); std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType);
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError); std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError);
fprintf(f, sT.c_str()); fprintf(f, sT.c_str());
fprintf(f, ": "); fprintf(f, ": ");
fprintf(f, sE.c_str()); fprintf(f, sE.c_str());
fprintf(f, "\n"); fprintf(f, "\n");
fclose(f); fclose(f);
#endif #endif
std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType); std::string sT = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strType);
std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError); std::string sE = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(strError);
std::cerr << sT << ": " << sE << std::endl; std::cerr << sT << ": " << sE << std::endl;
} }
static bool Doct_renderer_SaveFile(CExecuteParams* pParams, static bool Doct_renderer_SaveFile(CExecuteParams* pParams,
CNativeControl* pNative, CNativeControl* pNative,
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Local<v8::Object>& global_js, v8::Local<v8::Object>& global_js,
v8::Handle<v8::Value>* args, v8::Handle<v8::Value>* args,
v8::TryCatch& try_catch, v8::TryCatch& try_catch,
std::wstring& strError, std::wstring& strError,
bool bIsPdfBase64 = false) bool bIsPdfBase64 = false)
{ {
bool bIsBreak = false; bool bIsBreak = false;
switch (pParams->m_eDstFormat) switch (pParams->m_eDstFormat)
{ {
case DoctRendererFormat::DOCT: case DoctRendererFormat::DOCT:
case DoctRendererFormat::PPTT: case DoctRendererFormat::PPTT:
case DoctRendererFormat::XLST: case DoctRendererFormat::XLST:
{ {
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileData")); v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileData"));
if (js_func_get_file_s->IsFunction()) if (js_func_get_file_s->IsFunction())
{ {
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s); 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); v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
if (try_catch.HasCaught()) if (try_catch.HasCaught())
{ {
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); std::wstring strException = to_cstring(try_catch.Message()->Get());
_LOGGING_ERROR_(L"save_code", strCode); _LOGGING_ERROR_(L"save_code", strCode);
_LOGGING_ERROR_(L"save", strException); _LOGGING_ERROR_(L"save", strException);
strError = L"code=\"save\""; strError = L"code=\"save\"";
bIsBreak = true; bIsBreak = true;
} }
else else
{ {
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2); v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data(); BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
NSFile::CFileBinary oFile; NSFile::CFileBinary oFile;
if (true == oFile.CreateFileW(pParams->m_strDstFilePath)) if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
{ {
oFile.WriteFile((BYTE*)pNative->m_sHeader.c_str(), (DWORD)pNative->m_sHeader.length()); if (pNative->m_sHeader.find(";v10;") == std::string::npos)
{
char* pDst64 = NULL; oFile.WriteFile((BYTE*)pNative->m_sHeader.c_str(), (DWORD)pNative->m_sHeader.length());
int nDstLen = 0;
NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDst64, nDstLen, NSBase64::B64_BASE64_FLAG_NOCRLF); char* pDst64 = NULL;
int nDstLen = 0;
oFile.WriteFile((BYTE*)pDst64, (DWORD)nDstLen); NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDst64, nDstLen, NSBase64::B64_BASE64_FLAG_NOCRLF);
RELEASEARRAYOBJECTS(pDst64); oFile.WriteFile((BYTE*)pDst64, (DWORD)nDstLen);
oFile.CloseFile();
} RELEASEARRAYOBJECTS(pDst64);
} }
} else
break; {
} oFile.WriteFile(pData, (DWORD)pNative->m_nSaveBinaryLen);
case DoctRendererFormat::HTML: }
{ oFile.CloseFile();
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileDataHtml")); }
if (js_func_get_file_s->IsFunction()) }
{ }
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s); break;
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args); }
case DoctRendererFormat::HTML:
if (try_catch.HasCaught()) {
{ v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetFileDataHtml"));
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); if (js_func_get_file_s->IsFunction())
std::wstring 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);
_LOGGING_ERROR_(L"save_code", strCode); v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
_LOGGING_ERROR_(L"save", strException);
if (try_catch.HasCaught())
strError = L"code=\"save\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
else
{ _LOGGING_ERROR_(L"save_code", strCode);
std::string sHTML_Utf8 = to_cstringA(js_result2); _LOGGING_ERROR_(L"save", strException);
NSFile::CFileBinary oFile; strError = L"code=\"save\"";
if (true == oFile.CreateFileW(pParams->m_strDstFilePath)) bIsBreak = true;
{ }
oFile.WriteFile((BYTE*)sHTML_Utf8.c_str(), (DWORD)sHTML_Utf8.length()); else
oFile.CloseFile(); {
} std::string sHTML_Utf8 = to_cstringA(js_result2);
}
} NSFile::CFileBinary oFile;
break; if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
} {
case DoctRendererFormat::PDF: oFile.WriteFile((BYTE*)sHTML_Utf8.c_str(), (DWORD)sHTML_Utf8.length());
{ oFile.CloseFile();
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_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeFileDataPDF")); }
break;
// CALCULATE }
if (js_func_calculate->IsFunction()) case DoctRendererFormat::PDF:
{ {
v8::Handle<v8::Function> func_calculate = v8::Handle<v8::Function>::Cast(js_func_calculate); v8::Handle<v8::Value> js_func_calculate = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeCalculateFile"));
func_calculate->Call(global_js, 1, args); v8::Handle<v8::Value> js_func_pages_count = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeCountPages"));
v8::Handle<v8::Value> js_func_get_file_s = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeFileDataPDF"));
if (try_catch.HasCaught())
{ // CALCULATE
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); if (js_func_calculate->IsFunction())
std::wstring strException = to_cstring(try_catch.Message()->Get()); {
v8::Handle<v8::Function> func_calculate = v8::Handle<v8::Function>::Cast(js_func_calculate);
_LOGGING_ERROR_(L"calculate_code", strCode); func_calculate->Call(global_js, 1, args);
_LOGGING_ERROR_(L"calculate", strException);
if (try_catch.HasCaught())
strError = L"code=\"calculate\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
}
_LOGGING_ERROR_(L"calculate_code", strCode);
_LOGGING_ERROR_(L"calculate", strException);
LONG lPagesCount = 0;
strError = L"code=\"calculate\"";
// PAGESCOUNT bIsBreak = true;
if (!bIsBreak) }
{ }
if (js_func_pages_count->IsFunction())
{
v8::Handle<v8::Function> func_pages_count = v8::Handle<v8::Function>::Cast(js_func_pages_count); LONG lPagesCount = 0;
v8::Local<v8::Value> js_result1 = func_pages_count->Call(global_js, 1, args);
// PAGESCOUNT
if (try_catch.HasCaught()) if (!bIsBreak)
{ {
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); if (js_func_pages_count->IsFunction())
std::wstring strException = to_cstring(try_catch.Message()->Get()); {
v8::Handle<v8::Function> func_pages_count = v8::Handle<v8::Function>::Cast(js_func_pages_count);
_LOGGING_ERROR_(L"calculate_code", strCode); v8::Local<v8::Value> js_result1 = func_pages_count->Call(global_js, 1, args);
_LOGGING_ERROR_(L"calculate", strException);
if (try_catch.HasCaught())
strError = L"code=\"calculate\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
else
{ _LOGGING_ERROR_(L"calculate_code", strCode);
v8::Local<v8::Int32> intValue = js_result1->ToInt32(); _LOGGING_ERROR_(L"calculate", strException);
lPagesCount = (LONG)intValue->Value();
} strError = L"code=\"calculate\"";
} bIsBreak = true;
} }
else
// RENDER {
if (!bIsBreak) v8::Local<v8::Int32> intValue = js_result1->ToInt32();
{ lPagesCount = (LONG)intValue->Value();
if (js_func_get_file_s->IsFunction()) }
{ }
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s); }
int nArgument = pParams->m_nSaveToPDFParams;
if (pParams->m_bIsOnlyOnePage) // RENDER
nArgument |= 0x0100; if (!bIsBreak)
args[0] = v8::Int32::New(isolate, nArgument); {
if (js_func_get_file_s->IsFunction())
v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args); {
v8::Handle<v8::Function> func_get_file_s = v8::Handle<v8::Function>::Cast(js_func_get_file_s);
if (try_catch.HasCaught()) int nArgument = pParams->m_nSaveToPDFParams;
{ if (pParams->m_bIsOnlyOnePage)
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); nArgument |= 0x0100;
std::wstring strException = to_cstring(try_catch.Message()->Get()); args[0] = v8::Int32::New(isolate, nArgument);
_LOGGING_ERROR_(L"save_code", strCode); v8::Local<v8::Value> js_result2 = func_get_file_s->Call(global_js, 1, args);
_LOGGING_ERROR_(L"save", strException);
if (try_catch.HasCaught())
strError = L"code=\"save\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
else
{ _LOGGING_ERROR_(L"save_code", strCode);
v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2); _LOGGING_ERROR_(L"save", strException);
BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
strError = L"code=\"save\"";
NSFile::CFileBinary oFile; bIsBreak = true;
if (true == oFile.CreateFileW(pParams->m_strDstFilePath)) }
{ else
if (!bIsPdfBase64) {
{ v8::Local<v8::Uint8Array> pArray = v8::Local<v8::Uint8Array>::Cast(js_result2);
oFile.WriteFile(pData, (DWORD)pNative->m_nSaveBinaryLen); BYTE* pData = (BYTE*)pArray->Buffer()->Externalize().Data();
}
else NSFile::CFileBinary oFile;
{ if (true == oFile.CreateFileW(pParams->m_strDstFilePath))
char* pDataDst = NULL; {
int nDataDst = 0; if (!bIsPdfBase64)
if (NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDataDst, nDataDst)) {
{ oFile.WriteFile(pData, (DWORD)pNative->m_nSaveBinaryLen);
oFile.WriteFile((BYTE*)pDataDst, (DWORD)nDataDst); }
RELEASEARRAYOBJECTS(pDataDst); else
} {
char* pDataDst = NULL;
} int nDataDst = 0;
oFile.CloseFile(); if (NSFile::CBase64Converter::Encode(pData, pNative->m_nSaveBinaryLen, pDataDst, nDataDst))
} {
} oFile.WriteFile((BYTE*)pDataDst, (DWORD)nDataDst);
} RELEASEARRAYOBJECTS(pDataDst);
} }
break;
} }
default: oFile.CloseFile();
break; }
} }
return bIsBreak; }
} }
break;
}
bool ExecuteScript(const std::string& strScript, const std::wstring& sCachePath, std::wstring& strError, std::wstring& strReturnParams) default:
{ break;
bool bIsBreak = false; }
v8::Isolate* isolate = CV8Worker::getInitializer()->CreateNew(); return bIsBreak;
if (true) }
{
v8::Isolate::Scope isolate_cope(isolate);
v8::Locker isolate_locker(isolate); bool ExecuteScript(const std::string& strScript, const std::wstring& sCachePath, std::wstring& strError, std::wstring& strReturnParams)
{
v8::HandleScope handle_scope(isolate); bool bIsBreak = false;
v8::Isolate* isolate = CV8Worker::getInitializer()->CreateNew();
v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); if (true)
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::Isolate::Scope isolate_cope(isolate);
v8::Locker isolate_locker(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
v8::HandleScope handle_scope(isolate);
v8::Context::Scope context_scope(context);
v8::TryCatch try_catch; v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, strScript.c_str()); global->Set(v8::String::NewFromUtf8(isolate, "CreateNativeEngine"), v8::FunctionTemplate::New(isolate, CreateNativeObject));
v8::Local<v8::Script> script; global->Set(v8::String::NewFromUtf8(isolate, "CreateNativeMemoryStream"), v8::FunctionTemplate::New(isolate, CreateNativeMemoryStream));
CCacheDataScript oCachedScript(sCachePath); v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global);
if (sCachePath.empty())
script = v8::Script::Compile(source); v8::Context::Scope context_scope(context);
else v8::TryCatch try_catch;
{ v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, strScript.c_str());
script = oCachedScript.Compile(context, source); v8::Local<v8::Script> script;
}
CCacheDataScript oCachedScript(sCachePath);
// COMPILE if (sCachePath.empty())
if (try_catch.HasCaught()) script = v8::Script::Compile(source);
{ else
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); {
std::wstring strException = to_cstring(try_catch.Message()->Get()); script = oCachedScript.Compile(context, source);
}
_LOGGING_ERROR_(L"compile_code", strCode);
_LOGGING_ERROR_(L"compile", strException); // COMPILE
if (try_catch.HasCaught())
strError = L"code=\"compile\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
// RUN _LOGGING_ERROR_(L"compile_code", strCode);
if (!bIsBreak) _LOGGING_ERROR_(L"compile", strException);
{
v8::Local<v8::Value> result = script->Run(); strError = L"code=\"compile\"";
bIsBreak = true;
if (try_catch.HasCaught()) }
{
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); // RUN
std::wstring strException = to_cstring(try_catch.Message()->Get()); if (!bIsBreak)
{
_LOGGING_ERROR_(L"run_code", strCode); v8::Local<v8::Value> result = script->Run();
_LOGGING_ERROR_(L"run", strException);
if (try_catch.HasCaught())
strError = L"code=\"run\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
}
_LOGGING_ERROR_(L"run_code", strCode);
if (!bIsBreak && m_oParams.m_bIsRetina) _LOGGING_ERROR_(L"run", strException);
{
v8::Local<v8::String> sourceParams = v8::String::NewFromUtf8(isolate, strError = L"code=\"run\"";
"(function(){ if (window && window.SetDoctRendererParams) {window.SetDoctRendererParams({retina:true});} })();"); bIsBreak = true;
v8::Local<v8::Script> scriptParams = v8::Script::Compile(sourceParams); }
scriptParams->Run(); }
}
if (!bIsBreak && m_oParams.m_bIsRetina)
//--------------------------------------------------------------- {
v8::Local<v8::Object> global_js = context->Global(); v8::Local<v8::String> sourceParams = v8::String::NewFromUtf8(isolate,
v8::Handle<v8::Value> args[1]; "(function(){ if (window && window.SetDoctRendererParams) {window.SetDoctRendererParams({retina:true});} })();");
args[0] = v8::Int32::New(isolate, 0); v8::Local<v8::Script> scriptParams = v8::Script::Compile(sourceParams);
scriptParams->Run();
CNativeControl* pNative = NULL; }
// GET_NATIVE_ENGINE //---------------------------------------------------------------
if (!bIsBreak) v8::Local<v8::Object> global_js = context->Global();
{ v8::Handle<v8::Value> args[1];
v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeEngine")); args[0] = v8::Int32::New(isolate, 0);
v8::Local<v8::Object> objNative;
if (js_func_get_native->IsFunction()) CNativeControl* pNative = NULL;
{
v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native); // GET_NATIVE_ENGINE
v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args); if (!bIsBreak)
{
if (try_catch.HasCaught()) v8::Handle<v8::Value> js_func_get_native = global_js->Get(v8::String::NewFromUtf8(isolate, "GetNativeEngine"));
{ v8::Local<v8::Object> objNative;
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); if (js_func_get_native->IsFunction())
std::wstring strException = to_cstring(try_catch.Message()->Get()); {
v8::Handle<v8::Function> func_get_native = v8::Handle<v8::Function>::Cast(js_func_get_native);
_LOGGING_ERROR_(L"run_code", strCode); v8::Local<v8::Value> js_result2 = func_get_native->Call(global_js, 1, args);
_LOGGING_ERROR_(L"run", strException);
if (try_catch.HasCaught())
strError = L"code=\"run\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
else
{ _LOGGING_ERROR_(L"run_code", strCode);
objNative = js_result2->ToObject(); _LOGGING_ERROR_(L"run", strException);
v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0));
strError = L"code=\"run\"";
pNative = static_cast<CNativeControl*>(field->Value()); bIsBreak = true;
pNative->m_sConsoleLogFile = m_sConsoleLogFile; }
} else
} {
} objNative = js_result2->ToObject();
v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(objNative->GetInternalField(0));
if (pNative != NULL)
{ pNative = static_cast<CNativeControl*>(field->Value());
pNative->m_pChanges = &m_oParams.m_arChanges; pNative->m_sConsoleLogFile = m_sConsoleLogFile;
pNative->m_strFontsDirectory = m_oParams.m_strFontsDirectory; }
pNative->m_strImagesDirectory = m_oParams.m_strImagesDirectory; }
}
pNative->CheckFonts();
if (pNative != NULL)
pNative->m_strEditorType = m_strEditorType; {
pNative->SetFilePath(m_strFilePath); pNative->m_pChanges = &m_oParams.m_arChanges;
pNative->m_strFontsDirectory = m_oParams.m_strFontsDirectory;
pNative->m_nMaxChangesNumber = m_oParams.m_nCountChangesItems; pNative->m_strImagesDirectory = m_oParams.m_strImagesDirectory;
}
pNative->CheckFonts();
// OPEN
if (!bIsBreak) pNative->m_strEditorType = m_strEditorType;
{ pNative->SetFilePath(m_strFilePath);
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeOpenFileData"));
if (js_func_open->IsFunction()) pNative->m_nMaxChangesNumber = m_oParams.m_nCountChangesItems;
{ }
v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
// OPEN
CChangesWorker oWorkerLoader; if (!bIsBreak)
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath()); {
v8::Handle<v8::Value> js_func_open = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeOpenFileData"));
v8::Handle<v8::Value> args_open[2]; if (js_func_open->IsFunction())
args_open[0] = oWorkerLoader.GetDataFull(); {
args_open[1] = v8::Integer::New(isolate, nVersion); v8::Handle<v8::Function> func_open = v8::Handle<v8::Function>::Cast(js_func_open);
func_open->Call(global_js, 2, args_open); CChangesWorker oWorkerLoader;
int nVersion = oWorkerLoader.OpenNative(pNative->GetFilePath());
if (try_catch.HasCaught())
{ v8::Handle<v8::Value> args_open[2];
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); args_open[0] = oWorkerLoader.GetDataFull();
std::wstring strException = to_cstring(try_catch.Message()->Get()); args_open[1] = v8::Integer::New(isolate, nVersion);
_LOGGING_ERROR_(L"open_code", strCode); func_open->Call(global_js, 2, args_open);
_LOGGING_ERROR_(L"open", strException);
if (try_catch.HasCaught())
strError = L"code=\"open\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
}
} _LOGGING_ERROR_(L"open_code", strCode);
_LOGGING_ERROR_(L"open", strException);
// CHANGES
if (!bIsBreak) strError = L"code=\"open\"";
{ bIsBreak = true;
v8::Handle<v8::Value> js_func_apply_changes = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeApplyChangesData")); }
if (m_oParams.m_arChanges.GetCount() != 0) }
{ }
int nCurrentIndex = 0;
CChangesWorker oWorker; // CHANGES
if (!bIsBreak)
int nFileType = 0; {
if (m_strEditorType == L"spreadsheet") v8::Handle<v8::Value> js_func_apply_changes = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeApplyChangesData"));
nFileType = 1; if (m_oParams.m_arChanges.GetCount() != 0)
{
oWorker.SetFormatChanges(nFileType); int nCurrentIndex = 0;
oWorker.CheckFiles(m_oParams.m_arChanges); CChangesWorker oWorker;
while (!bIsBreak) int nFileType = 0;
{ if (m_strEditorType == L"spreadsheet")
nCurrentIndex = oWorker.Open(m_oParams.m_arChanges, nCurrentIndex); nFileType = 1;
bool bIsFull = (nCurrentIndex == m_oParams.m_arChanges.GetCount()) ? true : false;
oWorker.SetFormatChanges(nFileType);
if (js_func_apply_changes->IsFunction()) oWorker.CheckFiles(m_oParams.m_arChanges);
{
v8::Handle<v8::Function> func_apply_changes = v8::Handle<v8::Function>::Cast(js_func_apply_changes); while (!bIsBreak)
v8::Handle<v8::Value> args_changes[2]; {
args_changes[0] = oWorker.GetData(); nCurrentIndex = oWorker.Open(m_oParams.m_arChanges, nCurrentIndex);
args_changes[1] = v8::Boolean::New(isolate, bIsFull); bool bIsFull = (nCurrentIndex == m_oParams.m_arChanges.GetCount()) ? true : false;
func_apply_changes->Call(global_js, 2, args_changes); if (js_func_apply_changes->IsFunction())
{
if (try_catch.HasCaught()) v8::Handle<v8::Function> func_apply_changes = v8::Handle<v8::Function>::Cast(js_func_apply_changes);
{ v8::Handle<v8::Value> args_changes[2];
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); args_changes[0] = oWorker.GetData();
std::wstring strException = to_cstring(try_catch.Message()->Get()); args_changes[1] = v8::Boolean::New(isolate, bIsFull);
_LOGGING_ERROR_(L"change_code", strCode); func_apply_changes->Call(global_js, 2, args_changes);
_LOGGING_ERROR_(L"change", strException);
if (try_catch.HasCaught())
char buffer[50]; {
sprintf(buffer, "index=\"%d\"", pNative->m_nCurrentChangesNumber - 1); std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::string s(buffer); std::wstring strException = to_cstring(try_catch.Message()->Get());
strError = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)s.c_str(), (LONG)s.length());
bIsBreak = true; _LOGGING_ERROR_(L"change_code", strCode);
} _LOGGING_ERROR_(L"change", strException);
}
char buffer[50];
if (bIsFull) sprintf(buffer, "index=\"%d\"", pNative->m_nCurrentChangesNumber - 1);
break; std::string s(buffer);
} strError = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)s.c_str(), (LONG)s.length());
bIsBreak = true;
// images in changes }
if (NULL != pNative) }
{
for (std::map<std::wstring, bool>::const_iterator iter = pNative->m_mapImagesInChanges.begin(); if (bIsFull)
iter != pNative->m_mapImagesInChanges.end(); iter++) break;
{ }
m_arImagesInChanges.push_back(iter->first);
} // images in changes
} if (NULL != pNative)
} {
} for (std::map<std::wstring, bool>::const_iterator iter = pNative->m_mapImagesInChanges.begin();
iter != pNative->m_mapImagesInChanges.end(); iter++)
bool bIsMailMerge = false; {
if (!m_oParams.m_strMailMergeDatabasePath.empty() && m_arImagesInChanges.push_back(iter->first);
m_oParams.m_nMailMergeIndexEnd >= m_oParams.m_nMailMergeIndexStart && }
m_oParams.m_nMailMergeIndexEnd >= 0) }
{ }
bIsMailMerge = true; }
}
bool bIsMailMerge = false;
// MAIL MERGE if (!m_oParams.m_strMailMergeDatabasePath.empty() &&
if (!bIsBreak) m_oParams.m_nMailMergeIndexEnd >= m_oParams.m_nMailMergeIndexStart &&
{ m_oParams.m_nMailMergeIndexEnd >= 0)
if (bIsMailMerge) {
{ bIsMailMerge = true;
// OPEN DATABASE }
NSFile::CFileBinary oFileDataBase;
if (oFileDataBase.OpenFile(m_oParams.m_strMailMergeDatabasePath)) // MAIL MERGE
{ if (!bIsBreak)
DWORD dwSizeBase = (DWORD)oFileDataBase.GetFileSize(); {
DWORD dwSizeRead = 0; if (bIsMailMerge)
BYTE* pBaseData = new BYTE[dwSizeBase + 1]; {
oFileDataBase.ReadFile(pBaseData, dwSizeBase, dwSizeRead); // OPEN DATABASE
NSFile::CFileBinary oFileDataBase;
if (dwSizeBase != dwSizeRead) if (oFileDataBase.OpenFile(m_oParams.m_strMailMergeDatabasePath))
{ {
RELEASEARRAYOBJECTS(pBaseData); DWORD dwSizeBase = (DWORD)oFileDataBase.GetFileSize();
bIsBreak = true; DWORD dwSizeRead = 0;
BYTE* pBaseData = new BYTE[dwSizeBase + 1];
strError = L"mailmerge=\"databaseopen\""; oFileDataBase.ReadFile(pBaseData, dwSizeBase, dwSizeRead);
}
else if (dwSizeBase != dwSizeRead)
{ {
int nStart = 0; RELEASEARRAYOBJECTS(pBaseData);
if (dwSizeBase > 3) bIsBreak = true;
{
if (pBaseData[0] == 0xEF && pBaseData[1] == 0xBB && pBaseData[2] == 0xBF) strError = L"mailmerge=\"databaseopen\"";
{ }
nStart = 3; else
} {
} int nStart = 0;
if (dwSizeBase > 3)
pBaseData[dwSizeBase] = 0; {
v8::Handle<v8::Value> js_func_mm_start = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeStartMailMergeByList")); if (pBaseData[0] == 0xEF && pBaseData[1] == 0xBB && pBaseData[2] == 0xBF)
{
if (js_func_mm_start->IsFunction()) nStart = 3;
{ }
v8::Handle<v8::Function> func_mm_start = v8::Handle<v8::Function>::Cast(js_func_mm_start); }
v8::Handle<v8::Value> args_changes[1];
pBaseData[dwSizeBase] = 0;
args_changes[0] = v8::JSON::Parse(v8::String::NewFromUtf8(isolate, (char*)(pBaseData + nStart))); v8::Handle<v8::Value> js_func_mm_start = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeStartMailMergeByList"));
if (try_catch.HasCaught()) if (js_func_mm_start->IsFunction())
{ {
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); v8::Handle<v8::Function> func_mm_start = v8::Handle<v8::Function>::Cast(js_func_mm_start);
std::wstring strException = to_cstring(try_catch.Message()->Get()); v8::Handle<v8::Value> args_changes[1];
_LOGGING_ERROR_(L"change_code", strCode); args_changes[0] = v8::JSON::Parse(v8::String::NewFromUtf8(isolate, (char*)(pBaseData + nStart)));
_LOGGING_ERROR_(L"change", strException);
if (try_catch.HasCaught())
strError = L"mailmerge=\"databaseopenjs\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
//args_changes[0] = v8::String::NewFromUtf8(isolate, (char*)(pBaseData + nStart)); _LOGGING_ERROR_(L"change_code", strCode);
_LOGGING_ERROR_(L"change", strException);
func_mm_start->Call(global_js, 1, args_changes);
strError = L"mailmerge=\"databaseopenjs\"";
if (try_catch.HasCaught()) bIsBreak = true;
{ }
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
std::wstring strException = to_cstring(try_catch.Message()->Get()); //args_changes[0] = v8::String::NewFromUtf8(isolate, (char*)(pBaseData + nStart));
_LOGGING_ERROR_(L"change_code", strCode); func_mm_start->Call(global_js, 1, args_changes);
_LOGGING_ERROR_(L"change", strException);
if (try_catch.HasCaught())
strError = L"mailmerge=\"databaseopenjs\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
}
} _LOGGING_ERROR_(L"change_code", strCode);
} _LOGGING_ERROR_(L"change", strException);
else
{ strError = L"mailmerge=\"databaseopenjs\"";
strError = L"mailmerge=\"databaseopen\""; bIsBreak = true;
bIsBreak = true; }
} }
}
if (!bIsBreak) }
{ else
std::string sFieldUtf8 = NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(m_oParams.m_strMailMergeField.c_str(), {
(LONG)m_oParams.m_strMailMergeField.length()); strError = L"mailmerge=\"databaseopen\"";
bIsBreak = true;
strReturnParams += L"<MailMergeFields>"; }
for (int nIndexMM = m_oParams.m_nMailMergeIndexStart; nIndexMM <= m_oParams.m_nMailMergeIndexEnd && !bIsBreak; ++nIndexMM)
{ if (!bIsBreak)
v8::Handle<v8::Value> js_func_mm_preview = global_js->Get(v8::String::NewFromUtf8(isolate, "NativePreviewMailMergeResult")); {
std::string sFieldUtf8 = NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(m_oParams.m_strMailMergeField.c_str(),
if (js_func_mm_preview->IsFunction()) (LONG)m_oParams.m_strMailMergeField.length());
{
v8::Handle<v8::Function> func_mm_preview = v8::Handle<v8::Function>::Cast(js_func_mm_preview); strReturnParams += L"<MailMergeFields>";
v8::Handle<v8::Value> args_changes[1]; for (int nIndexMM = m_oParams.m_nMailMergeIndexStart; nIndexMM <= m_oParams.m_nMailMergeIndexEnd && !bIsBreak; ++nIndexMM)
args_changes[0] = v8::Integer::New(v8::Isolate::GetCurrent(), nIndexMM); {
v8::Handle<v8::Value> js_func_mm_preview = global_js->Get(v8::String::NewFromUtf8(isolate, "NativePreviewMailMergeResult"));
func_mm_preview->Call(global_js, 1, args_changes);
if (js_func_mm_preview->IsFunction())
if (try_catch.HasCaught()) {
{ v8::Handle<v8::Function> func_mm_preview = v8::Handle<v8::Function>::Cast(js_func_mm_preview);
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); v8::Handle<v8::Value> args_changes[1];
std::wstring strException = to_cstring(try_catch.Message()->Get()); args_changes[0] = v8::Integer::New(v8::Isolate::GetCurrent(), nIndexMM);
_LOGGING_ERROR_(L"change_code", strCode); func_mm_preview->Call(global_js, 1, args_changes);
_LOGGING_ERROR_(L"change", strException);
if (try_catch.HasCaught())
strError = L"mailmerge=\"preview" + std::to_wstring(nIndexMM) + L"\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
}
_LOGGING_ERROR_(L"change_code", strCode);
std::wstring sSaveFile = L""; _LOGGING_ERROR_(L"change", strException);
if (!bIsBreak)
{ strError = L"mailmerge=\"preview" + std::to_wstring(nIndexMM) + L"\"";
// SAVE bIsBreak = true;
std::wstring sSaveOld = m_oParams.m_strDstFilePath; }
m_oParams.m_strDstFilePath += (L"/file" + std::to_wstring(nIndexMM)); }
sSaveFile = m_oParams.m_strDstFilePath;
std::wstring sSaveFile = L"";
bIsBreak = Doct_renderer_SaveFile(&m_oParams, pNative, isolate, global_js, if (!bIsBreak)
args, try_catch, strError); {
// SAVE
m_oParams.m_strDstFilePath = sSaveOld; std::wstring sSaveOld = m_oParams.m_strDstFilePath;
} m_oParams.m_strDstFilePath += (L"/file" + std::to_wstring(nIndexMM));
sSaveFile = m_oParams.m_strDstFilePath;
if (!bIsBreak)
{ bIsBreak = Doct_renderer_SaveFile(&m_oParams, pNative, isolate, global_js,
v8::Handle<v8::Value> js_func_mm_field = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetMailMergeFiledValue")); args, try_catch, strError);
if (js_func_mm_field->IsFunction()) m_oParams.m_strDstFilePath = sSaveOld;
{ }
v8::Handle<v8::Function> func_mm_field = v8::Handle<v8::Function>::Cast(js_func_mm_field);
v8::Handle<v8::Value> args_changes[2]; if (!bIsBreak)
args_changes[0] = v8::Integer::New(v8::Isolate::GetCurrent(), nIndexMM); {
args_changes[1] = v8::String::NewFromUtf8(isolate, (char*)sFieldUtf8.c_str()); v8::Handle<v8::Value> js_func_mm_field = global_js->Get(v8::String::NewFromUtf8(isolate, "NativeGetMailMergeFiledValue"));
v8::Local<v8::Value> js_result2 = func_mm_field->Call(global_js, 2, args_changes); if (js_func_mm_field->IsFunction())
{
if (try_catch.HasCaught()) v8::Handle<v8::Function> func_mm_field = v8::Handle<v8::Function>::Cast(js_func_mm_field);
{ v8::Handle<v8::Value> args_changes[2];
std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine()); args_changes[0] = v8::Integer::New(v8::Isolate::GetCurrent(), nIndexMM);
std::wstring strException = to_cstring(try_catch.Message()->Get()); args_changes[1] = v8::String::NewFromUtf8(isolate, (char*)sFieldUtf8.c_str());
_LOGGING_ERROR_(L"change_code", strCode); v8::Local<v8::Value> js_result2 = func_mm_field->Call(global_js, 2, args_changes);
_LOGGING_ERROR_(L"change", strException);
if (try_catch.HasCaught())
strError = L"mailmerge=\"field" + std::to_wstring(nIndexMM) + L"\""; {
bIsBreak = true; std::wstring strCode = to_cstring(try_catch.Message()->GetSourceLine());
} std::wstring strException = to_cstring(try_catch.Message()->Get());
std::wstring sField = to_cstring(js_result2); _LOGGING_ERROR_(L"change_code", strCode);
NSDoctRenderer::replace_for_xml(sField); _LOGGING_ERROR_(L"change", strException);
NSDoctRenderer::replace_for_xml(sSaveFile);
strError = L"mailmerge=\"field" + std::to_wstring(nIndexMM) + L"\"";
strReturnParams += L"<file path=\"" + sSaveFile + L"\" field=\"" + sField + L"\" />"; bIsBreak = true;
} }
}
} std::wstring sField = to_cstring(js_result2);
strReturnParams += L"</MailMergeFields>"; NSDoctRenderer::replace_for_xml(sField);
} NSDoctRenderer::replace_for_xml(sSaveFile);
}
} strReturnParams += L"<file path=\"" + sSaveFile + L"\" field=\"" + sField + L"\" />";
}
// SAVE }
if (!bIsBreak && !bIsMailMerge) }
{ strReturnParams += L"</MailMergeFields>";
bIsBreak = Doct_renderer_SaveFile(&m_oParams, pNative, isolate, global_js, args, try_catch, strError); }
} }
} }
isolate->Dispose(); // SAVE
if (!bIsBreak && !bIsMailMerge)
// теперь вызываем это в x2t {
//CV8Worker::Dispose(); bIsBreak = Doct_renderer_SaveFile(&m_oParams, pNative, isolate, global_js, args, try_catch, strError);
}
return bIsBreak ? false : true; }
}
isolate->Dispose();
std::string ReadScriptFile(const std::wstring& strFile)
{ // теперь вызываем это в x2t
NSFile::CFileBinary oFile; //CV8Worker::Dispose();
if (!oFile.OpenFile(strFile)) return bIsBreak ? false : true;
return ""; }
int nSize = (int)oFile.GetFileSize(); std::string ReadScriptFile(const std::wstring& strFile)
if (nSize < 3) {
return ""; NSFile::CFileBinary oFile;
BYTE* pData = new BYTE[nSize]; if (!oFile.OpenFile(strFile))
DWORD dwReadSize = 0; return "";
oFile.ReadFile(pData, (DWORD)nSize, dwReadSize);
int nSize = (int)oFile.GetFileSize();
int nOffset = 0; if (nSize < 3)
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF) return "";
{
nOffset = 3; BYTE* pData = new BYTE[nSize];
} DWORD dwReadSize = 0;
oFile.ReadFile(pData, (DWORD)nSize, dwReadSize);
std::string sReturn((char*)(pData + nOffset), nSize - nOffset);
int nOffset = 0;
RELEASEARRAYOBJECTS(pData); if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
return sReturn; {
} nOffset = 3;
}; }
CDoctrenderer::CDoctrenderer(const std::wstring& sAllFontsPath) std::string sReturn((char*)(pData + nOffset), nSize - nOffset);
{
m_pInternal = new CDoctRenderer_Private(sAllFontsPath); RELEASEARRAYOBJECTS(pData);
} return sReturn;
}
CDoctrenderer::~CDoctrenderer() };
{
RELEASEOBJECT(m_pInternal); CDoctrenderer::CDoctrenderer(const std::wstring& sAllFontsPath)
} {
m_pInternal = new CDoctRenderer_Private(sAllFontsPath);
bool CDoctrenderer::Execute(const std::wstring& strXml, std::wstring& strError) }
{
strError = L""; CDoctrenderer::~CDoctrenderer()
m_pInternal->m_oParams.FromXml(strXml); {
m_pInternal->m_arImagesInChanges.clear(); RELEASEOBJECT(m_pInternal);
}
std::vector<std::wstring>* arSdkFiles = NULL;
switch (m_pInternal->m_oParams.m_eSrcFormat) bool CDoctrenderer::Execute(const std::wstring& strXml, std::wstring& strError)
{ {
case DoctRendererFormat::DOCT: strError = L"";
{ m_pInternal->m_oParams.FromXml(strXml);
switch (m_pInternal->m_oParams.m_eDstFormat) m_pInternal->m_arImagesInChanges.clear();
{
case DoctRendererFormat::DOCT: std::vector<std::wstring>* arSdkFiles = NULL;
case DoctRendererFormat::PDF: switch (m_pInternal->m_oParams.m_eSrcFormat)
case DoctRendererFormat::HTML: {
{ case DoctRendererFormat::DOCT:
arSdkFiles = &m_pInternal->m_arDoctSDK; {
m_pInternal->m_strEditorType = L"document"; switch (m_pInternal->m_oParams.m_eDstFormat)
break; {
} case DoctRendererFormat::DOCT:
default: case DoctRendererFormat::PDF:
return false; case DoctRendererFormat::HTML:
} {
break; arSdkFiles = &m_pInternal->m_arDoctSDK;
} m_pInternal->m_strEditorType = L"document";
case DoctRendererFormat::PPTT: break;
{ }
switch (m_pInternal->m_oParams.m_eDstFormat) default:
{ return false;
case DoctRendererFormat::PPTT: }
case DoctRendererFormat::PDF: break;
{ }
arSdkFiles = &m_pInternal->m_arPpttSDK; case DoctRendererFormat::PPTT:
m_pInternal->m_strEditorType = L"presentation"; {
break; switch (m_pInternal->m_oParams.m_eDstFormat)
} {
default: case DoctRendererFormat::PPTT:
return false; case DoctRendererFormat::PDF:
} {
break; arSdkFiles = &m_pInternal->m_arPpttSDK;
} m_pInternal->m_strEditorType = L"presentation";
case DoctRendererFormat::XLST: break;
{ }
switch (m_pInternal->m_oParams.m_eDstFormat) default:
{ return false;
case DoctRendererFormat::XLST: }
case DoctRendererFormat::PDF: break;
{ }
arSdkFiles = &m_pInternal->m_arXlstSDK; case DoctRendererFormat::XLST:
m_pInternal->m_strEditorType = L"spreadsheet"; {
break; switch (m_pInternal->m_oParams.m_eDstFormat)
} {
default: case DoctRendererFormat::XLST:
return false; case DoctRendererFormat::PDF:
} {
break; arSdkFiles = &m_pInternal->m_arXlstSDK;
} m_pInternal->m_strEditorType = L"spreadsheet";
default: break;
return false; }
} default:
return false;
std::wstring strFileName = m_pInternal->m_oParams.m_strSrcFilePath; }
strFileName += L"/Editor.bin"; break;
}
strFileName = string_replaceAll(strFileName, L"\\\\", L"\\"); default:
strFileName = string_replaceAll(strFileName, L"//", L"/"); return false;
strFileName = string_replaceAll(strFileName, L"\\", L"/"); }
m_pInternal->m_strFilePath = strFileName; std::wstring strFileName = m_pInternal->m_oParams.m_strSrcFilePath;
strFileName += L"/Editor.bin";
std::string strScript = "";
for (size_t i = 0; i < m_pInternal->m_arrFiles.GetCount(); ++i) strFileName = string_replaceAll(strFileName, L"\\\\", L"\\");
{ strFileName = string_replaceAll(strFileName, L"//", L"/");
#if 0 strFileName = string_replaceAll(strFileName, L"\\", L"/");
if (m_arrFiles[i].find(L"AllFonts.js") != std::wstring::npos)
continue; m_pInternal->m_strFilePath = strFileName;
#endif
std::string strScript = "";
strScript += m_pInternal->ReadScriptFile(m_pInternal->m_arrFiles[i]); for (size_t i = 0; i < m_pInternal->m_arrFiles.GetCount(); ++i)
strScript += "\n\n"; {
} #if 0
if (m_arrFiles[i].find(L"AllFonts.js") != std::wstring::npos)
std::wstring sCachePath = L""; continue;
if (NULL != arSdkFiles) #endif
{
if (m_pInternal->m_oParams.m_bIsCachedScripts && (0 < arSdkFiles->size())) strScript += m_pInternal->ReadScriptFile(m_pInternal->m_arrFiles[i]);
{ strScript += "\n\n";
sCachePath = NSFile::GetDirectoryName(*arSdkFiles->begin()) + L"/sdk-all.cache"; }
}
std::wstring sCachePath = L"";
for (std::vector<std::wstring>::iterator i = arSdkFiles->begin(); i != arSdkFiles->end(); i++) if (NULL != arSdkFiles)
{ {
strScript += m_pInternal->ReadScriptFile(*i); if (m_pInternal->m_oParams.m_bIsCachedScripts && (0 < arSdkFiles->size()))
strScript += "\n\n"; {
} sCachePath = NSFile::GetDirectoryName(*arSdkFiles->begin()) + L"/sdk-all.cache";
} }
if (m_pInternal->m_strEditorType == L"spreadsheet") for (std::vector<std::wstring>::iterator i = arSdkFiles->begin(); i != arSdkFiles->end(); i++)
strScript += "\n$.ready();"; {
strScript += m_pInternal->ReadScriptFile(*i);
std::wstring sReturnParams = L""; strScript += "\n\n";
bool bResult = m_pInternal->ExecuteScript(strScript, sCachePath, strError, sReturnParams); }
}
if (strError.length() != 0)
{ if (m_pInternal->m_strEditorType == L"spreadsheet")
strError = L"<result><error " + strError + L" />" + sReturnParams + L"</result>"; strScript += "\n$.ready();";
}
else if (sReturnParams.length() != 0) std::wstring sReturnParams = L"";
{ bool bResult = m_pInternal->ExecuteScript(strScript, sCachePath, strError, sReturnParams);
strError = L"<result>" + sReturnParams + L"</result>";
} if (strError.length() != 0)
{
return bResult ? true : false; strError = L"<result><error " + strError + L" />" + sReturnParams + L"</result>";
} }
else if (sReturnParams.length() != 0)
std::vector<std::wstring> CDoctrenderer::GetImagesInChanges() {
{ strError = L"<result>" + sReturnParams + L"</result>";
return m_pInternal->m_arImagesInChanges; }
}
} return bResult ? true : false;
}
bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFile,
CNativeControl* pNative, std::vector<std::wstring> CDoctrenderer::GetImagesInChanges()
v8::Isolate* isolate, {
v8::Local<v8::Object>& global_js, return m_pInternal->m_arImagesInChanges;
v8::Handle<v8::Value>* args, }
v8::TryCatch& try_catch, }
std::wstring& strError)
{ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFile,
NSDoctRenderer::CExecuteParams oParams; CNativeControl* pNative,
oParams.m_eDstFormat = (NSDoctRenderer::DoctRendererFormat::FormatFile)nFormat; v8::Isolate* isolate,
oParams.m_strDstFilePath = strDstFile; v8::Local<v8::Object>& global_js,
v8::Handle<v8::Value>* args,
return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams, v8::TryCatch& try_catch,
pNative, isolate, global_js, args, try_catch, strError, true); std::wstring& strError)
} {
NSDoctRenderer::CExecuteParams oParams;
oParams.m_eDstFormat = (NSDoctRenderer::DoctRendererFormat::FormatFile)nFormat;
oParams.m_strDstFilePath = strDstFile;
return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams,
pNative, isolate, global_js, args, try_catch, strError, true);
}
...@@ -674,12 +674,20 @@ public: ...@@ -674,12 +674,20 @@ public:
m_nLen = read_int2(pData, nCur, nLen); m_nLen = read_int2(pData, nCur, nLen);
m_pData = new BYTE[m_nLen]; if (nVersion < 10)
m_pDataCur = m_pData; {
m_pData = new BYTE[m_nLen];
read_base64_2(pData, nCur, nLen); m_pDataCur = m_pData;
read_base64_2(pData, nCur, nLen);
delete[]pData; delete[]pData;
}
else
{
m_nLen = nLen;
m_pData = (BYTE*)pData;
m_pDataCur = m_pData + m_nLen;
}
return nVersion; return nVersion;
} }
......
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