Skip to content

Commit

Permalink
Merge branch hotfix/v8.2.1 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
papacarlo committed Nov 22, 2024
2 parents e1fcf17 + 099ebc3 commit 09b4ab5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
66 changes: 64 additions & 2 deletions DesktopEditor/doctrenderer/embed/GraphicsEmbed.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "../graphics.h"
#include <map>
#include "../../../Common/Network/FileTransporter/include/FileTransporter.h"

// APPLICATION INFO
class CGraphicsAppImage_private
Expand All @@ -10,6 +12,8 @@ class CGraphicsAppImage_private
std::wstring m_sThemesDirectory;
bool m_bIsRgba;

std::map<std::wstring, std::wstring> m_mapDownloads;

CGraphicsAppImage_private()
{
m_pFonts = NULL;
Expand All @@ -21,6 +25,52 @@ class CGraphicsAppImage_private
~CGraphicsAppImage_private()
{
RELEASEINTERFACE(m_pFonts);

for (std::map<std::wstring, std::wstring>::iterator i = m_mapDownloads.begin(); i != m_mapDownloads.end(); i++)
{
std::wstring sTmp = i->second;
if (NSFile::CFileBinary::Exists(sTmp))
NSFile::CFileBinary::Remove(sTmp);
}
}

bool IsNeedDownload(const std::wstring& sUrl)
{
if ((0 == sUrl.find(L"www.")) ||
(0 == sUrl.find(L"http://")) ||
(0 == sUrl.find(L"https://")))
return true;
return false;
}

std::wstring GetImagePath(const std::wstring& sUrl)
{
std::map<std::wstring, std::wstring>::iterator find = m_mapDownloads.find(sUrl);
if (find != m_mapDownloads.end())
return find->second;

NSNetwork::NSFileTransport::CFileDownloader oDownloader(sUrl, false);

std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(NSFile::CFileBinary::GetTempPath(), L"IMG");
if (NSFile::CFileBinary::Exists(sTmpFile))
NSFile::CFileBinary::Remove(sTmpFile);
sTmpFile = sTmpFile + L".png";

oDownloader.SetFilePath(sTmpFile);
oDownloader.Start(0);
while ( oDownloader.IsRunned() )
{
NSThreads::Sleep( 10 );
}
bool bIsDownloaded = oDownloader.IsFileDownloaded();

if (bIsDownloaded)
{
m_mapDownloads.insert(std::pair<std::wstring, std::wstring>(sUrl, sTmpFile));
return sTmpFile;
}

return sUrl;
}
};

Expand Down Expand Up @@ -270,11 +320,19 @@ JSSmart<CJSValue> CGraphicsEmbed::ClearLastFont()
}
JSSmart<CJSValue> CGraphicsEmbed::drawImage2(JSSmart<CJSValue> img, JSSmart<CJSValue> x, JSSmart<CJSValue> y, JSSmart<CJSValue> w, JSSmart<CJSValue> h, JSSmart<CJSValue> alpha, JSSmart<CJSValue> srcRect)
{
m_pInternal->drawImage(img->toStringW(), x->toDouble(), y->toDouble(), w->toDouble(), h->toDouble(), alpha->toInt32());
std::wstring sUrl = img->toStringW();
if (m_pInternal->m_pAppImage && m_pInternal->m_pAppImage->m_internal->IsNeedDownload(sUrl))
sUrl = m_pInternal->m_pAppImage->m_internal->GetImagePath(sUrl);

m_pInternal->drawImage(sUrl, x->toDouble(), y->toDouble(), w->toDouble(), h->toDouble(), alpha->toInt32());
return NULL;
}
JSSmart<CJSValue> CGraphicsEmbed::drawImage (JSSmart<CJSValue> img, JSSmart<CJSValue> x, JSSmart<CJSValue> y, JSSmart<CJSValue> w, JSSmart<CJSValue> h, JSSmart<CJSValue> alpha, JSSmart<CJSValue> srcRect, JSSmart<CJSValue> nativeImage)
{
std::wstring sUrl = img->toStringW();
if (m_pInternal->m_pAppImage && m_pInternal->m_pAppImage->m_internal->IsNeedDownload(sUrl))
sUrl = m_pInternal->m_pAppImage->m_internal->GetImagePath(sUrl);

m_pInternal->drawImage(img->toStringW(), x->toDouble(), y->toDouble(), w->toDouble(), h->toDouble(), alpha->toInt32());
return NULL;
}
Expand Down Expand Up @@ -579,7 +637,11 @@ JSSmart<CJSValue> CGraphicsEmbed::GetBrushColor()
}
JSSmart<CJSValue> CGraphicsEmbed::put_brushTexture(JSSmart<CJSValue> src, JSSmart<CJSValue> type)
{
m_pInternal->put_brushTexture(src->toStringW(), type->toInt32());
std::wstring sUrl = src->toStringW();
if (m_pInternal->m_pAppImage && m_pInternal->m_pAppImage->m_internal->IsNeedDownload(sUrl))
sUrl = m_pInternal->m_pAppImage->m_internal->GetImagePath(sUrl);

m_pInternal->put_brushTexture(sUrl, type->toInt32());
return NULL;
}
JSSmart<CJSValue> CGraphicsEmbed::put_brushTextureMode(JSSmart<CJSValue> mode)
Expand Down
2 changes: 2 additions & 0 deletions DesktopEditor/doctrenderer/embed/GraphicsEmbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class JS_DECL CGraphicsAppImage

private:
CGraphicsAppImage_private* m_internal;

friend class CGraphicsEmbed;
};

namespace NSGraphics { class CGraphics; }
Expand Down
10 changes: 8 additions & 2 deletions DesktopEditor/doctrenderer/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ namespace NSGraphics
}
void CGraphics::drawImage(const std::wstring& img, double x, double y, double w, double h, BYTE alpha)
{
std::wstring strImage = (0 == img.find(L"theme") ? m_pAppImage->GetThemesDirectory() : m_pAppImage->GetImagesDirectory()) + L'/' + img;
std::wstring strImage = img;
if (!NSFile::CFileBinary::Exists(img))
strImage = (0 == img.find(L"theme") ? m_pAppImage->GetThemesDirectory() : m_pAppImage->GetImagesDirectory()) + L'/' + img;

#ifdef ENABLE_GR_LOGS
std::wcout << L"drawImage " << strImage << L" " << x << " " << y << L" " << w << L" " << h << L" " << alpha << std::endl;
#endif
Expand Down Expand Up @@ -1250,7 +1253,10 @@ namespace NSGraphics
}
else
{
std::wstring strImage = (0 == src.find(L"theme") ? m_pAppImage->GetThemesDirectory() : m_pAppImage->GetImagesDirectory()) + L'/' + src;
std::wstring strImage = src;
if (!NSFile::CFileBinary::Exists(src))
strImage = (0 == src.find(L"theme") ? m_pAppImage->GetThemesDirectory() : m_pAppImage->GetImagesDirectory()) + L'/' + src;

std::wstring sName = strImage.substr(0, strImage.rfind(L'.') + 1);
std::wstring sExt = src.substr(src.rfind(L'.') + 1);
if (sExt == L"svg")
Expand Down
4 changes: 2 additions & 2 deletions DesktopEditor/doctrenderer/js_internal/v8/v8_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ v8::Local<v8::String> CreateV8String(v8::Isolate* i, const std::string& str);

#ifdef __ANDROID__

#ifdef _DEBUG
//#ifdef _DEBUG
#define ANDROID_LOGS
#endif
//#endif

#ifdef ANDROID_LOGS
#include <android/log.h>
Expand Down
9 changes: 7 additions & 2 deletions DesktopEditor/graphics/BaseThreadMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ namespace NSThreads
{
if (i->ID == nThreadId)
{
CBaseThreadInfo last;
last.ID = i->ID;
last.Instance = i->Instance;

m_listThreads.erase(i);
m_listThreads.insert(m_listThreads.begin(), *i);
return i->Instance;
m_listThreads.insert(m_listThreads.begin(), last);

return last.Instance;
}
i++;
}
Expand Down

0 comments on commit 09b4ab5

Please sign in to comment.