Compare commits

...

9 Commits

Author SHA1 Message Date
447e1f5ccc Fix for snapshots 2024-08-28 13:08:06 +03:00
06ee659edc Fixwork with replaceAll function 2024-08-27 23:07:25 +03:00
fe35178e26 Add support snapshots 2024-08-27 22:52:05 +03:00
13590d4c2e Refactoring work with cache 2024-08-27 13:04:20 +03:00
84fc9f876e Add flag for fonts generation 2024-08-26 13:56:36 +03:00
c4530caac1 Merge pull request #1623 from ONLYOFFICE/release/v8.2.0
Release/v8.2.0
2024-08-21 04:17:49 -07:00
f18eb2ef5b Developing 2024-08-20 00:23:59 +03:00
facdff46fe Refactoring 2024-08-19 18:24:06 +03:00
2708479152 Add class for embed pdf object 2024-08-19 13:57:26 +03:00
26 changed files with 1529 additions and 891 deletions

View File

@ -5,6 +5,7 @@ v8_version_89 {
CONFIG += c++14
CONFIG += use_v8_monolith
DEFINES += V8_VERSION_89_PLUS
DEFINES += V8_SUPPORT_SNAPSHOTS
core_win_32:CONFIG += build_platform_32
core_linux_32:CONFIG += build_platform_32

View File

@ -40,24 +40,53 @@
namespace NSDoctRenderer
{
class CAdditionalData
{
public:
CAdditionalData() {}
virtual ~CAdditionalData() {}
virtual std::string getParam(const std::wstring& name) { return ""; }
};
class CDocBuilderParams
{
public:
CDocBuilderParams() :
m_bCheckFonts(false),
m_sWorkDir(L""),
m_bSaveWithDoctrendererMode(false),
m_sArgumentJSON(""),
m_bIsSystemFonts(true)
{
}
public:
bool m_bCheckFonts;
std::wstring m_sWorkDir;
bool m_bSaveWithDoctrendererMode;
std::string m_sArgumentJSON;
bool m_bIsSystemFonts;
std::vector<std::wstring> m_arFontDirs;
};
class CDoctRendererConfig
{
public:
std::vector<std::wstring> m_arrFiles;
std::wstring m_strSdkPath;
std::vector<std::wstring> m_arDoctSDK;
std::vector<std::wstring> m_arPpttSDK;
std::vector<std::wstring> m_arXlstSDK;
std::vector<std::wstring> m_arVsdtSDK;
std::vector<std::wstring> m_arrFiles;
std::wstring m_strAllFonts;
bool m_bIsNotUseConfigAllFontsDir;
bool m_bIsUseCache;
std::wstring m_sConsoleLogFile;
std::wstring m_sErrorsLogFile;
public:
CDoctRendererConfig() : m_bIsNotUseConfigAllFontsDir(false)
CDoctRendererConfig() : m_bIsNotUseConfigAllFontsDir(false), m_bIsUseCache(true)
{
}
@ -92,10 +121,6 @@ namespace NSDoctRenderer
void Parse(const std::wstring& sWorkDir)
{
m_arrFiles.clear();
m_arDoctSDK.clear();
m_arPpttSDK.clear();
m_arXlstSDK.clear();
m_arVsdtSDK.clear();
std::wstring sConfigDir = sWorkDir + L"/";
std::wstring sConfigPath = sConfigDir + L"DoctRenderer.config";
@ -149,40 +174,16 @@ namespace NSDoctRenderer
}
}
}
m_arrFiles.push_back(bIsAbsoluteFontsPath ? m_strAllFonts : private_GetFile(sConfigDir, m_strAllFonts));
if (!bIsAbsoluteFontsPath)
m_strAllFonts = private_GetFile(sConfigDir, m_strAllFonts);
}
std::wstring sSdkPath = oNode.ReadNodeText(L"sdkjs");
if (!sSdkPath.empty())
m_strSdkPath = oNode.ReadNodeText(L"sdkjs");
if (!m_strSdkPath.empty())
{
if (!NSDirectory::Exists(sSdkPath))
sSdkPath = sConfigDir + sSdkPath;
std::wstring sFontsPath = sSdkPath + L"/common/libfont/engine";
if (!sFontsPath.empty())
{
#ifdef SUPPORT_HARFBUZZ_SHAPER
sFontsPath += L"/fonts_native.js";
#else
sFontsPath += L"/fonts_ie.js";
#endif
}
m_arDoctSDK.push_back(sSdkPath + L"/word/sdk-all-min.js");
m_arDoctSDK.push_back(sFontsPath);
m_arDoctSDK.push_back(sSdkPath + L"/word/sdk-all.js");
m_arPpttSDK.push_back(sSdkPath + L"/slide/sdk-all-min.js");
m_arPpttSDK.push_back(sFontsPath);
m_arPpttSDK.push_back(sSdkPath + L"/slide/sdk-all.js");
m_arXlstSDK.push_back(sSdkPath + L"/cell/sdk-all-min.js");
m_arXlstSDK.push_back(sFontsPath);
m_arXlstSDK.push_back(sSdkPath + L"/cell/sdk-all.js");
m_arVsdtSDK.push_back(sSdkPath + L"/draw/sdk-all-min.js");
m_arVsdtSDK.push_back(sFontsPath);
m_arVsdtSDK.push_back(sSdkPath + L"/draw/sdk-all.js");
if (!NSDirectory::Exists(m_strSdkPath))
m_strSdkPath = sConfigDir + m_strSdkPath;
}
m_sConsoleLogFile = oNode.ReadNodeText(L"LogFileConsoleLog");
@ -193,7 +194,35 @@ namespace NSDoctRenderer
if (!m_sErrorsLogFile.empty())
m_sErrorsLogFile = private_GetFile(sConfigDir, m_sErrorsLogFile);
}
char* GetVersion()
{
std::wstring sFile = m_strSdkPath + L"/word/sdk-all-min.js";
std::string sData;
if (!NSFile::CFileBinary::ReadAllTextUtf8A(sFile, sData))
return NULL;
std::string::size_type startPos = sData.find("Version:");
if (std::string::npos == startPos)
return NULL;
startPos += 8;
std::string::size_type endPos = sData.find(')', startPos);
if (std::string::npos == endPos)
return NULL;
size_t sSrcLen = endPos - startPos + 1;
if (sSrcLen == 0)
return NULL;
char* sRet = new char[sSrcLen + 1];
memcpy(sRet, sData.c_str() + startPos, sSrcLen);
sRet[sSrcLen] = '\0';
return sRet;
}
};
} // namespace NSDoctRenderer
}
#endif // DOC_BUILDER_CONFIG

View File

@ -44,11 +44,15 @@ void CV8RealTimeWorker::_LOGGING_ERROR_(const std::wstring& strType, const std::
using namespace NSJSBase;
CV8RealTimeWorker::CV8RealTimeWorker(NSDoctRenderer::CDocBuilder* pBuilder)
CV8RealTimeWorker::CV8RealTimeWorker(NSDoctRenderer::CDocBuilder* pBuilder, const NSDoctRenderer::DoctRendererEditorType& type, NSDoctRenderer::CDoctRendererConfig* config)
{
m_nFileType = -1;
m_context = new CJSContext();
if (NSDoctRenderer::DoctRendererEditorType::INVALID == type)
m_context = new CJSContext();
else
m_context = NSDoctRenderer::CreateEditorContext(type, config);
CJSContextScope scope(m_context);
CJSContext::Embed<CNativeControlEmbed>(false);
@ -62,6 +66,7 @@ CV8RealTimeWorker::CV8RealTimeWorker(NSDoctRenderer::CDocBuilder* pBuilder)
JSSmart<CJSObject> global = m_context->GetGlobal();
global->set("window", global);
global->set("self", global);
JSSmart<CJSObject> oBuilderJS = CJSContext::createEmbedObject("CBuilderEmbed");
global->set("builderJS", oBuilderJS);
@ -239,7 +244,7 @@ bool CV8RealTimeWorker::InitVariables()
return true;
}
bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstring& path, const std::string& sString, const std::wstring& sCachePath, CV8Params* pParams)
bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstring& path, const NSDoctRenderer::DoctRendererEditorType& editorType, NSDoctRenderer::CDoctRendererConfig* config, CV8Params* pParams)
{
LOGGER_SPEED_START();
@ -248,7 +253,8 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
LOGGER_SPEED_LAP("compile");
m_context->runScript(sString, try_catch, sCachePath);
if (!m_context->isSnapshotUsed())
NSDoctRenderer::RunEditor(editorType, m_context, try_catch, config);
if(try_catch->Check())
return false;
@ -1249,45 +1255,7 @@ namespace NSDoctRenderer
char* CDocBuilder::GetVersion()
{
m_pInternal->Init();
if (0 == m_pInternal->m_arDoctSDK.size())
return NULL;
std::wstring sFile;
for (std::vector<std::wstring>::iterator i = m_pInternal->m_arDoctSDK.begin(); i != m_pInternal->m_arDoctSDK.end(); i++)
{
if (std::wstring::npos != i->find(L"sdk-all-min.js"))
{
sFile = *i;
break;
}
}
if (sFile.empty())
return NULL;
std::string sData;
if (!NSFile::CFileBinary::ReadAllTextUtf8A(sFile, sData))
return NULL;
std::string::size_type startPos = sData.find("Version:");
if (std::string::npos == startPos)
return NULL;
startPos += 8;
std::string::size_type endPos = sData.find(')', startPos);
if (std::string::npos == endPos)
return NULL;
size_t sSrcLen = endPos - startPos + 1;
if (sSrcLen == 0)
return NULL;
char* sRet = new char[sSrcLen + 1];
memcpy(sRet, sData.c_str() + startPos, sSrcLen);
sRet[sSrcLen] = '\0';
return sRet;
return m_pInternal->GetVersion();
}
bool CDocBuilder::Run(const wchar_t* path)
@ -1521,7 +1489,7 @@ namespace NSDoctRenderer
else if (sParam == "--work-directory")
m_pInternal->m_oParams.m_sWorkDir = std::wstring(value);
else if (sParam == "--cache-scripts")
m_pInternal->m_bIsCacheScript = (std::wstring(value) == L"true");
m_pInternal->m_bIsUseCache = (std::wstring(value) == L"true");
else if (sParam == "--save-use-only-names")
{
m_pInternal->m_bIsServerSafeVersion = true;

View File

@ -32,7 +32,7 @@
#ifndef DOC_BUILDER_PRIVATE
#define DOC_BUILDER_PRIVATE
#include "./config.h"
#include "./editors.h"
#include "docbuilder.h"
#include "doctrenderer.h"
@ -415,7 +415,7 @@ public:
public:
CV8RealTimeWorker(NSDoctRenderer::CDocBuilder* pBuilder);
CV8RealTimeWorker(NSDoctRenderer::CDocBuilder* pBuilder, const NSDoctRenderer::DoctRendererEditorType& type, NSDoctRenderer::CDoctRendererConfig* config);
~CV8RealTimeWorker();
public:
@ -427,36 +427,13 @@ public:
std::string GetGlobalVariable();
std::wstring GetJSVariable(std::wstring sParam);
bool OpenFile(const std::wstring& sBasePath, const std::wstring& path, const std::string& sString, const std::wstring& sCachePath, CV8Params* pParams = NULL);
bool OpenFile(const std::wstring& sBasePath, const std::wstring& path, const NSDoctRenderer::DoctRendererEditorType& editorType, NSDoctRenderer::CDoctRendererConfig* config, CV8Params* pParams = NULL);
bool SaveFileWithChanges(int type, const std::wstring& _path, const std::wstring& sJsonParams = L"");
bool InitVariables();
};
namespace NSDoctRenderer
{
class CAdditionalData
{
public:
CAdditionalData() {}
virtual ~CAdditionalData() {}
virtual std::string getParam(const std::wstring& name) { return ""; }
};
class CDocBuilderParams
{
public:
CDocBuilderParams() : m_bCheckFonts(false), m_sWorkDir(L""), m_bSaveWithDoctrendererMode(false), m_sArgumentJSON(""), m_bIsSystemFonts(true) {}
public:
bool m_bCheckFonts;
std::wstring m_sWorkDir;
bool m_bSaveWithDoctrendererMode;
std::string m_sArgumentJSON;
bool m_bIsSystemFonts;
std::vector<std::wstring> m_arFontDirs;
};
class CDocBuilder_Private : public CDoctRendererConfig
{
public:
@ -477,8 +454,6 @@ namespace NSDoctRenderer
CDocBuilderParams m_oParams;
bool m_bIsInit;
bool m_bIsCacheScript;
bool m_bIsServerSafeVersion;
std::wstring m_sFolderForSaveOnlyUseNames;
@ -490,7 +465,7 @@ namespace NSDoctRenderer
static std::wstring m_sExternalDirectory;
public:
CDocBuilder_Private() : CDoctRendererConfig(), m_sTmpFolder(NSFile::CFileBinary::GetTempPath()), m_nFileType(-1),
m_pWorker(NULL), m_pAdditionalData(NULL), m_bIsInit(false), m_bIsCacheScript(true), m_bIsServerSafeVersion(false),
m_pWorker(NULL), m_pAdditionalData(NULL), m_bIsInit(false), m_bIsServerSafeVersion(false),
m_sGlobalVariable(""), m_bIsGlobalVariableUse(false), m_pParent(NULL), m_bJavascriptBeforeEditor(false)
{
}
@ -1251,7 +1226,7 @@ namespace NSDoctRenderer
{
if (NULL == m_pWorker)
{
m_pWorker = new CV8RealTimeWorker(m_pParent);
m_pWorker = new CV8RealTimeWorker(m_pParent, GetEditorType(), this);
m_pWorker->m_sUtf8ArgumentJSON = m_oParams.m_sArgumentJSON;
m_pWorker->m_sGlobalVariable = m_sGlobalVariable;
@ -1273,15 +1248,12 @@ namespace NSDoctRenderer
}
m_bJavascriptBeforeEditor = false;
std::wstring sCachePath = L"";
if (m_bIsCacheScript)
sCachePath = GetScriptCache();
CV8Params oParams;
oParams.IsServerSaveVersion = m_bIsServerSafeVersion;
oParams.DocumentDirectory = m_sFileDir;
return m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, GetScript(), sCachePath, &oParams);
return m_pWorker->OpenFile(m_sX2tPath, m_sFileDir, GetEditorType(), this, &oParams);
}
int SaveFile(const std::wstring& ext, const std::wstring& path, const wchar_t* params = NULL)
@ -1316,119 +1288,22 @@ namespace NSDoctRenderer
return ctx;
}
std::string GetScript()
NSDoctRenderer::DoctRendererEditorType GetEditorType()
{
std::vector<std::wstring>* arSdkFiles = NULL;
switch (m_nFileType)
{
case 0:
{
arSdkFiles = &m_arDoctSDK;
break;
}
return NSDoctRenderer::DoctRendererEditorType::WORD;
case 1:
{
arSdkFiles = &m_arPpttSDK;
break;
}
return NSDoctRenderer::DoctRendererEditorType::SLIDE;
case 2:
{
arSdkFiles = &m_arXlstSDK;
break;
}
return NSDoctRenderer::DoctRendererEditorType::CELL;
case 7:
{
arSdkFiles = &m_arVsdtSDK;
break;
}
return NSDoctRenderer::DoctRendererEditorType::VISIO;
default:
return "";
}
std::string strScript = "";
for (size_t i = 0; i < m_arrFiles.size(); ++i)
{
strScript += ReadScriptFile(m_arrFiles[i]);
strScript += "\n\n";
}
if (NULL != arSdkFiles)
{
for (const std::wstring& i : *arSdkFiles)
{
strScript += ReadScriptFile(i);
strScript += "\n\n";
}
}
if (m_nFileType == 2)
strScript += "\n$.ready();";
return strScript;
}
std::wstring GetScriptCache()
{
std::vector<std::wstring>* arSdkFiles = NULL;
switch (m_nFileType)
{
case 0:
{
arSdkFiles = &m_arDoctSDK;
break;
}
case 1:
{
arSdkFiles = &m_arPpttSDK;
break;
}
case 2:
{
arSdkFiles = &m_arXlstSDK;
break;
}
case 7:
{
arSdkFiles = &m_arVsdtSDK;
break;
}
default:
return L"";
}
if (0 < arSdkFiles->size())
{
return NSFile::GetDirectoryName(*arSdkFiles->begin()) + L"/sdk-all.cache";
}
return L"";
}
std::string ReadScriptFile(const std::wstring& strFile)
{
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(strFile))
return "";
int nSize = (int)oFile.GetFileSize();
if (nSize < 3)
return "";
BYTE* pData = new BYTE[nSize];
DWORD dwReadSize = 0;
oFile.ReadFile(pData, (DWORD)nSize, dwReadSize);
int nOffset = 0;
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
{
nOffset = 3;
}
std::string sReturn((char*)(pData + nOffset), nSize - nOffset);
RELEASEARRAYOBJECTS(pData);
return sReturn;
return NSDoctRenderer::DoctRendererEditorType::INVALID;
}
void WriteData(const wchar_t* path, const wchar_t* value, const bool& append)

View File

@ -40,7 +40,7 @@
#include "embed/NativeControlEmbed.h"
#include "embed/GraphicsEmbed.h"
#include "./config.h"
#include "./editors.h"
#include <iostream>
namespace NSDoctRenderer
@ -99,9 +99,8 @@ namespace NSDoctRenderer
std::wstring m_sJsonParams;
int m_nLcid;
std::wstring m_sScriptsCacheDirectory;
std::vector<int> m_arThemesThumbnailsParams;
public:
CExecuteParams() : m_arChanges()
{
@ -123,7 +122,6 @@ namespace NSDoctRenderer
m_nMailMergeIndexEnd = -1;
m_nLcid = -1;
m_sScriptsCacheDirectory = L"";
}
~CExecuteParams()
{
@ -152,13 +150,13 @@ namespace NSDoctRenderer
{
m_nCountChangesItems = oNodeChanges.ReadAttributeInt(L"TopItem", -1);
std::vector<XmlUtils::CXmlNode> oNodes;
std::vector<XmlUtils::CXmlNode> oNodes;
oNodeChanges.GetNodes(L"Change", oNodes);
size_t nCount = oNodes.size();
for (size_t i = 0; i < nCount; ++i)
size_t nCount = oNodes.size();
for (size_t i = 0; i < nCount; ++i)
{
XmlUtils::CXmlNode & _node = oNodes[i];
XmlUtils::CXmlNode& _node = oNodes[i];
m_arChanges.push_back(_node.GetText());
}
}
@ -175,8 +173,6 @@ namespace NSDoctRenderer
m_nLcid = oNode.ReadValueInt(L"Lcid", -1);
m_sJsonParams = oNode.ReadValueString(L"JsonParams");
m_sScriptsCacheDirectory = oNode.ReadValueString(L"ScriptsCacheDirectory", L"");
m_arThemesThumbnailsParams.clear();
std::wstring sThemesThumbnailsParams = oNode.ReadValueString(L"ThemesThumbnailsParams");
if (!sThemesThumbnailsParams.empty())
@ -190,21 +186,21 @@ namespace NSDoctRenderer
return true;
}
};
}
} // namespace NSDoctRenderer
namespace NSDoctRenderer
{
std::wstring string_replaceAll(std::wstring str, const std::wstring& from, const std::wstring& to)
{
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);
start_pos += to.length();
}
return str;
}
}
} // namespace NSDoctRenderer
namespace NSDoctRenderer
{
@ -243,7 +239,6 @@ namespace NSDoctRenderer
}
~CDoctRenderer_Private()
{
}
void LoadConfig(const std::wstring& sConfigDir, const std::wstring& sAllFontsPath = L"")
{
@ -256,7 +251,6 @@ namespace NSDoctRenderer
}
public:
static void _LOGGING_ERROR_(const std::wstring& strType, const std::wstring& strError)
{
#if 0
@ -280,16 +274,12 @@ namespace NSDoctRenderer
std::cerr << sT << ": " << sE << std::endl;
}
static bool Doct_renderer_SaveFile(CExecuteParams* pParams,
NSNativeControl::CNativeControl* pNative,
JSSmart<CJSContext> context,
JSSmart<CJSValue>* args,
std::wstring& strError,
JSSmart<CJSObject>& api_js_maybe_null,
bool bIsPdfBase64 = false)
static bool Doct_renderer_SaveFile(
CExecuteParams* pParams, NSNativeControl::CNativeControl* pNative, JSSmart<CJSContext> context, JSSmart<CJSValue>* args, std::wstring& strError, JSSmart<CJSObject>& api_js_maybe_null,
bool bIsPdfBase64 = false)
{
JSSmart<CJSTryCatch> try_catch = context->GetExceptions();
JSSmart<CJSObject> global_js = context->GetGlobal();
JSSmart<CJSObject> global_js = context->GetGlobal();
JSSmart<CJSObject> js_objectApi = api_js_maybe_null;
if (!js_objectApi.IsInit() || js_objectApi->isUndefined())
@ -313,7 +303,7 @@ namespace NSDoctRenderer
case DoctRendererFormat::XLST:
{
JSSmart<CJSValue> js_result2 = js_objectApi->call_func("asc_nativeGetFileData", 1, args);
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"save\"";
bIsBreak = true;
@ -362,14 +352,14 @@ namespace NSDoctRenderer
}
JSSmart<CJSValue> js_result1 = js_objectApi->call_func("asc_nativeCalculateFile", 1, args);
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"calculate\"";
bIsBreak = true;
}
JSSmart<CJSValue> js_result2 = js_objectApi->call_func("asc_nativeGetHtml", 1, args);
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"save\"";
bIsBreak = true;
@ -401,7 +391,7 @@ namespace NSDoctRenderer
}
JSSmart<CJSValue> js_result2 = js_objectApi->call_func("asc_nativeCalculateFile", 1, args);
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"calculate\"";
bIsBreak = true;
@ -412,7 +402,7 @@ namespace NSDoctRenderer
if (!bIsBreak)
{
JSSmart<CJSValue> js_result1 = js_objectApi->call_func("asc_nativePrintPagesCount", 1, args);
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"calculate\"";
bIsBreak = true;
@ -422,8 +412,7 @@ namespace NSDoctRenderer
}
// RENDER
if (!bIsBreak &&
(DoctRendererFormat::PDF == pParams->m_eDstFormat || DoctRendererFormat::IMAGE == pParams->m_eDstFormat))
if (!bIsBreak && (DoctRendererFormat::PDF == pParams->m_eDstFormat || DoctRendererFormat::IMAGE == pParams->m_eDstFormat))
{
if (pParams->m_sJsonParams.empty())
{
@ -447,7 +436,7 @@ namespace NSDoctRenderer
}
JSSmart<CJSValue> js_result2 = js_objectApi->call_func("asc_nativeGetPDF", 1, args);
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"save\"";
bIsBreak = true;
@ -500,7 +489,7 @@ namespace NSDoctRenderer
js_result2 = js_objectApi->call_func("asc_nativeGetThemeThumbnail", 1, args);
}
if(try_catch->Check())
if (try_catch->Check())
{
strError = L"code=\"save\"";
bIsBreak = true;
@ -582,14 +571,12 @@ namespace NSDoctRenderer
return bIsBreak;
}
bool ExecuteScript(const std::string& strScript, const std::wstring& sCachePath, std::wstring& strError, std::wstring& strReturnParams)
bool ExecuteScript(NSDoctRenderer::DoctRendererEditorType& editorType, std::wstring& strError, std::wstring& strReturnParams)
{
if (strScript.empty() && sCachePath.empty()) return true;
LOGGER_SPEED_START();
bool bIsBreak = false;
JSSmart<CJSContext> context = new CJSContext();
JSSmart<CJSContext> context = NSDoctRenderer::CreateEditorContext(editorType, this);
if (true)
{
@ -598,10 +585,11 @@ namespace NSDoctRenderer
CJSContext::Embed<CGraphicsEmbed>();
NSJSBase::CreateDefaults();
JSSmart<CJSTryCatch> try_catch = context->GetExceptions();
JSSmart<CJSTryCatch> try_catch = context->GetExceptions();
JSSmart<CJSObject> global_js = context->GetGlobal();
global_js->set("window", global_js);
global_js->set("self", global_js);
JSSmart<CJSObject> oNativeCtrl = CJSContext::createEmbedObject("CNativeControlEmbed");
global_js->set("native", oNativeCtrl);
@ -611,8 +599,10 @@ namespace NSDoctRenderer
LOGGER_SPEED_LAP("compile");
JSSmart<CJSValue> res = context->runScript(strScript, try_catch, sCachePath);
if(try_catch->Check())
if (!context->isSnapshotUsed())
NSDoctRenderer::RunEditor(editorType, context, try_catch, this);
if (try_catch->Check())
{
strError = L"code=\"run\"";
bIsBreak = true;
@ -748,8 +738,7 @@ namespace NSDoctRenderer
// 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++)
for (std::map<std::wstring, bool>::const_iterator iter = pNative->m_mapImagesInChanges.begin(); iter != pNative->m_mapImagesInChanges.end(); iter++)
{
m_arImagesInChanges.push_back(iter->first);
}
@ -760,9 +749,7 @@ namespace NSDoctRenderer
LOGGER_SPEED_LAP("changes");
bool bIsMailMerge = false;
if (!m_oParams.m_strMailMergeDatabasePath.empty() &&
m_oParams.m_nMailMergeIndexEnd >= m_oParams.m_nMailMergeIndexStart &&
m_oParams.m_nMailMergeIndexEnd >= 0)
if (!m_oParams.m_strMailMergeDatabasePath.empty() && m_oParams.m_nMailMergeIndexEnd >= m_oParams.m_nMailMergeIndexStart && m_oParams.m_nMailMergeIndexEnd >= 0)
{
bIsMailMerge = true;
}
@ -819,11 +806,10 @@ namespace NSDoctRenderer
if (!bIsBreak)
{
std::string sFieldUtf8 = NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(m_oParams.m_strMailMergeField.c_str(),
(LONG)m_oParams.m_strMailMergeField.length());
std::string sFieldUtf8 = NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(m_oParams.m_strMailMergeField.c_str(), (LONG)m_oParams.m_strMailMergeField.length());
strReturnParams += L"<MailMergeFields>";
for (int nIndexMM = m_oParams.m_nMailMergeIndexStart; nIndexMM <= m_oParams.m_nMailMergeIndexEnd && !bIsBreak; ++nIndexMM)
for (int nIndexMM = m_oParams.m_nMailMergeIndexStart; nIndexMM <= m_oParams.m_nMailMergeIndexEnd && !bIsBreak; ++nIndexMM)
{
JSSmart<CJSValue> args_changes[1];
args_changes[0] = CJSContext::createInt(nIndexMM);
@ -935,7 +921,7 @@ namespace NSDoctRenderer
m_pInternal->m_oParams.FromXml(strXml);
m_pInternal->m_arImagesInChanges.clear();
std::vector<std::wstring>* arSdkFiles = NULL;
NSDoctRenderer::DoctRendererEditorType editorType = NSDoctRenderer::DoctRendererEditorType::INVALID;
switch (m_pInternal->m_oParams.m_eSrcFormat)
{
case DoctRendererFormat::DOCT:
@ -948,7 +934,7 @@ namespace NSDoctRenderer
case DoctRendererFormat::HTML:
case DoctRendererFormat::WATERMARK:
{
arSdkFiles = &m_pInternal->m_arDoctSDK;
editorType = NSDoctRenderer::DoctRendererEditorType::WORD;
m_pInternal->m_strEditorType = L"document";
break;
}
@ -966,7 +952,7 @@ namespace NSDoctRenderer
case DoctRendererFormat::IMAGE:
case DoctRendererFormat::PPTX_THEME_THUMBNAIL:
{
arSdkFiles = &m_pInternal->m_arPpttSDK;
editorType = NSDoctRenderer::DoctRendererEditorType::SLIDE;
m_pInternal->m_strEditorType = L"presentation";
break;
}
@ -983,7 +969,7 @@ namespace NSDoctRenderer
case DoctRendererFormat::PDF:
case DoctRendererFormat::IMAGE:
{
arSdkFiles = &m_pInternal->m_arXlstSDK;
editorType = NSDoctRenderer::DoctRendererEditorType::CELL;
m_pInternal->m_strEditorType = L"spreadsheet";
break;
}
@ -1000,7 +986,7 @@ namespace NSDoctRenderer
case DoctRendererFormat::PDF:
case DoctRendererFormat::IMAGE:
{
arSdkFiles = &m_pInternal->m_arVsdtSDK;
editorType = NSDoctRenderer::DoctRendererEditorType::VISIO;
m_pInternal->m_strEditorType = L"draw";
break;
}
@ -1009,6 +995,21 @@ namespace NSDoctRenderer
}
break;
}
case DoctRendererFormat::PDF:
{
switch (m_pInternal->m_oParams.m_eDstFormat)
{
case DoctRendererFormat::PDF:
{
editorType = NSDoctRenderer::DoctRendererEditorType::PDF;
m_pInternal->m_strEditorType = L"pdf";
break;
}
default:
return false;
}
break;
}
default:
return false;
@ -1026,50 +1027,8 @@ namespace NSDoctRenderer
m_pInternal->m_strFilePath = strFileName;
std::string strScript = "";
for (size_t i = 0; i < m_pInternal->m_arrFiles.size(); ++i)
{
strScript += m_pInternal->ReadScriptFile(m_pInternal->m_arrFiles[i]);
strScript += "\n\n";
}
std::wstring sCachePath = L"";
if (arSdkFiles && (0 < arSdkFiles->size()))
{
if (m_pInternal->m_oParams.m_sScriptsCacheDirectory.empty())
{
sCachePath = NSFile::GetDirectoryName(*arSdkFiles->begin()) + L"/sdk-all.cache";
}
else if (m_pInternal->m_oParams.m_sScriptsCacheDirectory != L"empty")
{
sCachePath = m_pInternal->m_oParams.m_sScriptsCacheDirectory;
wchar_t lastSymbol = sCachePath.back();
if (lastSymbol != '\\' && lastSymbol != '/')
sCachePath += L"/";
wchar_t editorFirst = m_pInternal->m_strEditorType.at(0);
if (editorFirst == 'd' && L"document" == m_pInternal->m_strEditorType)
sCachePath += L"word";
else if (editorFirst == 'p')
sCachePath += L"slide";
else if (editorFirst == 'd')
sCachePath += L"draw";
else
sCachePath += L"cell";
}
for (std::vector<std::wstring>::iterator i = arSdkFiles->begin(); i != arSdkFiles->end(); i++)
{
strScript += m_pInternal->ReadScriptFile(*i);
strScript += "\n\n";
}
}
if (m_pInternal->m_strEditorType == L"spreadsheet")
strScript += "\n$.ready();";
std::wstring sReturnParams = L"";
bool bResult = m_pInternal->ExecuteScript(strScript, sCachePath, strError, sReturnParams);
bool bResult = m_pInternal->ExecuteScript(editorType, strError, sReturnParams);
if (strError.length() != 0)
{
@ -1093,76 +1052,15 @@ namespace NSDoctRenderer
#ifndef JS_ENGINE_JAVASCRIPTCORE
LoadConfig(NSFile::GetProcessDirectory(), sAllFontsPath);
std::wstring sCacheDirectory = sCacheDir;
if (sCacheDirectory.empty() && m_pInternal->m_arDoctSDK.size() > 0)
std::vector<NSDoctRenderer::DoctRendererEditorType> editors;
editors.push_back(NSDoctRenderer::DoctRendererEditorType::WORD);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::SLIDE);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::CELL);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::VISIO);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::PDF);
for (std::vector<NSDoctRenderer::DoctRendererEditorType>::const_iterator i = editors.begin(); i != editors.end(); i++)
{
sCacheDirectory = NSFile::GetDirectoryName(m_pInternal->m_arDoctSDK[0]);
sCacheDirectory = NSFile::GetDirectoryName(sCacheDirectory);
}
if (sCacheDirectory.empty())
return;
std::string strScriptAll = "";
for (size_t i = 0; i < m_pInternal->m_arrFiles.size(); ++i)
{
strScriptAll += m_pInternal->ReadScriptFile(m_pInternal->m_arrFiles[i]);
strScriptAll += "\n\n";
}
for (int i = 0; i < 4; ++i)
{
std::string strScript = strScriptAll;
std::wstring sCachePath = sCacheDirectory;
std::vector<std::wstring>* arSdkFiles = NULL;
switch (i)
{
case 0:
{
arSdkFiles = &m_pInternal->m_arDoctSDK;
sCachePath += L"/word/sdk-all.cache";
break;
}
case 1:
{
arSdkFiles = &m_pInternal->m_arPpttSDK;
sCachePath += L"/slide/sdk-all.cache";
break;
}
case 2:
{
arSdkFiles = &m_pInternal->m_arXlstSDK;
sCachePath += L"/cell/sdk-all.cache";
break;
}
case 3:
{
arSdkFiles = &m_pInternal->m_arVsdtSDK;
sCachePath += L"/draw/sdk-all.cache";
if (0 < arSdkFiles->size() && !NSFile::CFileBinary::Exists(*arSdkFiles->begin()))
{
continue;
}
break;
}
default:
break;
}
if (NSFile::CFileBinary::Exists(sCachePath))
NSFile::CFileBinary::Remove(sCachePath);
for (std::vector<std::wstring>::iterator i = arSdkFiles->begin(); i != arSdkFiles->end(); i++)
{
strScript += m_pInternal->ReadScriptFile(*i);
strScript += "\n\n";
}
if (2 == i)
strScript += "\n$.ready();";
JSSmart<CJSContext> context = new CJSContext();
if (true)
@ -1174,24 +1072,42 @@ namespace NSDoctRenderer
JSSmart<CJSObject> global = context->GetGlobal();
global->set("window", global);
global->set("self", global);
global->set("native", CJSContext::createEmbedObject("CNativeControlEmbed"));
JSSmart<CJSTryCatch> try_catch = context->GetExceptions();
context->runScript(strScript, try_catch, sCachePath);
NSDoctRenderer::RunEditor(*i, context, try_catch, m_pInternal);
}
context->Dispose();
}
#endif
}
}
bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFile,
NSNativeControl::CNativeControl* pNative,
JSSmart<CJSContext> context,
JSSmart<CJSValue>* args,
std::wstring& strError, const std::wstring& jsonParams)
void CDoctrenderer::CreateSnapshots()
{
#ifdef V8_VERSION_89_PLUS
std::vector<NSDoctRenderer::DoctRendererEditorType> editors;
editors.push_back(NSDoctRenderer::DoctRendererEditorType::WORD);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::SLIDE);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::CELL);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::VISIO);
editors.push_back(NSDoctRenderer::DoctRendererEditorType::PDF);
// initialize v8
JSSmart<CJSContext> context = new CJSContext();
for (std::vector<NSDoctRenderer::DoctRendererEditorType>::const_iterator i = editors.begin(); i != editors.end(); i++)
{
NSDoctRenderer::GenerateEditorSnapshot(*i, m_pInternal);
}
#endif
}
} // namespace NSDoctRenderer
bool Doct_renderer_SaveFile_ForBuilder(
int nFormat, const std::wstring& strDstFile, NSNativeControl::CNativeControl* pNative, JSSmart<CJSContext> context, JSSmart<CJSValue>* args, std::wstring& strError, const std::wstring& jsonParams)
{
NSDoctRenderer::CExecuteParams oParams;
oParams.m_eDstFormat = (NSDoctRenderer::DoctRendererFormat::FormatFile)nFormat;
@ -1199,6 +1115,5 @@ bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFi
oParams.m_sJsonParams = jsonParams;
JSSmart<CJSObject> js_objectApi; // empty
return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams,
pNative, context, args, strError, js_objectApi, false);
return NSDoctRenderer::CDoctRenderer_Private::Doct_renderer_SaveFile(&oParams, pNative, context, args, strError, js_objectApi, false);
}

View File

@ -71,6 +71,7 @@ namespace NSDoctRenderer
bool Execute(const std::wstring& strXml, std::wstring& strError);
std::vector<std::wstring> GetImagesInChanges();
void CreateCache(const std::wstring& sAllFontsPath, const std::wstring& sCacheDir);
void CreateSnapshots();
private:
CDoctRenderer_Private* m_pInternal;

View File

@ -16,12 +16,18 @@ DEFINES += DOCTRENDERER_USE_DYNAMIC_LIBRARY_BUILDING
DEFINES += JSBASE_USE_DYNAMIC_LIBRARY_BUILDING
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
# drawingfile support
DEFINES += WASM_SERIALIZER_USE_ALLOCATOR
ADD_DEPENDENCY(PdfFile, XpsFile, DjVuFile, DocxRenderer)
SOURCES += ../../HtmlRenderer/src/HTMLRendererText.cpp
#CONFIG += build_xp
#CONFIG += v8_version_60
core_android:DEFINES += DISABLE_MEMORY_LIMITATION
HEADERS += \
config.h \
editors.h \
doctrenderer.h \
docbuilder.h
@ -43,7 +49,8 @@ HEADERS += \
nativecontrol.h \
graphics.h \
hash.h \
server.h
server.h \
drawingfile.h
HEADERS += \
embed/PointerEmbed.h \
@ -56,6 +63,7 @@ HEADERS += \
embed/TextMeasurerEmbed.h \
embed/HashEmbed.h \
embed/Default.h \
embed/DrawingFileEmbed.h \
js_internal/js_base.h
SOURCES += \
@ -68,7 +76,8 @@ SOURCES += \
embed/NativeBuilderDocumentEmbed.cpp \
embed/TextMeasurerEmbed.cpp \
embed/HashEmbed.cpp \
embed/Default.cpp
embed/Default.cpp \
embed/DrawingFileEmbed.cpp
# Serialize objects to JS
HEADERS += \
@ -101,6 +110,7 @@ ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/NativeControlEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/PointerEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/TextMeasurerEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/ZipEmbed.h)
ADD_FILES_FOR_EMBEDDED_CLASS_HEADER(embed/DrawingFileEmbed.h)
include(../graphics/pro/textshaper.pri)
include(../../Common/3dParty/openssl/openssl.pri)

View File

@ -0,0 +1,493 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* 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)
* 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
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* 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
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* 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
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef DRAWINGFILE_H
#define DRAWINGFILE_H
#include "./common.h"
#include <stddef.h>
#include "../../PdfFile/PdfFile.h"
#include "../../XpsFile/XpsFile.h"
#include "../../DjVuFile/DjVu.h"
#include "../../DesktopEditor/graphics/pro/js/wasm/src/serialize.h"
#include "../../HtmlRenderer/include/HTMLRendererText.h"
#include "../../DocxRenderer/DocxRenderer.h"
class CDrawingFile
{
private:
NSFonts::IApplicationFonts* m_pApplicationFonts;
NSFonts::IFontManager* m_pFontManager;
NSHtmlRenderer::CHTMLRendererText* m_pTextRenderer;
NSDocxRenderer::IImageStorage* m_pImageStorage;
IOfficeDrawingFile* m_pFile;
int m_nType = -1;
public:
CDrawingFile(NSFonts::IApplicationFonts* pFonts)
{
m_pApplicationFonts = pFonts;
ADDREFINTERFACE(m_pApplicationFonts);
m_pFontManager = m_pApplicationFonts->GenerateFontManager();
NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create();
pFontCache->SetStreams(m_pApplicationFonts->GetStreams());
pFontCache->SetCacheSize(8);
m_pFontManager->SetOwnerCache(pFontCache);
m_pTextRenderer = NULL;
m_pImageStorage = NULL;
m_pFile = NULL;
}
~CDrawingFile()
{
RELEASEOBJECT(m_pFile);
RELEASEOBJECT(m_pTextRenderer);
RELEASEOBJECT(m_pFontManager);
RELEASEINTERFACE(m_pApplicationFonts);
RELEASEOBJECT(m_pImageStorage);
}
public:
static void InitFontsGlobalStorage()
{
NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NSFonts::NSApplicationFontStream::CreateDefaultGlobalMemoryStorage());
}
static NSFonts::IFontsMemoryStorage* GetFontsStorage()
{
return NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
}
public:
bool OpenFile(const std::wstring& sFile, const std::wstring& sPassword)
{
CloseFile();
if (NULL == m_pFile)
{
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
}
if (NULL == m_pFile)
{
m_pFile = new CXpsFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 2;
}
if (NULL == m_pFile)
{
m_pFile = new CDjVuFile(m_pApplicationFonts);
if (!m_pFile->LoadFromFile(sFile, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 1;
}
return m_pFile ? true : false;
}
bool OpenFile(BYTE* data, LONG size, const std::wstring& sPassword)
{
CloseFile();
if (NULL == m_pFile)
{
m_pFile = new CPdfFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 0;
}
if (NULL == m_pFile)
{
m_pFile = new CXpsFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 2;
}
if (NULL == m_pFile)
{
m_pFile = new CDjVuFile(m_pApplicationFonts);
if (!m_pFile->LoadFromMemory(data, size, L"", sPassword, sPassword))
{
RELEASEOBJECT(m_pFile);
}
else
m_nType = 1;
}
return m_pFile ? true : false;
}
void CloseFile()
{
if (m_pFile)
RELEASEOBJECT(m_pFile);
m_nType = -1;
}
int GetType()
{
return m_nType;
}
int GetErrorCode()
{
if (!m_pFile)
return -1;
if (0 == m_nType)
return ((CPdfFile*)m_pFile)->GetError();
return 0;
}
BYTE* GetInfo()
{
NSWasm::CData oRes;
oRes.SkipLen();
oRes.AddInt(GetMaxRefID());
int pages_count = GetPagesCount();
oRes.AddInt(pages_count);
for (int page = 0; page < pages_count; ++page)
{
int nW = 0;
int nH = 0;
int nDpi = 0;
int nRotate = 0;
GetPageInfo(page, nW, nH, nDpi, nRotate);
oRes.AddInt(nW);
oRes.AddInt(nH);
oRes.AddInt(nDpi);
oRes.AddInt(nRotate);
}
std::wstring wsInfo = m_pFile->GetInfo();
std::string sInfo = U_TO_UTF8(wsInfo);
oRes.WriteString((BYTE*)sInfo.c_str(), sInfo.length());
oRes.WriteLen();
BYTE* bRes = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return bRes;
}
BYTE* GetPixmap(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor)
{
if (!m_pFile)
return NULL;
return m_pFile->ConvertToPixels(nPageIndex, nRasterW, nRasterH, true, m_pFontManager, nBackgroundColor, (nBackgroundColor == 0xFFFFFF) ? false : true);
}
BYTE* GetGlyphs(int nPageIndex)
{
if (NULL == m_pTextRenderer)
m_pTextRenderer = new NSHtmlRenderer::CHTMLRendererText();
m_pTextRenderer->Init(m_pFile, 8);
m_pFile->DrawPageOnRenderer(m_pTextRenderer, nPageIndex, NULL);
return m_pTextRenderer->GetBuffer();
}
BYTE* GetLinks(int nPageIndex)
{
return m_pFile->GetLinks(nPageIndex);
}
BYTE* GetStructure()
{
return m_pFile->GetStructure();
}
BYTE* GetInteractiveFormsInfo()
{
if (m_nType == 0)
return ((CPdfFile*)m_pFile)->GetWidgets();
return NULL;
}
BYTE* GetInteractiveFormsFonts(int nTypeFonts)
{
if (m_nType == 0)
{
if (nTypeFonts == 1)
return ((CPdfFile*)m_pFile)->GetAnnotEmbeddedFonts();
if (nTypeFonts == 2)
return ((CPdfFile*)m_pFile)->GetAnnotStandardFonts();
}
return NULL;
}
BYTE* GetInteractiveFormsAP(int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget, int nView, int nButtonView)
{
if (0 != m_nType)
return NULL;
const char* sView = NULL;
if (nView == 0)
sView = "N";
else if (nView == 1)
sView = "D";
else if (nView == 2)
sView = "R";
const char* sButtonView = NULL;
if (nButtonView == 0)
sButtonView = "Off";
else if (nButtonView == 1)
sButtonView = "Yes";
return ((CPdfFile*)m_pFile)->GetAPWidget(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nWidget, sView, sButtonView);
}
BYTE* GetButtonIcons(int nBackgroundColor, int nPageIndex, int bBase64, int nButtonWidget, int nIconView)
{
if (0 != m_nType)
return NULL;
const char* sIconView = NULL;
if (nIconView == 0)
sIconView = "I";
else if (nIconView == 1)
sIconView = "RI";
else if (nIconView == 2)
sIconView = "IX";
return ((CPdfFile*)m_pFile)->GetButtonIcon(nBackgroundColor, nPageIndex, bBase64 ? true : false, nButtonWidget, sIconView);
}
BYTE* GetAnnotationsInfo(int nPageIndex)
{
if (m_nType == 0)
return ((CPdfFile*)m_pFile)->GetAnnots(nPageIndex);
return NULL;
}
BYTE* GetAnnotationsAP(int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot, int nView)
{
if (m_nType != 0)
return NULL;
const char* sView = NULL;
if (nView == 0)
sView = "N";
else if (nView == 1)
sView = "D";
else if (nView == 2)
sView = "R";
return ((CPdfFile*)m_pFile)->GetAPAnnots(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nAnnot, sView);
}
void DestroyTextInfo()
{
RELEASEOBJECT(m_pTextRenderer);
}
bool IsNeedCMap()
{
if (m_nType == 0)
return ((CPdfFile*)m_pFile)->IsNeedCMap();
return false;
}
void SetCMapData(BYTE* data, int size)
{
if (m_nType == 0)
((CPdfFile*)m_pFile)->SetCMapMemory(data, size);
}
BYTE* ScanPage(int nPageIndex, int mode)
{
if (NULL == m_pImageStorage)
m_pImageStorage = NSDocxRenderer::CreateWasmImageStorage();
CDocxRenderer oRenderer(m_pApplicationFonts);
oRenderer.SetExternalImageStorage(m_pImageStorage);
oRenderer.SetTextAssociationType(NSDocxRenderer::TextAssociationType::tatParagraphToShape);
std::vector<std::wstring> arShapes;
if (0 == mode)
arShapes = oRenderer.ScanPage(m_pFile, nPageIndex);
else
arShapes = oRenderer.ScanPagePptx(m_pFile, nPageIndex);
int nLen = (int)arShapes.size();
NSWasm::CData oRes;
oRes.SkipLen();
oRes.AddInt(nLen);
for (int i = 0; i < nLen; ++i)
oRes.WriteString(arShapes[i]);
oRes.WriteLen();
BYTE* res = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return res;
}
void* GetImageBase64(int rId)
{
if (NULL == m_pImageStorage)
return NULL;
return m_pImageStorage->GetBase64(rId);
}
int GetImageBase64Len(std::string* p)
{
return (int)p->length();
}
char* GetImageBase64Ptr(std::string* p)
{
return (char*)p->c_str();
}
void GetImageBase64Free(std::string* p)
{
*p = "";
}
void SetFontBinary(char* path, BYTE* data, int size)
{
NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
if (pStorage)
{
std::string sPathA(path);
pStorage->Add(UTF8_TO_U(sPathA), data, size, true);
}
}
int IsFontBinaryExist(char* path)
{
NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
if (pStorage)
{
std::string sPathA(path);
NSFonts::IFontStream* pStream = pStorage->Get(UTF8_TO_U(sPathA));
if (pStream)
return 1;
}
return 0;
}
BYTE* GetFontBinary(const std::string& sPathA)
{
std::wstring sFontName = UTF8_TO_U(sPathA);
std::wstring sFontFile;
if (m_nType == 0)
sFontFile = ((CPdfFile*)m_pFile)->GetFontPath(sFontName);
if (sFontFile.empty())
sFontFile = sFontName;
NSFonts::IFontsMemoryStorage* pStorage = GetFontsStorage();
if (pStorage)
{
NSFonts::IFontStream* pStream = pStorage->Get(sFontFile);
if (pStream)
{
BYTE* pData = NULL;
LONG lLength = 0;
pStream->GetMemory(pData, lLength);
if (pData)
{
NSWasm::CData oRes;
oRes.SkipLen();
oRes.AddInt(lLength);
unsigned long long npSubMatrix = (unsigned long long)pData;
unsigned int npSubMatrix1 = npSubMatrix & 0xFFFFFFFF;
oRes.AddInt(npSubMatrix1);
oRes.AddInt(npSubMatrix >> 32);
oRes.WriteLen();
BYTE* bRes = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return bRes;
}
}
}
return NULL;
}
private:
int GetPagesCount()
{
return m_pFile->GetPagesCount();
}
int GetMaxRefID()
{
if (m_nType == 0)
return ((CPdfFile*)m_pFile)->GetMaxRefID();
return 0;
}
void GetPageInfo(int nPageIndex, int& nWidth, int& nHeight, int& nPageDpiX, int& nRotate)
{
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
m_pFile->GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
if (m_nType == 2)
{
dWidth = dWidth / 25.4 * 96.0;
dHeight = dHeight / 25.4 * 96.0;
dPageDpiX = dPageDpiX / 25.4 * 96.0;
}
if (m_nType == 0)
nRotate = ((CPdfFile*)m_pFile)->GetRotate(nPageIndex);
nWidth = dWidth;
nHeight = dHeight;
nPageDpiX = dPageDpiX;
}
};
#endif // DRAWINGFILE_H

View File

@ -0,0 +1,306 @@
/*
* (c) Copyright Ascensio System SIA 2010-2023
*
* 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)
* 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
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* 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
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* 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
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#ifndef DOC_BUILDER_EDITORS_CONFIG
#define DOC_BUILDER_EDITORS_CONFIG
#include "./config.h"
#include "../js_internal/js_base.h"
#include "../common/StringBuilder.h"
#ifdef CreateFile
#undef CreateFile
#endif
namespace NSDoctRenderer
{
enum class DoctRendererEditorType
{
WORD = 0,
CELL = 1,
SLIDE = 2,
VISIO = 3,
PDF = 4,
INVALID = 255
};
static void AppendScript(NSStringUtils::CStringBuilderA* builder, const std::wstring& path)
{
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(path))
return;
int size = (int)oFile.GetFileSize();
if (size < 3)
return;
BYTE* pData = new BYTE[size];
DWORD dwReadSize = 0;
oFile.ReadFile(pData, (DWORD)size, dwReadSize);
oFile.CloseFile();
int nOffset = 0;
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
nOffset = 3;
builder->WriteString((char*)(pData + nOffset), size - nOffset);
builder->WriteString("\n\n");
RELEASEARRAYOBJECTS(pData);
}
static bool RunScript(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, const std::wstring& path)
{
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(path))
return false;
int size = (int)oFile.GetFileSize();
if (size < 3)
return false;
BYTE* pData = new BYTE[size];
DWORD dwReadSize = 0;
oFile.ReadFile(pData, (DWORD)size, dwReadSize);
oFile.CloseFile();
int nOffset = 0;
if (pData[0] == 0xEF && pData[1] == 0xBB && pData[2] == 0xBF)
nOffset = 3;
context->runScript(std::string((char*)(pData + nOffset), size - nOffset), try_catch);
RELEASEARRAYOBJECTS(pData);
return !try_catch->Check();
}
static std::wstring GetAllScript(NSStringUtils::CStringBuilderA* builder, const DoctRendererEditorType& type, CDoctRendererConfig* config, const bool& isSnapshot = false)
{
for (std::vector<std::wstring>::const_iterator i = config->m_arrFiles.cbegin(); i != config->m_arrFiles.cend(); i++)
AppendScript(builder, *i);
std::wstring sFontsPath = config->m_strSdkPath + L"/common/libfont/engine";
#ifdef SUPPORT_HARFBUZZ_SHAPER
sFontsPath += L"/fonts_native.js";
#else
sFontsPath += L"/fonts_ie.js";
#endif
std::wstring sCachePath = L"";
switch (type)
{
case DoctRendererEditorType::WORD:
{
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all-min.js");
AppendScript(builder, sFontsPath);
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
sCachePath = config->m_strSdkPath + L"/word/sdk-all";
break;
}
case DoctRendererEditorType::SLIDE:
{
AppendScript(builder, config->m_strSdkPath + L"/slide/sdk-all-min.js");
AppendScript(builder, sFontsPath);
AppendScript(builder, config->m_strSdkPath + L"/slide/sdk-all.js");
sCachePath = config->m_strSdkPath + L"/slide/sdk-all";
break;
}
case DoctRendererEditorType::CELL:
{
AppendScript(builder, config->m_strSdkPath + L"/cell/sdk-all-min.js");
AppendScript(builder, sFontsPath);
AppendScript(builder, config->m_strSdkPath + L"/cell/sdk-all.js");
builder->WriteString("\n$.ready();", 11);
sCachePath = config->m_strSdkPath + L"/cell/sdk-all";
break;
}
case DoctRendererEditorType::VISIO:
{
if (!NSFile::CFileBinary::Exists(config->m_strSdkPath + L"/draw/sdk-all-min.js"))
return L"";
AppendScript(builder, config->m_strSdkPath + L"/draw/sdk-all-min.js");
AppendScript(builder, sFontsPath);
AppendScript(builder, config->m_strSdkPath + L"/draw/sdk-all.js");
sCachePath = config->m_strSdkPath + L"/draw/sdk-all";
break;
}
case DoctRendererEditorType::PDF:
{
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all-min.js");
AppendScript(builder, sFontsPath);
AppendScript(builder, config->m_strSdkPath + L"/word/sdk-all.js");
AppendScript(builder, config->m_strSdkPath + L"/pdf/src/engine/drawingfile_native.js");
sCachePath = config->m_strSdkPath + L"/pdf/sdk-all";
break;
}
default:
break;
}
if (!sCachePath.empty())
sCachePath += (isSnapshot ? L".bin" : L".cache");
return sCachePath;
}
static std::wstring GetSnapshotPath(const DoctRendererEditorType& type, CDoctRendererConfig* config)
{
std::wstring sCachePath = L"";
switch (type)
{
case DoctRendererEditorType::WORD:
{
return config->m_strSdkPath + L"/word/sdk-all.bin";
}
case DoctRendererEditorType::SLIDE:
{
return config->m_strSdkPath + L"/slide/sdk-all.bin";
}
case DoctRendererEditorType::CELL:
{
return config->m_strSdkPath + L"/cell/sdk-all.bin";
}
case DoctRendererEditorType::VISIO:
{
return config->m_strSdkPath + L"/draw/sdk-all.bin";
}
case DoctRendererEditorType::PDF:
{
return config->m_strSdkPath + L"/pdf/sdk-all.bin";
}
default:
break;
}
return L"";
}
static bool RunEditorFooter(JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config)
{
if (!RunScript(context, try_catch, config->m_strAllFonts))
return false;
std::string sFooter = "\
window.InitNativeObject();\
window.InitNativeTextMeasurer();\
window.InitNativeZLib();\
AscFonts.checkAllFonts();\n";
if (context->isSnapshotUsed())
{
sFooter += "\
if (undefined === String.prototype.replaceAll)\
{\
String.prototype.replaceAll = function(str, newStr)\
{\
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]')\
return this.replace(str, newStr);\
return this.split(str).join(newStr);\
};\
}\n";
}
context->runScript(sFooter, try_catch);
return !try_catch->Check();
}
static bool RunEditor(const DoctRendererEditorType& type, JSSmart<NSJSBase::CJSContext>& context, JSSmart<NSJSBase::CJSTryCatch>& try_catch, CDoctRendererConfig* config)
{
NSStringUtils::CStringBuilderA builder;
builder.AddSize(10 * 1024 * 1024);
std::wstring sCachePath = GetAllScript(&builder, type, config);
if (!sCachePath.empty())
{
context->runScript(builder.GetData(), try_catch, config->m_bIsUseCache ? sCachePath : L"");
RunEditorFooter(context, try_catch, config);
}
return !try_catch->Check();
}
static bool GenerateEditorSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config)
{
NSStringUtils::CStringBuilderA builder;
builder.AddSize(10 * 1024 * 1024);
std::wstring sCachePath = GetAllScript(&builder, type, config, true);
builder.WriteString("delete String.prototype.replaceAll;");
if (sCachePath.empty())
return false;
return NSJSBase::CJSContext::generateSnapshot(builder.GetData(), sCachePath);
}
static JSSmart<NSJSBase::CJSContext> RunEditorWithSnapshot(const DoctRendererEditorType& type, CDoctRendererConfig* config)
{
#ifndef V8_VERSION_89_PLUS
return NULL;
#endif
#ifndef V8_SUPPORT_SNAPSHOTS
return NULL;
#endif
std::wstring sCachePath = GetSnapshotPath(type, config);
if (!NSFile::CFileBinary::Exists(sCachePath))
return NULL;
if (sCachePath.empty())
return NULL;
JSSmart<NSJSBase::CJSContext> context = new NSJSBase::CJSContext(false);
context->Initialize(sCachePath);
NSJSBase::CJSContextScope scope(context);
JSSmart<NSJSBase::CJSTryCatch> try_catch = context->GetExceptions();
if (!RunEditorFooter(context, try_catch, config))
return NULL;
return context;
}
static JSSmart<NSJSBase::CJSContext> CreateEditorContext(const DoctRendererEditorType& type, CDoctRendererConfig* config)
{
JSSmart<NSJSBase::CJSContext> context = RunEditorWithSnapshot(type, config);
if (context.is_init())
return context;
return new NSJSBase::CJSContext();
}
}
#endif // DOC_BUILDER_EDITORS_CONFIG

View File

@ -1,7 +1,7 @@
#ifndef _BUILD_NATIVE_DEFAULT_EMBED_H_
#define _BUILD_NATIVE_DEFAULT_EMBED_H_
#include "../js_internal/js_base.h"
#include "../js_internal/js_base.h"
namespace NSJSBase
{

View File

@ -0,0 +1,119 @@
#include "DrawingFileEmbed.h"
JSSmart<CJSValue> MoveMemoryToJS(BYTE* pWasmData)
{
if (NULL == pWasmData)
return CJSContext::createNull();
int nLen = 0;
memcpy(&nLen, pWasmData, sizeof(int));
if (4 >= nLen)
return CJSContext::createNull();
size_t nBufferSize = (size_t)(nLen - 4);
BYTE* pMemory = NSJSBase::NSAllocator::Alloc(nBufferSize);
memcpy(pMemory, pWasmData + 4, nBufferSize);
free(pWasmData);
return NSJSBase::CJSContext::createUint8Array(pMemory, (int)nBufferSize, false);
}
JSSmart<CJSValue> CDrawingFileEmbed::OpenFile(JSSmart<CJSValue> sFile, JSSmart<CJSValue> sPassword)
{
bool bResult = m_pFile->OpenFile(sFile->toStringW(), sPassword->isString() ? sPassword->toStringW() : L"");
return CJSContext::createBool(bResult);
}
JSSmart<CJSValue> CDrawingFileEmbed::CloseFile()
{
m_pFile->CloseFile();
return CJSContext::createUndefined();
}
JSSmart<CJSValue> CDrawingFileEmbed::GetType()
{
return CJSContext::createInt(m_pFile->GetType());
}
JSSmart<CJSValue> CDrawingFileEmbed::GetErrorCode()
{
return CJSContext::createInt(m_pFile->GetErrorCode());
}
JSSmart<CJSValue> CDrawingFileEmbed::GetInfo()
{
return MoveMemoryToJS(m_pFile->GetInfo());
}
JSSmart<CJSValue> CDrawingFileEmbed::GetPixmap(JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor)
{
return MoveMemoryToJS(m_pFile->GetPixmap(nPageIndex->toInt32(), nRasterW->toInt32(), nRasterH->toInt32(), nBackgroundColor->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetGlyphs(JSSmart<CJSValue> nPageIndex)
{
return MoveMemoryToJS(m_pFile->GetGlyphs(nPageIndex->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetLinks(JSSmart<CJSValue> nPageIndex)
{
return MoveMemoryToJS(m_pFile->GetLinks(nPageIndex->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetStructure()
{
return MoveMemoryToJS(m_pFile->GetStructure());
}
JSSmart<CJSValue> CDrawingFileEmbed::GetInteractiveFormsInfo()
{
return MoveMemoryToJS(m_pFile->GetInteractiveFormsInfo());
}
JSSmart<CJSValue> CDrawingFileEmbed::GetInteractiveFormsFonts(JSSmart<CJSValue> nTypeFonts)
{
return MoveMemoryToJS(m_pFile->GetInteractiveFormsFonts(nTypeFonts->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetInteractiveFormsAP(JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor,
JSSmart<CJSValue> nPageIndex,
JSSmart<CJSValue> nWidget, JSSmart<CJSValue> nView, JSSmart<CJSValue> nButtonView)
{
return MoveMemoryToJS(m_pFile->GetInteractiveFormsAP(nRasterW->toInt32(), nRasterH->toInt32(), nBackgroundColor->toInt32(),
nPageIndex->toInt32(),
nWidget->toInt32(), nView->toInt32(), nButtonView->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetButtonIcons(JSSmart<CJSValue> nBackgroundColor, JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> bBase64,
JSSmart<CJSValue> nButtonWidget, JSSmart<CJSValue> nIconView)
{
return MoveMemoryToJS(m_pFile->GetButtonIcons(nBackgroundColor->toInt32(), nPageIndex->toInt32(), bBase64->toInt32(),
nButtonWidget->toInt32(), nIconView->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetAnnotationsInfo(JSSmart<CJSValue> nPageIndex)
{
return MoveMemoryToJS(m_pFile->GetAnnotationsInfo(nPageIndex->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetAnnotationsAP(JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor,
JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nAnnot, JSSmart<CJSValue> nView)
{
return MoveMemoryToJS(m_pFile->GetAnnotationsAP(nRasterW->toInt32(), nRasterH->toInt32(), nBackgroundColor->toInt32(),
nPageIndex->toInt32(), nAnnot->toInt32(), nView->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::DestroyTextInfo()
{
m_pFile->DestroyTextInfo();
return CJSContext::createUndefined();
}
JSSmart<CJSValue> CDrawingFileEmbed::IsNeedCMap()
{
return CJSContext::createBool(false);
}
JSSmart<CJSValue> CDrawingFileEmbed::ScanPage(JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> mode)
{
return MoveMemoryToJS(m_pFile->ScanPage(nPageIndex->toInt32(), mode->toInt32()));
}
JSSmart<CJSValue> CDrawingFileEmbed::GetImageBase64(JSSmart<CJSValue> rId)
{
std::string* pData = (std::string*)m_pFile->GetImageBase64(rId->toInt32());
if (!pData)
return CJSContext::createNull();
JSSmart<CJSValue> ret = CJSContext::createString(*pData);
*pData = "";
return ret;
}

View File

@ -0,0 +1,56 @@
#ifndef _BUILD_DRAWING_EMBED_H_
#define _BUILD_DRAWING_EMBED_H_
#include "../drawingfile.h"
#include "../js_internal/js_base.h"
using namespace NSJSBase;
class JS_DECL CDrawingFileEmbed : public CJSEmbedObject
{
public:
CDrawingFile* m_pFile;
public:
CDrawingFileEmbed()
{
m_pFile = NULL;
}
~CDrawingFileEmbed()
{
RELEASEOBJECT(m_pFile);
}
virtual void* getObject() override { return (void*)m_pFile; }
public:
JSSmart<CJSValue> OpenFile(JSSmart<CJSValue> sFile, JSSmart<CJSValue> sPassword);
JSSmart<CJSValue> CloseFile();
JSSmart<CJSValue> GetType();
JSSmart<CJSValue> GetErrorCode();
JSSmart<CJSValue> GetInfo();
JSSmart<CJSValue> GetPixmap(JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor);
JSSmart<CJSValue> GetGlyphs(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> GetLinks(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> GetStructure();
JSSmart<CJSValue> GetInteractiveFormsInfo();
JSSmart<CJSValue> GetInteractiveFormsFonts(JSSmart<CJSValue> nTypeFonts);
JSSmart<CJSValue> GetInteractiveFormsAP(JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor, JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nWidget, JSSmart<CJSValue> nView, JSSmart<CJSValue> nButtonView);
JSSmart<CJSValue> GetButtonIcons(JSSmart<CJSValue> nBackgroundColor, JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> bBase64, JSSmart<CJSValue> nButtonWidget, JSSmart<CJSValue> nIconView);
JSSmart<CJSValue> GetAnnotationsInfo(JSSmart<CJSValue> nPageIndex);
JSSmart<CJSValue> GetAnnotationsAP(JSSmart<CJSValue> nRasterW, JSSmart<CJSValue> nRasterH, JSSmart<CJSValue> nBackgroundColor, JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> nAnnot, JSSmart<CJSValue> nView);
JSSmart<CJSValue> DestroyTextInfo();
JSSmart<CJSValue> IsNeedCMap();
JSSmart<CJSValue> ScanPage(JSSmart<CJSValue> nPageIndex, JSSmart<CJSValue> mode);
JSSmart<CJSValue> GetImageBase64(JSSmart<CJSValue> rId);
DECLARE_EMBED_METHODS
};
#endif // _BUILD_NATIVE_ZIP_EMBED_H_

View File

@ -0,0 +1,81 @@
// THIS FILE WAS GENERATED AUTOMATICALLY. DO NOT CHANGE IT!
// IF YOU NEED TO UPDATE THIS CODE, JUST RERUN PYTHON SCRIPT WITH "--internal" OPTION.
#include "../DrawingFileEmbed.h"
#include "../../js_internal/jsc/jsc_base.h"
@protocol IJSCDrawingFileEmbed <JSExport>
-(JSValue*) OpenFile : (JSValue*)sFile : (JSValue*)sPassword;
-(JSValue*) CloseFile;
-(JSValue*) GetType;
-(JSValue*) GetErrorCode;
-(JSValue*) GetInfo;
-(JSValue*) GetPixmap : (JSValue*)nPageIndex : (JSValue*)nRasterW : (JSValue*)nRasterH : (JSValue*)nBackgroundColor;
-(JSValue*) GetGlyphs : (JSValue*)nPageIndex;
-(JSValue*) GetLinks : (JSValue*)nPageIndex;
-(JSValue*) GetStructure;
-(JSValue*) GetInteractiveFormsInfo;
-(JSValue*) GetInteractiveFormsFonts : (JSValue*)nTypeFonts;
-(JSValue*) GetInteractiveFormsAP : (JSValue*)nRasterW : (JSValue*)nRasterH : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)nWidget : (JSValue*)nView : (JSValue*)nButtonView;
-(JSValue*) GetButtonIcons : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)bBase64 : (JSValue*)nButtonWidget : (JSValue*)nIconView;
-(JSValue*) GetAnnotationsInfo : (JSValue*)nPageIndex;
-(JSValue*) GetAnnotationsAP : (JSValue*)nRasterW : (JSValue*)nRasterH : (JSValue*)nBackgroundColor : (JSValue*)nPageIndex : (JSValue*)nAnnot : (JSValue*)nView;
-(JSValue*) DestroyTextInfo;
-(JSValue*) IsNeedCMap;
-(JSValue*) ScanPage : (JSValue*)nPageIndex : (JSValue*)mode;
-(JSValue*) GetImageBase64 : (JSValue*)rId;
@end
@interface CJSCDrawingFileEmbed : NSObject<IJSCDrawingFileEmbed, JSEmbedObjectProtocol>
{
@public
CDrawingFileEmbed* m_internal;
}
@end
@implementation CJSCDrawingFileEmbed
EMBED_OBJECT_WRAPPER_METHODS(CDrawingFileEmbed);
FUNCTION_WRAPPER_JS_2(OpenFile, OpenFile)
FUNCTION_WRAPPER_JS_0(CloseFile, CloseFile)
FUNCTION_WRAPPER_JS_0(GetType, GetType)
FUNCTION_WRAPPER_JS_0(GetErrorCode, GetErrorCode)
FUNCTION_WRAPPER_JS_0(GetInfo, GetInfo)
FUNCTION_WRAPPER_JS_4(GetPixmap, GetPixmap)
FUNCTION_WRAPPER_JS_1(GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_JS_1(GetLinks, GetLinks)
FUNCTION_WRAPPER_JS_0(GetStructure, GetStructure)
FUNCTION_WRAPPER_JS_0(GetInteractiveFormsInfo, GetInteractiveFormsInfo)
FUNCTION_WRAPPER_JS_1(GetInteractiveFormsFonts, GetInteractiveFormsFonts)
FUNCTION_WRAPPER_JS_7(GetInteractiveFormsAP, GetInteractiveFormsAP)
FUNCTION_WRAPPER_JS_5(GetButtonIcons, GetButtonIcons)
FUNCTION_WRAPPER_JS_1(GetAnnotationsInfo, GetAnnotationsInfo)
FUNCTION_WRAPPER_JS_6(GetAnnotationsAP, GetAnnotationsAP)
FUNCTION_WRAPPER_JS_0(DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_JS_0(IsNeedCMap, IsNeedCMap)
FUNCTION_WRAPPER_JS_2(ScanPage, ScanPage)
FUNCTION_WRAPPER_JS_1(GetImageBase64, GetImageBase64)
@end
class CDrawingFileEmbedAdapter : public CJSEmbedObjectAdapterJSC
{
public:
virtual id getExportedObject(CJSEmbedObject* pNative) override
{
return [[CJSCDrawingFileEmbed alloc] init:(CDrawingFileEmbed*)pNative];
}
};
CJSEmbedObjectAdapterBase* CDrawingFileEmbed::getAdapter()
{
if (m_pAdapter == nullptr)
m_pAdapter = new CDrawingFileEmbedAdapter();
return m_pAdapter;
}
std::string CDrawingFileEmbed::getName() { return "CDrawingFileEmbed"; }
CJSEmbedObject* CDrawingFileEmbed::getCreator()
{
return new CDrawingFileEmbed();
}

View File

@ -0,0 +1,84 @@
// THIS FILE WAS GENERATED AUTOMATICALLY. DO NOT CHANGE IT!
// IF YOU NEED TO UPDATE THIS CODE, JUST RERUN PYTHON SCRIPT WITH "--internal" OPTION.
#include "../DrawingFileEmbed.h"
#include "../../js_internal/v8/v8_base.h"
namespace NSDrawingFileEmbed
{
#define CURRENTWRAPPER CDrawingFileEmbed
FUNCTION_WRAPPER_V8_2(_OpenFile, OpenFile)
FUNCTION_WRAPPER_V8_0(_CloseFile, CloseFile)
FUNCTION_WRAPPER_V8_0(_GetType, GetType)
FUNCTION_WRAPPER_V8_0(_GetErrorCode, GetErrorCode)
FUNCTION_WRAPPER_V8_0(_GetInfo, GetInfo)
FUNCTION_WRAPPER_V8_4(_GetPixmap, GetPixmap)
FUNCTION_WRAPPER_V8_1(_GetGlyphs, GetGlyphs)
FUNCTION_WRAPPER_V8_1(_GetLinks, GetLinks)
FUNCTION_WRAPPER_V8_0(_GetStructure, GetStructure)
FUNCTION_WRAPPER_V8_0(_GetInteractiveFormsInfo, GetInteractiveFormsInfo)
FUNCTION_WRAPPER_V8_1(_GetInteractiveFormsFonts, GetInteractiveFormsFonts)
FUNCTION_WRAPPER_V8_7(_GetInteractiveFormsAP, GetInteractiveFormsAP)
FUNCTION_WRAPPER_V8_5(_GetButtonIcons, GetButtonIcons)
FUNCTION_WRAPPER_V8_1(_GetAnnotationsInfo, GetAnnotationsInfo)
FUNCTION_WRAPPER_V8_6(_GetAnnotationsAP, GetAnnotationsAP)
FUNCTION_WRAPPER_V8_0(_DestroyTextInfo, DestroyTextInfo)
FUNCTION_WRAPPER_V8_0(_IsNeedCMap, IsNeedCMap)
FUNCTION_WRAPPER_V8_2(_ScanPage, ScanPage)
FUNCTION_WRAPPER_V8_1(_GetImageBase64, GetImageBase64)
v8::Handle<v8::ObjectTemplate> CreateTemplate(v8::Isolate* isolate)
{
v8::EscapableHandleScope handle_scope(isolate);
v8::Local<v8::ObjectTemplate> result = v8::ObjectTemplate::New(isolate);
result->SetInternalFieldCount(1);
NSV8Objects::Template_Set(result, "OpenFile", _OpenFile);
NSV8Objects::Template_Set(result, "CloseFile", _CloseFile);
NSV8Objects::Template_Set(result, "GetType", _GetType);
NSV8Objects::Template_Set(result, "GetErrorCode", _GetErrorCode);
NSV8Objects::Template_Set(result, "GetInfo", _GetInfo);
NSV8Objects::Template_Set(result, "GetPixmap", _GetPixmap);
NSV8Objects::Template_Set(result, "GetGlyphs", _GetGlyphs);
NSV8Objects::Template_Set(result, "GetLinks", _GetLinks);
NSV8Objects::Template_Set(result, "GetStructure", _GetStructure);
NSV8Objects::Template_Set(result, "GetInteractiveFormsInfo", _GetInteractiveFormsInfo);
NSV8Objects::Template_Set(result, "GetInteractiveFormsFonts", _GetInteractiveFormsFonts);
NSV8Objects::Template_Set(result, "GetInteractiveFormsAP", _GetInteractiveFormsAP);
NSV8Objects::Template_Set(result, "GetButtonIcons", _GetButtonIcons);
NSV8Objects::Template_Set(result, "GetAnnotationsInfo", _GetAnnotationsInfo);
NSV8Objects::Template_Set(result, "GetAnnotationsAP", _GetAnnotationsAP);
NSV8Objects::Template_Set(result, "DestroyTextInfo", _DestroyTextInfo);
NSV8Objects::Template_Set(result, "IsNeedCMap", _IsNeedCMap);
NSV8Objects::Template_Set(result, "ScanPage", _ScanPage);
NSV8Objects::Template_Set(result, "GetImageBase64", _GetImageBase64);
return handle_scope.Escape(result);
}
}
class CDrawingFileEmbedAdapter : public CJSEmbedObjectAdapterV8Template
{
public:
virtual v8::Local<v8::ObjectTemplate> getTemplate(v8::Isolate* isolate) override
{
v8::EscapableHandleScope handle_scope(isolate);
v8::Local<v8::ObjectTemplate> templ = NSDrawingFileEmbed::CreateTemplate(isolate);
return handle_scope.Escape(templ);
}
};
CJSEmbedObjectAdapterBase* CDrawingFileEmbed::getAdapter()
{
if (m_pAdapter == nullptr)
m_pAdapter = new CDrawingFileEmbedAdapter();
return m_pAdapter;
}
std::string CDrawingFileEmbed::getName() { return "CDrawingFileEmbed"; }
CJSEmbedObject* CDrawingFileEmbed::getCreator()
{
return new CDrawingFileEmbed();
}

View File

@ -440,14 +440,21 @@ namespace NSJSBase
/**
* Initializes the JS context.
* By default it happens automatically when creating a CJSConext instance.
* @param snapshotPath Path to snapshot file.
*/
void Initialize();
void Initialize(const std::wstring& snapshotPath = L"");
/**
* Releases any resources taken by the JS context.
* Generally there is no need to call it manually, cause this method called when CJSConext is being destructed.
*/
void Dispose();
/**
* Get information about snapshot
* @return Returns true if snapshot was used on Initialize method
*/
bool isSnapshotUsed();
/**
* Creates and returns the pointer to an object for tracking exceptions during code execution in current JS context.
*/
@ -480,6 +487,15 @@ namespace NSJSBase
AddEmbedCreator(T::getName(), T::getCreator, isAllowedInJS);
}
/**
* Generate snapshot by script.
* @param script The script to be executed.
* @param exception The object for handling exceptions.
* @param snapshotPath The path to the snapshot
* @return Returns true whether a snapshot has been created.
*/
static bool generateSnapshot(const std::string& script, const std::wstring& snapshotPath);
/**
* Run the script in the current JS context.
* @param script The script to be executed.

View File

@ -215,7 +215,7 @@ namespace NSJSBase
return new CJSCTryCatch();
}
void CJSContext::Initialize()
void CJSContext::Initialize(const std::wstring& snapshotPath)
{
m_internal->context = [[JSContext alloc] init];
@ -249,6 +249,11 @@ namespace NSJSBase
m_internal->context = nil;
}
bool CJSContext::isSnapshotUsed()
{
return false;
}
JSSmart<CJSObject> CJSContext::GetGlobal()
{
CJSObjectJSC* ret = new CJSObjectJSC();
@ -346,6 +351,11 @@ namespace NSJSBase
return _value;
}
bool CJSContext::generateSnapshot(const std::string& script, const std::wstring& snapshotPath)
{
return false;
}
JSSmart<CJSValue> CJSContext::runScript(const std::string& script, JSSmart<CJSTryCatch> exception, const std::wstring& scriptPath)
{
CJSValueJSC* _value = new CJSValueJSC();

View File

@ -188,12 +188,25 @@ namespace NSJSBase
return new CV8TryCatch();
}
void CJSContext::Initialize()
void CJSContext::Initialize(const std::wstring& snapshotPath)
{
if (m_internal->m_isolate == NULL)
{
#ifdef V8_VERSION_89_PLUS
if (!snapshotPath.empty())
{
BYTE* data = NULL;
DWORD dataLength = 0;
if (NSFile::CFileBinary::ReadAllBytes(snapshotPath, &data, dataLength))
{
m_internal->m_startup_data.data = reinterpret_cast<const char*>(data);
m_internal->m_startup_data.raw_size = (int)dataLength;
}
}
#endif
// get new isolate
v8::Isolate* isolate = CV8Worker::getInitializer().CreateNew();
v8::Isolate* isolate = CV8Worker::getInitializer().CreateNew(m_internal->m_startup_data.data ? &m_internal->m_startup_data : nullptr);
m_internal->m_isolate = isolate;
// get new context
v8::Isolate::Scope iscope(isolate);
@ -219,6 +232,11 @@ namespace NSJSBase
m_internal->m_isolate = NULL;
}
bool CJSContext::isSnapshotUsed()
{
return m_internal->m_startup_data.data != NULL;
}
JSSmart<CJSObject> CJSContext::GetGlobal()
{
CJSObjectV8* ret = new CJSObjectV8();
@ -391,6 +409,51 @@ namespace NSJSBase
return _return;
}
bool CJSContext::generateSnapshot(const std::string& script, const std::wstring& snapshotPath)
{
#ifdef V8_VERSION_89_PLUS
bool result = false;
// snapshot creator should be in its own scope, because it handles entering, exiting and disposing the isolate
v8::SnapshotCreator snapshotCreator;
v8::Isolate* isolate = snapshotCreator.GetIsolate();
{
v8::HandleScope handle_scope(isolate);
// Create a new context
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
// Trying to handle compile & run errors:
// window
v8::Local<v8::Object> global = context->Global();
global->Set(context, v8::String::NewFromUtf8Literal(isolate, "window"), global).Check();
global->Set(context, v8::String::NewFromUtf8Literal(isolate, "self"), global).Check();
global->Set(context, v8::String::NewFromUtf8Literal(isolate, "native"), v8::Undefined(isolate)).Check();
// Compile and run
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, script.c_str()).ToLocalChecked();
v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked();
bool isEmpty = script->Run(context).IsEmpty();
snapshotCreator.SetDefaultContext(context);
}
v8::StartupData data = snapshotCreator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kKeep);
NSFile::CFileBinary snapshotFile;
if (data.data && snapshotFile.CreateFile(snapshotPath))
{
snapshotFile.WriteFile(data.data, (DWORD)data.raw_size);
snapshotFile.CloseFile();
result = true;
}
delete[] data.data;
return result;
#else
return false;
#endif
}
JSSmart<CJSContext> CJSContext::GetCurrent()
{
CJSContext* ret = new CJSContext(false);

View File

@ -180,7 +180,7 @@ public:
return m_pAllocator;
}
v8::Isolate* CreateNew()
v8::Isolate* CreateNew(v8::StartupData* startupData = nullptr)
{
v8::Isolate::CreateParams create_params;
#ifndef V8_OS_XP
@ -200,6 +200,10 @@ public:
nMaxVirtualMemory);
#endif
#ifdef V8_VERSION_89_PLUS
create_params.snapshot_blob = startupData;
#endif
return v8::Isolate::New(create_params);
}
};
@ -839,9 +843,13 @@ namespace NSJSBase
v8::Persistent<v8::Context> m_contextPersistent;
v8::Local<v8::Context> m_context;
v8::StartupData m_startup_data;
public:
CJSContextPrivate() : m_isolate(NULL)
{
m_startup_data.data = NULL;
m_startup_data.raw_size = 0;
}
void InsertToGlobal(const std::string& name, v8::FunctionCallback creator)
@ -850,6 +858,12 @@ namespace NSJSBase
v8::MaybeLocal<v8::Function> oFuncMaybeLocal = templ->GetFunction(m_context);
m_context->Global()->Set(m_context, CreateV8String(m_isolate, name.c_str()), oFuncMaybeLocal.ToLocalChecked());
}
~CJSContextPrivate()
{
if (m_startup_data.data)
delete [] m_startup_data.data;
}
};
// embed

View File

@ -1039,108 +1039,6 @@ public:
#endif
//////////////////////////////////////////////////////////////////////////////
#if 0
class CSnapshotScript
{
public:
bool m_bIsExist;
v8::StartupData m_oStartupData;
CSnapshotScript(const std::wstring& sDir = L"")
{
m_bIsExist = false;
m_oStartupData.data = NULL;
m_oStartupData.raw_size = 0;
std::wstring sFile = sDir + L"/heap_snapshot.bin";
if (NSFile::CFileBinary::Exists(sFile))
{
m_bIsExist = true;
NSFile::CFileBinary oFile;
oFile.OpenFile(sFile);
m_oStartupData.raw_size = (int)oFile.GetFileSize();
m_oStartupData.data = new char[m_oStartupData.raw_size];
DWORD dwRead = 0;
oFile.ReadFile((BYTE*)m_oStartupData.data, (DWORD)m_oStartupData.raw_size, dwRead);
oFile.CloseFile();
}
}
bool Generate(const std::string& sScript)
{
m_oStartupData = {NULL, 0};
{
v8::SnapshotCreator snapshot_creator;
// Obtain an isolate provided by SnapshotCreator.
v8::Isolate* isolate = snapshot_creator.GetIsolate();
{
v8::HandleScope scope(isolate);
// Create a new context and optionally run some script.
v8::Local<v8::Context> context = v8::Context::New(isolate);
//v8::Context::Scope context_scope(context);
if (!RunExtraCode(isolate, context, sScript.c_str(), "<embedded>"))
return false;
// Add the possibly customized context to the SnapshotCreator.
snapshot_creator.SetDefaultContext(context);
}
// Use the SnapshotCreator to create the snapshot blob.
m_oStartupData = snapshot_creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear);
}
return true;
}
void Save(const std::wstring& sDir)
{
if (m_oStartupData.data == NULL)
return;
std::wstring sFile = sDir + L"/heap_snapshot.bin";
NSFile::CFileBinary oFile;
oFile.CreateFile(sFile);
oFile.WriteFile((BYTE*)m_oStartupData.data, (DWORD)m_oStartupData.raw_size);
oFile.CloseFile();
}
bool RunExtraCode(v8::Isolate* isolate, v8::Local<v8::Context> context, const char* utf8_source, const char* name)
{
// Run custom script if provided.
v8::TryCatch try_catch(isolate);
v8::Local<v8::String> source_string;
if (!v8::String::NewFromUtf8(isolate, utf8_source, v8::NewStringType::kNormal).ToLocal(&source_string))
return false;
v8::Local<v8::String> resource_name = v8::String::NewFromUtf8(isolate, name, v8::NewStringType::kNormal).ToLocalChecked();
v8::ScriptOrigin origin(resource_name);
v8::ScriptCompiler::Source source(source_string, origin);
v8::Local<v8::Script> script;
bool bRet = v8::ScriptCompiler::Compile(context, &source).ToLocal(&script);
if (try_catch.HasCaught())
{
std::string strCode = to_cstringA(try_catch.Message()->GetSourceLine());
std::string strException = to_cstringA(try_catch.Message()->Get());
return false;
}
script->Run();
if (try_catch.HasCaught())
{
std::string strCode = to_cstringA(try_catch.Message()->GetSourceLine());
std::string strException = to_cstringA(try_catch.Message()->Get());
return false;
}
return true;
}
};
#endif
bool Doct_renderer_SaveFile_ForBuilder(int nFormat, const std::wstring& strDstFile,
NSNativeControl::CNativeControl* pNative,

View File

@ -1,8 +1,7 @@
#include <malloc.h>
#include "../../../../../common/Base64.h"
#include "drawingfile.h"
#include "../../../../../doctrenderer/drawingfile.h"
#ifdef _WIN32
#define WASM_EXPORT __declspec(dllexport)
@ -49,7 +48,7 @@ WASM_EXPORT void InitializeFontsRanges(BYTE* pDataSrc)
}
WASM_EXPORT void SetFontBinary(char* path, BYTE* data, int size)
{
NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
NSFonts::IFontsMemoryStorage* pStorage = CDrawingFile::GetFontsStorage();
if (pStorage)
{
std::string sPathA(path);
@ -58,7 +57,7 @@ WASM_EXPORT void SetFontBinary(char* path, BYTE* data, int size)
}
WASM_EXPORT int IsFontBinaryExist(char* path)
{
NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
NSFonts::IFontsMemoryStorage* pStorage = CDrawingFile::GetFontsStorage();
if (pStorage)
{
std::string sPathA(path);
@ -88,188 +87,100 @@ WASM_EXPORT int GetType(BYTE* data, LONG size)
return 1;
return 2;
}
WASM_EXPORT CGraphicsFileDrawing* Open(BYTE* data, LONG size, const char* password)
WASM_EXPORT CDrawingFile* Open(BYTE* data, LONG size, const char* password)
{
if (!g_applicationFonts)
g_applicationFonts = NSFonts::NSApplication::Create();
// всегда пересоздаем сторадж
NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NSFonts::NSApplicationFontStream::CreateDefaultGlobalMemoryStorage());
CDrawingFile::InitFontsGlobalStorage();
CGraphicsFileDrawing* pGraphics = new CGraphicsFileDrawing(g_applicationFonts);
pGraphics->Open(data, size, GetType(data, size), password);
return pGraphics;
CDrawingFile* pFile = new CDrawingFile(g_applicationFonts);
std::wstring sPassword = L"";
if (NULL != password)
sPassword = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)password, strlen(password));
pFile->OpenFile(data, size, sPassword);
return pFile;
}
WASM_EXPORT int GetErrorCode(CGraphicsFileDrawing* pGraphics)
WASM_EXPORT int GetErrorCode(CDrawingFile* pFile)
{
if (!pGraphics)
if (!pFile)
return -1;
return pGraphics->GetErrorCode();
return pFile->GetErrorCode();
}
WASM_EXPORT void Close (CGraphicsFileDrawing* pGraphics)
WASM_EXPORT void Close(CDrawingFile* pFile)
{
delete pGraphics;
delete pFile;
NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NULL);
}
WASM_EXPORT BYTE* GetInfo (CGraphicsFileDrawing* pGraphics)
WASM_EXPORT BYTE* GetInfo(CDrawingFile* pFile)
{
NSWasm::CData oRes;
oRes.SkipLen();
oRes.AddInt(pGraphics->GetMaxRefID());
int pages_count = pGraphics->GetPagesCount();
oRes.AddInt(pages_count);
for (int page = 0; page < pages_count; ++page)
{
int nW = 0;
int nH = 0;
int nDpi = 0;
int nRotate = 0;
pGraphics->GetPageInfo(page, nW, nH, nDpi, nRotate);
oRes.AddInt(nW);
oRes.AddInt(nH);
oRes.AddInt(nDpi);
oRes.AddInt(nRotate);
}
std::wstring wsInfo = pGraphics->GetInfo();
std::string sInfo = U_TO_UTF8(wsInfo);
oRes.WriteString((BYTE*)sInfo.c_str(), sInfo.length());
oRes.WriteLen();
BYTE* bRes = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return bRes;
return pFile->GetInfo();
}
WASM_EXPORT BYTE* GetPixmap (CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor)
WASM_EXPORT BYTE* GetPixmap(CDrawingFile* pFile, int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor)
{
return pGraphics->GetPage(nPageIndex, nRasterW, nRasterH, nBackgroundColor);
return pFile->GetPixmap(nPageIndex, nRasterW, nRasterH, nBackgroundColor);
}
WASM_EXPORT BYTE* GetGlyphs (CGraphicsFileDrawing* pGraphics, int nPageIndex)
WASM_EXPORT BYTE* GetGlyphs(CDrawingFile* pFile, int nPageIndex)
{
return pGraphics->GetGlyphs(nPageIndex);
return pFile->GetGlyphs(nPageIndex);
}
WASM_EXPORT BYTE* GetLinks (CGraphicsFileDrawing* pGraphics, int nPageIndex)
WASM_EXPORT BYTE* GetLinks (CDrawingFile* pFile, int nPageIndex)
{
return pGraphics->GetLinks(nPageIndex);
return pFile->GetLinks(nPageIndex);
}
WASM_EXPORT BYTE* GetStructure(CGraphicsFileDrawing* pGraphics)
WASM_EXPORT BYTE* GetStructure(CDrawingFile* pFile)
{
return pGraphics->GetStructure();
return pFile->GetStructure();
}
WASM_EXPORT BYTE* GetInteractiveFormsInfo(CGraphicsFileDrawing* pGraphics)
WASM_EXPORT BYTE* GetInteractiveFormsInfo(CDrawingFile* pFile)
{
return pGraphics->GetInteractiveFormsInfo();
return pFile->GetInteractiveFormsInfo();
}
WASM_EXPORT BYTE* GetInteractiveFormsFonts(CGraphicsFileDrawing* pGraphics, int nType)
WASM_EXPORT BYTE* GetInteractiveFormsFonts(CDrawingFile* pFile, int nType)
{
return pGraphics->GetAnnotFonts(nType);
return pFile->GetInteractiveFormsFonts(nType);
}
WASM_EXPORT BYTE* GetInteractiveFormsAP(CGraphicsFileDrawing* pGraphics, int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget, int nView, int nButtonView)
WASM_EXPORT BYTE* GetInteractiveFormsAP(CDrawingFile* pFile, int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget, int nView, int nButtonView)
{
const char* sView = NULL;
if (nView == 0)
sView = "N";
else if (nView == 1)
sView = "D";
else if (nView == 2)
sView = "R";
const char* sButtonView = NULL;
if (nButtonView == 0)
sButtonView = "Off";
else if (nButtonView == 1)
sButtonView = "Yes";
return pGraphics->GetAPWidget(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nWidget, sView, sButtonView);
return pFile->GetInteractiveFormsAP(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nWidget, nView, nButtonView);
}
WASM_EXPORT BYTE* GetButtonIcons(CGraphicsFileDrawing* pGraphics, int nBackgroundColor, int nPageIndex, int bBase64, int nButtonWidget, int nIconView)
WASM_EXPORT BYTE* GetButtonIcons(CDrawingFile* pFile, int nBackgroundColor, int nPageIndex, int bBase64, int nButtonWidget, int nIconView)
{
const char* sIconView = NULL;
if (nIconView == 0)
sIconView = "I";
else if (nIconView == 1)
sIconView = "RI";
else if (nIconView == 2)
sIconView = "IX";
return pGraphics->GetButtonIcon(nBackgroundColor, nPageIndex, bBase64 ? true : false, nButtonWidget, sIconView);
return pFile->GetButtonIcons(nBackgroundColor, nPageIndex, bBase64 ? true : false, nButtonWidget, nIconView);
}
WASM_EXPORT BYTE* GetAnnotationsInfo(CGraphicsFileDrawing* pGraphics, int nPageIndex)
WASM_EXPORT BYTE* GetAnnotationsInfo(CDrawingFile* pFile, int nPageIndex)
{
return pGraphics->GetAnnots(nPageIndex);
return pFile->GetAnnotationsInfo(nPageIndex);
}
WASM_EXPORT BYTE* GetAnnotationsAP(CGraphicsFileDrawing* pGraphics, int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot, int nView)
WASM_EXPORT BYTE* GetAnnotationsAP(CDrawingFile* pFile, int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot, int nView)
{
const char* sView = NULL;
if (nView == 0)
sView = "N";
else if (nView == 1)
sView = "D";
else if (nView == 2)
sView = "R";
return pGraphics->GetAPAnnots(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nAnnot, sView);
return pFile->GetAnnotationsAP(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nAnnot, nView);
}
WASM_EXPORT BYTE* GetFontBinary(CGraphicsFileDrawing* pGraphics, char* path)
WASM_EXPORT BYTE* GetFontBinary(CDrawingFile* pFile, char* path)
{
std::string sPathA(path);
std::wstring sFontName = UTF8_TO_U(sPathA);
std::wstring sFontFile = pGraphics->GetFont(sFontName);
if (sFontFile.empty())
sFontFile = sFontName;
NSFonts::IFontsMemoryStorage* pStorage = NSFonts::NSApplicationFontStream::GetGlobalMemoryStorage();
if (pStorage)
{
NSFonts::IFontStream* pStream = pStorage->Get(sFontFile);
if (pStream)
{
BYTE* pData = NULL;
LONG lLength = 0;
pStream->GetMemory(pData, lLength);
if (pData)
{
NSWasm::CData oRes;
oRes.SkipLen();
oRes.AddInt(lLength);
unsigned long long npSubMatrix = (unsigned long long)pData;
unsigned int npSubMatrix1 = npSubMatrix & 0xFFFFFFFF;
oRes.AddInt(npSubMatrix1);
oRes.AddInt(npSubMatrix >> 32);
oRes.WriteLen();
BYTE* bRes = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return bRes;
}
}
}
return NULL;
return pFile->GetFontBinary(std::string(path));
}
WASM_EXPORT void DestroyTextInfo(CGraphicsFileDrawing* pGraphics)
WASM_EXPORT void DestroyTextInfo(CDrawingFile* pFile)
{
return pGraphics->DestroyText();
return pFile->DestroyTextInfo();
}
WASM_EXPORT int IsNeedCMap(CGraphicsFileDrawing* pGraphics)
WASM_EXPORT int IsNeedCMap(CDrawingFile* pFile)
{
return pGraphics->IsNeedCMap() ? 1 : 0;
return pFile->IsNeedCMap() ? 1 : 0;
}
WASM_EXPORT void SetCMapData(CGraphicsFileDrawing* pGraphics, BYTE* data, int size)
WASM_EXPORT void SetCMapData(CDrawingFile* pFile, BYTE* data, int size)
{
pGraphics->SetCMapData(data, size);
pFile->SetCMapData(data, size);
}
WASM_EXPORT BYTE* ScanPage(CGraphicsFileDrawing* pGraphics, int nPageIndex, int mode)
WASM_EXPORT BYTE* ScanPage(CDrawingFile* pFile, int nPageIndex, int mode)
{
return pGraphics->GetPageShapes(nPageIndex, mode);
return pFile->ScanPage(nPageIndex, mode);
}
WASM_EXPORT void* GetImageBase64(CGraphicsFileDrawing* pGraphics, int rId)
WASM_EXPORT void* GetImageBase64(CDrawingFile* pFile, int rId)
{
return pGraphics->GetImageBase64(rId);
return pFile->GetImageBase64(rId);
}
WASM_EXPORT int GetImageBase64Len(std::string* p)
{

View File

@ -1,232 +0,0 @@
#ifndef _WASM_GRAPHICS_
#define _WASM_GRAPHICS_
#include "../../../../../common/File.h"
#include "../../../../pro/officedrawingfile.h"
#include "../../../../../../XpsFile/XpsFile.h"
#include "../../../../../../DjVuFile/DjVu.h"
#include "../../../../../../PdfFile/PdfFile.h"
#include "../../../../../../HtmlRenderer/include/HTMLRendererText.h"
#include "../../../../../../DocxRenderer/DocxRenderer.h"
#include "serialize.h"
class CGraphicsFileDrawing
{
private:
IOfficeDrawingFile* pReader;
NSFonts::IApplicationFonts* pApplicationFonts;
NSFonts::IFontManager* pFontManager;
NSHtmlRenderer::CHTMLRendererText* pTextRenderer;
NSDocxRenderer::IImageStorage* pImageStorage;
int nType;
public:
CGraphicsFileDrawing(NSFonts::IApplicationFonts* pFonts)
{
pReader = NULL;
pTextRenderer = NULL;
pImageStorage = NULL;
pApplicationFonts = pFonts;
pApplicationFonts->AddRef();
pFontManager = pApplicationFonts->GenerateFontManager();
NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create();
pFontCache->SetStreams(pApplicationFonts->GetStreams());
pFontCache->SetCacheSize(8);
pFontManager->SetOwnerCache(pFontCache);
nType = -1;
}
~CGraphicsFileDrawing()
{
RELEASEOBJECT(pReader);
RELEASEOBJECT(pTextRenderer);
RELEASEOBJECT(pFontManager);
RELEASEINTERFACE(pApplicationFonts);
RELEASEOBJECT(pImageStorage);
nType = -1;
}
bool Open(BYTE* data, DWORD length, int _nType, const char* password)
{
nType = _nType;
if (nType == 0)
pReader = new CPdfFile(pApplicationFonts);
else if (nType == 1)
pReader = new CDjVuFile(pApplicationFonts);
else if (nType == 2)
pReader = new CXpsFile(pApplicationFonts);
if (!pReader)
return false;
std::wstring sPassword = L"";
if (password)
{
std::string sPass(password);
sPassword = UTF8_TO_U(sPass);
}
return pReader->LoadFromMemory(data, length, L"", sPassword, sPassword);
}
int GetErrorCode()
{
if (!pReader)
return -1;
if (nType == 0)
// диапозон ошибки от 0 до 10
return ((CPdfFile*)pReader)->GetError();
return 0; // errNone
}
int GetPagesCount()
{
return pReader->GetPagesCount();
}
int GetMaxRefID()
{
if (nType == 0)
return ((CPdfFile*)pReader)->GetMaxRefID();
return 0;
}
void GetPageInfo(int nPageIndex, int& nWidth, int& nHeight, int& nPageDpiX, int& nRotate)
{
double dPageDpiX, dPageDpiY;
double dWidth, dHeight;
pReader->GetPageInfo(nPageIndex, &dWidth, &dHeight, &dPageDpiX, &dPageDpiY);
if (nType == 2)
{
dWidth = dWidth / 25.4 * 96.0;
dHeight = dHeight / 25.4 * 96.0;
dPageDpiX = dPageDpiX / 25.4 * 96.0;
}
if (nType == 0)
nRotate = ((CPdfFile*)pReader)->GetRotate(nPageIndex);
nWidth = dWidth;
nHeight = dHeight;
nPageDpiX = dPageDpiX;
}
std::wstring GetFont(const std::wstring& sFontName)
{
std::wstring sFontFile;
if (nType == 0)
sFontFile = ((CPdfFile*)pReader)->GetFontPath(sFontName);
return sFontFile;
}
BYTE* GetPage(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor)
{
return pReader->ConvertToPixels(nPageIndex, nRasterW, nRasterH, true, pFontManager, nBackgroundColor, (nBackgroundColor == 0xFFFFFF) ? false : true);
}
BYTE* GetGlyphs(int nPageIndex)
{
if (NULL == pTextRenderer)
pTextRenderer = new NSHtmlRenderer::CHTMLRendererText();
pTextRenderer->Init(pReader, 8);
pReader->DrawPageOnRenderer(pTextRenderer, nPageIndex, NULL);
return pTextRenderer->GetBuffer();
}
BYTE* GetLinks(int nPageIndex)
{
return pReader->GetLinks(nPageIndex);
}
BYTE* GetStructure()
{
return pReader->GetStructure();
}
BYTE* GetInteractiveFormsInfo()
{
if (nType == 0)
return ((CPdfFile*)pReader)->GetWidgets();
return NULL;
}
BYTE* GetAnnotFonts(int nTypeFonts)
{
if (nType == 0)
{
if (nTypeFonts == 1)
return ((CPdfFile*)pReader)->GetAnnotEmbeddedFonts();
if (nTypeFonts == 2)
return ((CPdfFile*)pReader)->GetAnnotStandardFonts();
}
return NULL;
}
BYTE* GetAnnots(int nPageIndex = -1)
{
if (nType == 0)
return ((CPdfFile*)pReader)->GetAnnots(nPageIndex);
return NULL;
}
BYTE* GetAPWidget (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget = -1, const char* sView = NULL, const char* sBView = NULL)
{
if (nType == 0)
return ((CPdfFile*)pReader)->GetAPWidget(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nWidget, sView, sBView);
return NULL;
}
BYTE* GetButtonIcon(int nBackgroundColor, int nPageIndex, bool bBase64, int nBWidget = -1, const char* sIView = NULL)
{
if (nType == 0)
return ((CPdfFile*)pReader)->GetButtonIcon(nBackgroundColor, nPageIndex, bBase64, nBWidget, sIView);
return NULL;
}
BYTE* GetAPAnnots (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot = -1, const char* sView = NULL)
{
if (nType == 0)
return ((CPdfFile*)pReader)->GetAPAnnots(nRasterW, nRasterH, nBackgroundColor, nPageIndex, nAnnot, sView);
return NULL;
}
std::wstring GetInfo()
{
return pReader->GetInfo();
}
bool IsNeedCMap()
{
if (nType == 0)
return ((CPdfFile*)pReader)->IsNeedCMap();
return false;
}
void SetCMapData(BYTE* pData, DWORD nSizeData)
{
if (nType == 0)
((CPdfFile*)pReader)->SetCMapMemory(pData, nSizeData);
}
void DestroyText()
{
RELEASEOBJECT(pTextRenderer);
}
BYTE* GetPageShapes(const int& nPageIndex, int mode)
{
if (NULL == pImageStorage)
pImageStorage = NSDocxRenderer::CreateWasmImageStorage();
CDocxRenderer oRenderer(pApplicationFonts);
oRenderer.SetExternalImageStorage(pImageStorage);
oRenderer.SetTextAssociationType(NSDocxRenderer::TextAssociationType::tatParagraphToShape);
std::vector<std::wstring> arShapes;
if (0 == mode)
arShapes = oRenderer.ScanPage(pReader, nPageIndex);
else
arShapes = oRenderer.ScanPagePptx(pReader, nPageIndex);
int nLen = (int)arShapes.size();
NSWasm::CData oRes;
oRes.SkipLen();
oRes.AddInt(nLen);
for (int i = 0; i < nLen; ++i)
oRes.WriteString(arShapes[i]);
oRes.WriteLen();
BYTE* res = oRes.GetBuffer();
oRes.ClearWithoutAttack();
return res;
}
std::string* GetImageBase64(int nRId)
{
if (NULL == pImageStorage)
return NULL;
return pImageStorage->GetBase64(nRId);
}
};
#endif // _WASM_GRAPHICS_

View File

@ -98,6 +98,16 @@ namespace NExtractTools
NSDoctRenderer::CDocBuilder::Dispose();
}
void createJSSnapshots()
{
NSDoctRenderer::CDocBuilder::Initialize();
NSDoctRenderer::CDoctrenderer oDoctRenderer;
oDoctRenderer.CreateSnapshots();
NSDoctRenderer::CDocBuilder::Dispose();
}
// mailmerge
_UINT32 convertmailmerge(const InputParamsMailMerge& oMailMergeSend,
const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams)

View File

@ -296,6 +296,7 @@ namespace NExtractTools
_UINT32 detectMacroInFile(InputParams& oInputParams);
void createJSCaches();
void createJSSnapshots();
X2T_DECL_EXPORT _UINT32 FromFile(const std::wstring& file);
X2T_DECL_EXPORT _UINT32 FromXml(const std::wstring& xml);

View File

@ -791,12 +791,6 @@ namespace NExtractTools
oBuilder.WriteEncodeXmlString(sJsonParams);
oBuilder.WriteString(L"</JsonParams>");
}
if (NULL != params.m_sScriptsCacheDirectory)
{
oBuilder.WriteString(L"<ScriptsCacheDirectory>");
oBuilder.WriteEncodeXmlString(*params.m_sScriptsCacheDirectory);
oBuilder.WriteString(L"</ScriptsCacheDirectory>");
}
oBuilder.WriteString(L"<Changes TopItem=\"");
oBuilder.AddInt(nTopIndex);
oBuilder.WriteString(L"\">");

View File

@ -512,7 +512,6 @@ namespace NExtractTools
boost::unordered_map<int, std::vector<InputLimit>> m_mapInputLimits;
bool* m_bIsPDFA;
std::wstring* m_sConvertToOrigin;
std::wstring* m_sScriptsCacheDirectory;
// output params
mutable bool m_bOutputConvertCorrupted;
mutable bool m_bMacro;
@ -547,7 +546,6 @@ namespace NExtractTools
m_bIsNoBase64 = NULL;
m_bIsPDFA = NULL;
m_sConvertToOrigin = NULL;
m_sScriptsCacheDirectory = NULL;
m_bOutputConvertCorrupted = false;
m_bMacro = false;
@ -581,7 +579,6 @@ namespace NExtractTools
RELEASEOBJECT(m_bIsNoBase64);
RELEASEOBJECT(m_bIsPDFA);
RELEASEOBJECT(m_sConvertToOrigin);
RELEASEOBJECT(m_sScriptsCacheDirectory);
}
bool FromXmlFile(const std::wstring& sFilename)
@ -770,11 +767,6 @@ namespace NExtractTools
RELEASEOBJECT(m_sConvertToOrigin);
m_sConvertToOrigin = new std::wstring(sValue);
}
else if (_T("m_sScriptsCacheDirectory") == sName)
{
RELEASEOBJECT(m_sScriptsCacheDirectory);
m_sScriptsCacheDirectory = new std::wstring(sValue);
}
}
else if (_T("m_nCsvDelimiterChar") == sName)
{

View File

@ -35,6 +35,7 @@
#include "../../DesktopEditor/common/SystemUtils.h"
#include "ASCConverters.h"
#include "cextracttools.h"
#include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
#include <iostream>
@ -160,6 +161,28 @@ int wmain_lib(int argc, wchar_t *argv[])
NExtractTools::createJSCaches();
return 0;
}
else if (sArg1 == L"-create-js-snapshots")
{
NExtractTools::createJSSnapshots();
return 0;
}
else if (sArg1 == L"-create-allfonts")
{
if (argc > 2)
{
CApplicationFontsWorker oWorker;
oWorker.m_sDirectory = std::wstring(argv[2]);
oWorker.m_bIsUseSystemFonts = true;
oWorker.m_bIsNeedThumbnails = false;
oWorker.m_bIsCleanDirectory = false;
for (int i = 3; i < argc; ++i)
oWorker.m_arAdditionalFolders.push_back(std::wstring(argv[i]));
NSFonts::IApplicationFonts* pFonts = oWorker.Check();
RELEASEINTERFACE(pFonts);
}
}
else
{
InputParams oInputParams;