mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@68988 954022d7-b5bf-4e40-9824-e11837661b57
This commit is contained in:
committed by
Alexander Trofimov
parent
b5e6eae991
commit
db69c4505f
@ -37,10 +37,33 @@ public:
|
|||||||
CScopeWrapper(v8::Isolate* isolate) : m_handler(isolate) {}
|
CScopeWrapper(v8::Isolate* isolate) : m_handler(isolate) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CV8Initializer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
v8::Platform* m_platform;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CV8Initializer()
|
||||||
|
{
|
||||||
|
m_platform = v8::platform::CreateDefaultPlatform();
|
||||||
|
v8::V8::InitializePlatform(m_platform);
|
||||||
|
|
||||||
|
v8::V8::Initialize();
|
||||||
|
v8::V8::InitializeICU();
|
||||||
|
|
||||||
|
enableTypedArrays();
|
||||||
|
}
|
||||||
|
~CV8Initializer()
|
||||||
|
{
|
||||||
|
v8::V8::Dispose();
|
||||||
|
v8::V8::ShutdownPlatform();
|
||||||
|
delete m_platform;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class CV8RealTimeWorker
|
class CV8RealTimeWorker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
v8::Platform* m_platform;
|
|
||||||
v8::Isolate* m_isolate;
|
v8::Isolate* m_isolate;
|
||||||
|
|
||||||
v8::Isolate::Scope* m_isolate_scope;
|
v8::Isolate::Scope* m_isolate_scope;
|
||||||
@ -51,25 +74,17 @@ public:
|
|||||||
|
|
||||||
int m_nFileType;
|
int m_nFileType;
|
||||||
|
|
||||||
private:
|
public:
|
||||||
static bool m_bIsInitTypedArrays;
|
static CV8Initializer* m_pInitializer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CV8RealTimeWorker()
|
CV8RealTimeWorker()
|
||||||
{
|
{
|
||||||
|
if (NULL == m_pInitializer)
|
||||||
|
NSDoctRenderer::CDocBuilder::Initialize();
|
||||||
|
|
||||||
m_nFileType = -1;
|
m_nFileType = -1;
|
||||||
m_platform = v8::platform::CreateDefaultPlatform();
|
|
||||||
v8::V8::InitializePlatform(m_platform);
|
|
||||||
|
|
||||||
v8::V8::Initialize();
|
|
||||||
v8::V8::InitializeICU();
|
|
||||||
|
|
||||||
if (!m_bIsInitTypedArrays)
|
|
||||||
{
|
|
||||||
m_bIsInitTypedArrays = true;
|
|
||||||
enableTypedArrays();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_isolate = v8::Isolate::New();
|
m_isolate = v8::Isolate::New();
|
||||||
|
|
||||||
@ -92,11 +107,6 @@ public:
|
|||||||
RELEASEOBJECT(m_isolate_scope);
|
RELEASEOBJECT(m_isolate_scope);
|
||||||
|
|
||||||
m_isolate->Dispose();
|
m_isolate->Dispose();
|
||||||
v8::V8::Dispose();
|
|
||||||
|
|
||||||
v8::V8::ShutdownPlatform();
|
|
||||||
delete m_platform;
|
|
||||||
m_platform = NULL;
|
|
||||||
m_isolate = NULL;
|
m_isolate = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +296,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool CV8RealTimeWorker::m_bIsInitTypedArrays = false;
|
CV8Initializer* CV8RealTimeWorker::m_pInitializer = NULL;
|
||||||
|
|
||||||
#ifdef CreateFile
|
#ifdef CreateFile
|
||||||
#undef CreateFile
|
#undef CreateFile
|
||||||
@ -316,7 +326,7 @@ namespace NSDoctRenderer
|
|||||||
|
|
||||||
CV8RealTimeWorker* m_pWorker;
|
CV8RealTimeWorker* m_pWorker;
|
||||||
public:
|
public:
|
||||||
CDocBuilder_Private()
|
CDocBuilder_Private(bool bIsCheckSystemFonts)
|
||||||
{
|
{
|
||||||
m_sX2tPath = NSFile::GetProcessDirectory();
|
m_sX2tPath = NSFile::GetProcessDirectory();
|
||||||
m_pWorker = NULL;
|
m_pWorker = NULL;
|
||||||
@ -382,7 +392,7 @@ namespace NSDoctRenderer
|
|||||||
if (!NSFile::CFileBinary::Exists(m_strXlstSDK))
|
if (!NSFile::CFileBinary::Exists(m_strXlstSDK))
|
||||||
m_strXlstSDK = sConfigDir + m_strXlstSDK;
|
m_strXlstSDK = sConfigDir + m_strXlstSDK;
|
||||||
|
|
||||||
CheckFonts();
|
CheckFonts(bIsCheckSystemFonts);
|
||||||
|
|
||||||
m_sTmpFolder = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"DTB");
|
m_sTmpFolder = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"DTB");
|
||||||
|
|
||||||
@ -396,7 +406,7 @@ namespace NSDoctRenderer
|
|||||||
CloseFile();
|
CloseFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckFonts()
|
void CheckFonts(bool bIsCheckSystemFonts)
|
||||||
{
|
{
|
||||||
CArray<std::string> strFonts;
|
CArray<std::string> strFonts;
|
||||||
std::wstring strDirectory = NSCommon::GetDirectoryName(m_strAllFonts);
|
std::wstring strDirectory = NSCommon::GetDirectoryName(m_strAllFonts);
|
||||||
@ -435,54 +445,52 @@ namespace NSDoctRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CApplicationFonts oApplicationF;
|
bool bIsEqual = NSFile::CFileBinary::Exists(strFontsSelectionBin);
|
||||||
CArray<std::wstring> strFontsW_Cur = oApplicationF.GetSetupFontFiles();
|
|
||||||
|
|
||||||
bool bIsEqual = true;
|
if (bIsEqual && bIsCheckSystemFonts)
|
||||||
if (strFonts.GetCount() != strFontsW_Cur.GetCount())
|
|
||||||
bIsEqual = false;
|
|
||||||
|
|
||||||
if (bIsEqual)
|
|
||||||
{
|
{
|
||||||
int nCount = strFonts.GetCount();
|
CApplicationFonts oApplicationF;
|
||||||
for (int i = 0; i < nCount; ++i)
|
CArray<std::wstring> strFontsW_Cur = oApplicationF.GetSetupFontFiles();
|
||||||
|
|
||||||
|
if (strFonts.GetCount() != strFontsW_Cur.GetCount())
|
||||||
|
bIsEqual = false;
|
||||||
|
|
||||||
|
if (bIsEqual)
|
||||||
{
|
{
|
||||||
if (strFonts[i] != NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(strFontsW_Cur[i].c_str(), strFontsW_Cur[i].length()))
|
int nCount = strFonts.GetCount();
|
||||||
|
for (int i = 0; i < nCount; ++i)
|
||||||
{
|
{
|
||||||
bIsEqual = false;
|
if (strFonts[i] != NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(strFontsW_Cur[i].c_str(), strFontsW_Cur[i].length()))
|
||||||
break;
|
{
|
||||||
|
bIsEqual = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (bIsEqual)
|
if (!bIsEqual)
|
||||||
{
|
|
||||||
if (!NSFile::CFileBinary::Exists(strFontsSelectionBin))
|
|
||||||
bIsEqual = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bIsEqual)
|
|
||||||
{
|
|
||||||
if (NSFile::CFileBinary::Exists(strAllFontsJSPath))
|
|
||||||
NSFile::CFileBinary::Remove(strAllFontsJSPath);
|
|
||||||
if (NSFile::CFileBinary::Exists(strFontsSelectionBin))
|
|
||||||
NSFile::CFileBinary::Remove(strFontsSelectionBin);
|
|
||||||
|
|
||||||
if (strFonts.GetCount() != 0)
|
|
||||||
NSFile::CFileBinary::Remove(strDirectory + L"/fonts.log");
|
|
||||||
|
|
||||||
NSFile::CFileBinary oFile;
|
|
||||||
oFile.CreateFileW(strDirectory + L"/fonts.log");
|
|
||||||
int nCount = strFontsW_Cur.GetCount();
|
|
||||||
for (int i = 0; i < nCount; ++i)
|
|
||||||
{
|
{
|
||||||
oFile.WriteStringUTF8(strFontsW_Cur[i]);
|
if (NSFile::CFileBinary::Exists(strAllFontsJSPath))
|
||||||
oFile.WriteFile((BYTE*)"\n", 1);
|
NSFile::CFileBinary::Remove(strAllFontsJSPath);
|
||||||
}
|
if (NSFile::CFileBinary::Exists(strFontsSelectionBin))
|
||||||
oFile.CloseFile();
|
NSFile::CFileBinary::Remove(strFontsSelectionBin);
|
||||||
|
|
||||||
oApplicationF.InitializeFromArrayFiles(strFontsW_Cur, 2);
|
if (strFonts.GetCount() != 0)
|
||||||
NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, L"", strFontsSelectionBin);
|
NSFile::CFileBinary::Remove(strDirectory + L"/fonts.log");
|
||||||
|
|
||||||
|
NSFile::CFileBinary oFile;
|
||||||
|
oFile.CreateFileW(strDirectory + L"/fonts.log");
|
||||||
|
int nCount = strFontsW_Cur.GetCount();
|
||||||
|
for (int i = 0; i < nCount; ++i)
|
||||||
|
{
|
||||||
|
oFile.WriteStringUTF8(strFontsW_Cur[i]);
|
||||||
|
oFile.WriteFile((BYTE*)"\n", 1);
|
||||||
|
}
|
||||||
|
oFile.CloseFile();
|
||||||
|
|
||||||
|
oApplicationF.InitializeFromArrayFiles(strFontsW_Cur, 2);
|
||||||
|
NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, L"", strFontsSelectionBin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,9 +1005,9 @@ namespace NSDoctRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CDocBuilder::CDocBuilder()
|
CDocBuilder::CDocBuilder(bool bIsCheckSystemFonts)
|
||||||
{
|
{
|
||||||
m_pInternal = new CDocBuilder_Private();
|
m_pInternal = new CDocBuilder_Private(bIsCheckSystemFonts);
|
||||||
}
|
}
|
||||||
CDocBuilder::~CDocBuilder()
|
CDocBuilder::~CDocBuilder()
|
||||||
{
|
{
|
||||||
@ -1012,7 +1020,7 @@ namespace NSDoctRenderer
|
|||||||
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
|
if (!NSDirectory::Exists(m_pInternal->m_sTmpFolder))
|
||||||
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
|
NSDirectory::CreateDirectory(m_pInternal->m_sTmpFolder);
|
||||||
|
|
||||||
return m_pInternal->OpenFile(path, params);
|
return m_pInternal->OpenFile(path, params);
|
||||||
}
|
}
|
||||||
bool CDocBuilder::CreateFile(const int& type)
|
bool CDocBuilder::CreateFile(const int& type)
|
||||||
{
|
{
|
||||||
@ -1055,23 +1063,34 @@ namespace NSDoctRenderer
|
|||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this->RunTextA(sCommands.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CDocBuilder::RunTextW(const wchar_t* commands)
|
||||||
|
{
|
||||||
|
std::wstring sCommandsW(commands);
|
||||||
|
std::string sCommands = U_TO_UTF8(sCommandsW);
|
||||||
|
return this->RunTextA(sCommands.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CDocBuilder::RunTextA(const char* commands)
|
||||||
|
{
|
||||||
std::list<std::string> _commands;
|
std::list<std::string> _commands;
|
||||||
const char* _commandsPtr = sCommands.c_str();
|
size_t _commandsLen = strlen(commands);
|
||||||
size_t _commandsLen = sCommands.length();
|
|
||||||
size_t _currentPos = 0;
|
size_t _currentPos = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
while (_currentPos < _commandsLen && (_commandsPtr[_currentPos] == 0x0d || _commandsPtr[_currentPos] == 0x0a))
|
while (_currentPos < _commandsLen && (commands[_currentPos] == 0x0d || commands[_currentPos] == 0x0a))
|
||||||
++_currentPos;
|
++_currentPos;
|
||||||
|
|
||||||
size_t _start = _currentPos;
|
size_t _start = _currentPos;
|
||||||
|
|
||||||
while (_currentPos < _commandsLen && (_commandsPtr[_currentPos] != 0x0d && _commandsPtr[_currentPos] != 0x0a))
|
while (_currentPos < _commandsLen && (commands[_currentPos] != 0x0d && commands[_currentPos] != 0x0a))
|
||||||
++_currentPos;
|
++_currentPos;
|
||||||
|
|
||||||
if (_currentPos > (_start + 1))
|
if (_currentPos > (_start + 1))
|
||||||
_commands.push_back(std::string(_commandsPtr + _start, _currentPos - _start));
|
_commands.push_back(std::string(commands + _start, _currentPos - _start));
|
||||||
|
|
||||||
if (_currentPos >= _commandsLen)
|
if (_currentPos >= _commandsLen)
|
||||||
break;
|
break;
|
||||||
@ -1167,4 +1186,17 @@ namespace NSDoctRenderer
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDocBuilder::Initialize()
|
||||||
|
{
|
||||||
|
if (NULL == CV8RealTimeWorker::m_pInitializer)
|
||||||
|
CV8RealTimeWorker::m_pInitializer = new CV8Initializer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CDocBuilder::Dispose()
|
||||||
|
{
|
||||||
|
if (NULL != CV8RealTimeWorker::m_pInitializer)
|
||||||
|
delete CV8RealTimeWorker::m_pInitializer;
|
||||||
|
CV8RealTimeWorker::m_pInitializer = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ namespace NSDoctRenderer
|
|||||||
class Q_DECL_EXPORT CDocBuilder
|
class Q_DECL_EXPORT CDocBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CDocBuilder();
|
CDocBuilder(bool bIsCheckSystemFonts);
|
||||||
~CDocBuilder();
|
~CDocBuilder();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -22,6 +22,13 @@ namespace NSDoctRenderer
|
|||||||
|
|
||||||
bool Run(const wchar_t* path);
|
bool Run(const wchar_t* path);
|
||||||
|
|
||||||
|
bool RunTextW(const wchar_t* commands);
|
||||||
|
bool RunTextA(const char* commands);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void Initialize();
|
||||||
|
static void Dispose();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CDocBuilder_Private* m_pInternal;
|
CDocBuilder_Private* m_pInternal;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user