Compare commits

..

5 Commits

Author SHA1 Message Date
12ef2e6510 Fix bug 59462 2022-11-24 18:11:20 +03:00
da3a6b3189 Fix bugs with cache 2022-11-18 12:20:05 +03:00
81e03f64db Add support print custom pages in pdf/xps/djvu 2022-11-17 19:24:11 +03:00
0aed94b748 Fix ios/android build 2022-11-17 10:19:34 +03:00
5af4ebba9e Fix bug with caches 2022-11-16 23:25:19 +03:00
5 changed files with 154 additions and 11 deletions

View File

@ -1204,12 +1204,18 @@ namespace NSDoctRenderer
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();
context->Initialize();

View File

@ -188,4 +188,8 @@ namespace NSDoctRenderer
std::vector<std::wstring> stub;
return stub;
}
void CDoctrenderer::CreateCache(const std::wstring& sAllFontsPath, const std::wstring& sCacheDir)
{
}
}

View File

@ -56,7 +56,7 @@ namespace NSJSBase
{
// no cache
v8::ScriptCompiler::Source oSource(source);
v8::MaybeLocal<v8::Script> sctiptMB = v8::ScriptCompiler::Compile(_context, &oSource, v8::ScriptCompiler::kConsumeCodeCache);
v8::MaybeLocal<v8::Script> sctiptMB = v8::ScriptCompiler::Compile(_context, &oSource, v8::ScriptCompiler::kNoCompileOptions);
if (!sctiptMB.IsEmpty())
script = sctiptMB.ToLocalChecked();
@ -84,7 +84,7 @@ namespace NSJSBase
}
else
{
v8::ScriptCompiler::CachedData* pCacheData = NULL;
v8::ScriptCompiler::CachedData* pCacheData = nullptr;
// save cache to file
NSFile::CFileBinary oFileTest;
@ -93,7 +93,7 @@ namespace NSJSBase
// create cache data
v8::ScriptCompiler::Source oSource(source);
v8::Local<v8::Script> pScriptCache = v8::ScriptCompiler::Compile(_context, &oSource, v8::ScriptCompiler::kNoCompileOptions).ToLocalChecked();
v8::ScriptCompiler::CachedData* pCacheData = v8::ScriptCompiler::CreateCodeCache(pScriptCache->GetUnboundScript());
pCacheData = v8::ScriptCompiler::CreateCodeCache(pScriptCache->GetUnboundScript());
if (pCacheData)
{
@ -109,8 +109,9 @@ namespace NSJSBase
// compile with/without(if pCacheData === NULL) cache data
v8::ScriptCompiler::Source oSource2(source, pCacheData);
v8::ScriptCompiler::CompileOptions compileOptions = (nullptr == pCacheData) ? v8::ScriptCompiler::kNoCompileOptions : v8::ScriptCompiler::kConsumeCodeCache;
v8::MaybeLocal<v8::Script> sctiptMB = v8::ScriptCompiler::Compile(_context, &oSource2, v8::ScriptCompiler::kConsumeCodeCache);
v8::MaybeLocal<v8::Script> sctiptMB = v8::ScriptCompiler::Compile(_context, &oSource2, compileOptions);
if (!sctiptMB.IsEmpty())
script = sctiptMB.ToLocalChecked();
}
@ -355,7 +356,7 @@ namespace NSJSBase
#endif
LOGGER_START
v8::Local<v8::String> _source = CreateV8String(CV8Worker::GetCurrent(), script.c_str());
v8::Local<v8::String> _source = CreateV8String(CV8Worker::GetCurrent(), script.c_str());
v8::Local<v8::Script> _script;
if(!scriptPath.empty())
{
@ -372,7 +373,7 @@ namespace NSJSBase
LOGGER_LAP("compile")
CJSValueV8* _return = new CJSValueV8();
CJSValueV8* _return = new CJSValueV8();
v8::MaybeLocal<v8::Value> retValue;
if (exception.is_init())

View File

@ -54,9 +54,15 @@ bool CSVGTransformer::OpenFromFile(const std::wstring& file)
m_internal->m_oRender.SetWorkingDirectory(sDirectory);
m_internal->m_oStorage.SetWorkingDirectory(sDirectory);
if (0 == m_internal->m_oXmlParser.LoadFromFile(file, &m_internal->m_oStorage))
try
{
if (!m_internal->m_oXmlParser.LoadFromFile(file, &m_internal->m_oStorage))
return false;
}
catch(...)
{
return false;
}
return true;
}
bool CSVGTransformer::Load(const std::wstring& content)

View File

@ -3584,7 +3584,121 @@ namespace NExtractTools
}
return nRes;
}
_UINT32 PdfDjvuXpsToRenderer(IOfficeDrawingFile** ppReader, IRenderer* pRenderer, const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params, NSFonts::IApplicationFonts* pApplicationFonts)
std::string checkPrintPages(InputParams& params)
{
if (NULL == params.m_sJsonParams)
return "";
std::wstring::size_type posNativeOptions = params.m_sJsonParams->find(L"\"nativeOptions\"");
if (std::wstring::npos == posNativeOptions)
return "";
std::wstring::size_type posNativePages = params.m_sJsonParams->find(L"\"pages\":\"", posNativeOptions);
if (std::wstring::npos == posNativePages)
return "";
posNativePages += 9;
std::wstring::size_type posNativePages2 = params.m_sJsonParams->find(L"\"", posNativePages);
if (std::wstring::npos == posNativePages2)
return "";
std::wstring sPages = params.m_sJsonParams->substr(posNativePages, posNativePages2 - posNativePages);
if (L"all" == sPages)
return "";
if (L"current" == sPages)
{
std::wstring::size_type posCurrentPage = params.m_sJsonParams->find(L"\"currentPage\":", posNativeOptions);
if (std::wstring::npos == posCurrentPage)
return "";
posCurrentPage += 14;
std::wstring::size_type posCurrentPage2 = params.m_sJsonParams->find(L",", posCurrentPage);
std::wstring::size_type posCurrentPage3 = params.m_sJsonParams->find(L"}", posCurrentPage);
if (std::wstring::npos == posCurrentPage2)
{
if (std::wstring::npos == posCurrentPage3)
return "";
posCurrentPage2 = posCurrentPage3;
}
else if (std::wstring::npos != posCurrentPage3 && posCurrentPage3 < posCurrentPage2)
posCurrentPage2 = posCurrentPage3;
if (std::wstring::npos == posCurrentPage2)
return "";
sPages = params.m_sJsonParams->substr(posCurrentPage, posCurrentPage2 - posCurrentPage);
}
return U_TO_UTF8(sPages);
}
std::vector<bool> getPrintPages(const std::string& sPages, int nPagesCount)
{
const char* buffer = sPages.c_str();
size_t nCur = 0;
size_t nLen = sPages.length();
std::vector<bool> arPages;
for (int i = 0; i < nPagesCount; ++i)
arPages.push_back(false);
while (nCur < nLen)
{
size_t cur = nCur;
while (cur < nLen && buffer[cur] != ',')
++cur;
int nStart = 0;
int nEnd = 0;
size_t curRec = nCur;
while (curRec < cur)
{
char c = buffer[curRec++];
if (c >= '0' && c <= '9')
nStart = 10 * nStart + (c - '0');
if (c == '-')
break;
}
if (nStart == 0)
nStart = 1;
if (curRec == cur)
nEnd = nStart;
else
{
while (curRec < cur)
{
char c = buffer[curRec++];
if (c >= '0' && c <= '9')
nEnd = 10 * nEnd + (c - '0');
if (c == '-')
break;
}
if (0 == nEnd || nEnd > nPagesCount)
nEnd = nPagesCount;
}
for (int i = nStart; i <= nEnd; ++i)
arPages[i - 1] = true;
nCur = cur;
if (nCur < nLen)
++nCur;
}
return arPages;
}
_UINT32 PdfDjvuXpsToRenderer(IOfficeDrawingFile** ppReader, IRenderer* pRenderer, const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTo, const std::wstring &sTemp, InputParams& params, NSFonts::IApplicationFonts* pApplicationFonts, const std::string& sPages = "")
{
_UINT32 nRes = 0;
IOfficeDrawingFile* pReader = NULL;
@ -3613,8 +3727,17 @@ namespace NExtractTools
if(bResult)
{
int nPagesCount = pReader->GetPagesCount();
bool bIsUsePages = sPages.empty() ? false : true;
std::vector<bool> arPages;
if (bIsUsePages)
arPages = getPrintPages(sPages, nPagesCount);
for (int i = 0; i < nPagesCount; ++i)
{
if (bIsUsePages && !arPages[i])
continue;
pRenderer->NewPage();
pRenderer->BeginCommand(c_nPageType);
@ -4722,6 +4845,7 @@ namespace NExtractTools
}
return nRes;
}
_UINT32 fromCrossPlatform(const std::wstring &sFrom, int nFormatFrom, const std::wstring &sTo, int nFormatTo, const std::wstring &sTemp, const std::wstring &sThemeDir, bool bPaid, InputParams& params)
{
_UINT32 nRes = 0;
@ -4729,7 +4853,9 @@ namespace NExtractTools
initApplicationFonts(pApplicationFonts, params);
if(AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF == nFormatTo)
{
if(nFormatFrom == nFormatTo && !params.getIsPDFA() && params.getPassword() == params.getSavePassword())
std::string sPages = checkPrintPages(params);
if(nFormatFrom == nFormatTo && !params.getIsPDFA() && params.getPassword() == params.getSavePassword() && sPages.empty())
{
NSFile::CFileBinary::Copy(sFrom, sTo);
}
@ -4748,7 +4874,7 @@ namespace NExtractTools
pdfWriter.SetPassword(password);
IOfficeDrawingFile* pReader = NULL;
nRes = PdfDjvuXpsToRenderer(&pReader, &pdfWriter, sFrom, nFormatFrom, sTo, sTemp, params, pApplicationFonts);
nRes = PdfDjvuXpsToRenderer(&pReader, &pdfWriter, sFrom, nFormatFrom, sTo, sTemp, params, pApplicationFonts, sPages);
pdfWriter.SaveToFile(sTo);
RELEASEOBJECT(pReader);
}