Commit db69c450 authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander Trofimov
parent b5e6eae9
...@@ -37,10 +37,33 @@ public: ...@@ -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: ...@@ -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()
{ {
m_nFileType = -1; if (NULL == m_pInitializer)
m_platform = v8::platform::CreateDefaultPlatform(); NSDoctRenderer::CDocBuilder::Initialize();
v8::V8::InitializePlatform(m_platform);
v8::V8::Initialize();
v8::V8::InitializeICU();
if (!m_bIsInitTypedArrays) m_nFileType = -1;
{
m_bIsInitTypedArrays = true;
enableTypedArrays();
}
m_isolate = v8::Isolate::New(); m_isolate = v8::Isolate::New();
...@@ -92,11 +107,6 @@ public: ...@@ -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: ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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,10 +445,13 @@ namespace NSDoctRenderer ...@@ -435,10 +445,13 @@ namespace NSDoctRenderer
} }
} }
bool bIsEqual = NSFile::CFileBinary::Exists(strFontsSelectionBin);
if (bIsEqual && bIsCheckSystemFonts)
{
CApplicationFonts oApplicationF; CApplicationFonts oApplicationF;
CArray<std::wstring> strFontsW_Cur = oApplicationF.GetSetupFontFiles(); CArray<std::wstring> strFontsW_Cur = oApplicationF.GetSetupFontFiles();
bool bIsEqual = true;
if (strFonts.GetCount() != strFontsW_Cur.GetCount()) if (strFonts.GetCount() != strFontsW_Cur.GetCount())
bIsEqual = false; bIsEqual = false;
...@@ -455,12 +468,6 @@ namespace NSDoctRenderer ...@@ -455,12 +468,6 @@ namespace NSDoctRenderer
} }
} }
if (bIsEqual)
{
if (!NSFile::CFileBinary::Exists(strFontsSelectionBin))
bIsEqual = false;
}
if (!bIsEqual) if (!bIsEqual)
{ {
if (NSFile::CFileBinary::Exists(strAllFontsJSPath)) if (NSFile::CFileBinary::Exists(strAllFontsJSPath))
...@@ -485,6 +492,7 @@ namespace NSDoctRenderer ...@@ -485,6 +492,7 @@ namespace NSDoctRenderer
NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, L"", strFontsSelectionBin); NSCommon::SaveAllFontsJS(oApplicationF, strAllFontsJSPath, L"", strFontsSelectionBin);
} }
} }
}
void CheckFileDir() void CheckFileDir()
{ {
...@@ -997,9 +1005,9 @@ namespace NSDoctRenderer ...@@ -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()
{ {
...@@ -1055,23 +1063,34 @@ namespace NSDoctRenderer ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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;
}; };
......
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