mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix bug 68072
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
#include "../graphics.h"
|
||||
#include <map>
|
||||
#include "../../../Common/Network/FileTransporter/include/FileTransporter.h"
|
||||
|
||||
// APPLICATION INFO
|
||||
class CGraphicsAppImage_private
|
||||
@ -10,6 +12,8 @@ public:
|
||||
std::wstring m_sThemesDirectory;
|
||||
bool m_bIsRgba;
|
||||
|
||||
std::map<std::wstring, std::wstring> m_mapDownloads;
|
||||
|
||||
CGraphicsAppImage_private()
|
||||
{
|
||||
m_pFonts = NULL;
|
||||
@ -21,6 +25,52 @@ public:
|
||||
~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;
|
||||
}
|
||||
};
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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)
|
||||
|
||||
@ -31,6 +31,8 @@ public:
|
||||
|
||||
private:
|
||||
CGraphicsAppImage_private* m_internal;
|
||||
|
||||
friend class CGraphicsEmbed;
|
||||
};
|
||||
|
||||
namespace NSGraphics { class CGraphics; }
|
||||
|
||||
@ -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
|
||||
@ -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")
|
||||
|
||||
Reference in New Issue
Block a user