mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-20 16:18:03 +08:00
Add support images from web
This commit is contained in:
@ -52,6 +52,7 @@
|
||||
#include "../DesktopEditor/graphics/pro/Image.h"
|
||||
|
||||
#include "../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "../Common/Network/FileTransporter/include/FileTransporter.h"
|
||||
|
||||
#include "OnlineOfficeBinToPdf.h"
|
||||
|
||||
@ -1223,8 +1224,22 @@ HRESULT CPdfRenderer::DrawPath(const LONG& lType)
|
||||
if (bStroke)
|
||||
UpdatePen();
|
||||
|
||||
std::wstring sTextureOldPath = L"";
|
||||
std::wstring sTextureTmpPath = L"";
|
||||
|
||||
if (bFill || bEoFill)
|
||||
{
|
||||
if (c_BrushTypeTexture == m_oBrush.GetType())
|
||||
{
|
||||
sTextureOldPath = m_oBrush.GetTexturePath();
|
||||
sTextureTmpPath = GetDownloadFile(sTextureOldPath);
|
||||
|
||||
if (!sTextureTmpPath.empty())
|
||||
m_oBrush.SetTexturePath(sTextureTmpPath);
|
||||
}
|
||||
|
||||
UpdateBrush();
|
||||
}
|
||||
|
||||
if (!m_pShading)
|
||||
{
|
||||
@ -1250,6 +1265,14 @@ HRESULT CPdfRenderer::DrawPath(const LONG& lType)
|
||||
|
||||
m_pPage->GrRestore();
|
||||
|
||||
if (!sTextureTmpPath.empty())
|
||||
{
|
||||
m_oBrush.SetTexturePath(sTextureOldPath);
|
||||
|
||||
if (NSFile::CFileBinary::Exists(sTextureTmpPath))
|
||||
NSFile::CFileBinary::Remove(sTextureTmpPath);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CPdfRenderer::PathCommandMoveTo(const double& dX, const double& dY)
|
||||
@ -1397,13 +1420,16 @@ HRESULT CPdfRenderer::DrawImage(IGrObject* pImage, const double& dX, const doubl
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
|
||||
HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePathSrc, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha)
|
||||
{
|
||||
m_oCommandManager.Flush();
|
||||
|
||||
if (!IsPageValid())
|
||||
return S_OK;
|
||||
|
||||
std::wstring sTempImagePath = GetDownloadFile(wsImagePathSrc);
|
||||
std::wstring wsImagePath = sTempImagePath.empty() ? wsImagePathSrc : sTempImagePath;
|
||||
|
||||
Aggplus::CImage* pAggImage = NULL;
|
||||
|
||||
CImageFileFormatChecker oImageFormat(wsImagePath);
|
||||
@ -1429,18 +1455,17 @@ HRESULT CPdfRenderer::DrawImageFromFile(const std::wstring& wsImagePath, const d
|
||||
pAggImage = new Aggplus::CImage(wsImagePath);
|
||||
}
|
||||
|
||||
if (!pAggImage)
|
||||
return S_FALSE;
|
||||
HRESULT hRes = S_OK;
|
||||
if (!pAggImage || !DrawImage(pAggImage, dX, dY, dW, dH, nAlpha))
|
||||
hRes = S_FALSE;
|
||||
|
||||
if (!DrawImage(pAggImage, dX, dY, dW, dH, nAlpha))
|
||||
{
|
||||
if (NSFile::CFileBinary::Exists(sTempImagePath))
|
||||
NSFile::CFileBinary::Remove(sTempImagePath);
|
||||
|
||||
if (pAggImage)
|
||||
delete pAggImage;
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
delete pAggImage;
|
||||
|
||||
return S_OK;
|
||||
return hRes;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Функции для выставления преобразования
|
||||
@ -2371,6 +2396,10 @@ void CPdfRenderer::UpdateBrush()
|
||||
std::wstring wsTexturePath = m_oBrush.GetTexturePath();
|
||||
CImageFileFormatChecker oImageFormat(wsTexturePath);
|
||||
|
||||
FILE* f = fopen("D:/111.txt", "a+");
|
||||
fprintf(f, "ff: %d\n", oImageFormat.eFileType);
|
||||
fclose(f);
|
||||
|
||||
CImageDict* pImage = NULL;
|
||||
int nImageW = 0;
|
||||
int nImageH = 0;
|
||||
@ -2747,3 +2776,37 @@ void CPdfRenderer::SetError()
|
||||
{
|
||||
m_bValid = false;
|
||||
}
|
||||
|
||||
std::wstring CPdfRenderer::GetDownloadFile(const std::wstring& sUrl)
|
||||
{
|
||||
std::wstring::size_type n1 = sUrl.find(L"www.");
|
||||
std::wstring::size_type n2 = sUrl.find(L"http://");
|
||||
std::wstring::size_type n3 = sUrl.find(L"ftp://");
|
||||
std::wstring::size_type n4 = sUrl.find(L"https://");
|
||||
std::wstring::size_type nMax = 3;
|
||||
|
||||
bool bIsNeedDownload = false;
|
||||
if (n1 != std::wstring::npos && n1 < nMax)
|
||||
bIsNeedDownload = true;
|
||||
else if (n2 != std::wstring::npos && n2 < nMax)
|
||||
bIsNeedDownload = true;
|
||||
else if (n3 != std::wstring::npos && n3 < nMax)
|
||||
bIsNeedDownload = true;
|
||||
else if (n4 != std::wstring::npos && n4 < nMax)
|
||||
bIsNeedDownload = true;
|
||||
|
||||
if (!bIsNeedDownload)
|
||||
return L"";
|
||||
|
||||
std::wstring sTempFile = GetTempFile();
|
||||
NSNetwork::NSFileTransport::CFileDownloader oDownloader(sUrl, false);
|
||||
oDownloader.SetFilePath(sTempFile);
|
||||
|
||||
if (oDownloader.DownloadSync())
|
||||
return sTempFile;
|
||||
|
||||
if (NSFile::CFileBinary::Exists(sTempFile))
|
||||
NSFile::CFileBinary::Remove(sTempFile);
|
||||
|
||||
return L"";
|
||||
}
|
||||
|
||||
@ -242,10 +242,11 @@ private:
|
||||
void UpdateTransform();
|
||||
void UpdatePen();
|
||||
void UpdateBrush();
|
||||
bool IsValid();
|
||||
bool IsPageValid();
|
||||
void SetError();
|
||||
bool IsValid();
|
||||
bool IsPageValid();
|
||||
void SetError();
|
||||
void AddLink(const unsigned int& unPage, const double& dX, const double& dY, const double& dW, const double& dH, const double& dDestX, const double& dDestY, const unsigned int& unDestPage);
|
||||
std::wstring GetDownloadFile(const std::wstring& sUrl);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@ -15,7 +15,7 @@ include(../Common/base.pri)
|
||||
|
||||
DEFINES += PDFWRITER_USE_DYNAMIC_LIBRARY
|
||||
|
||||
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter)
|
||||
ADD_DEPENDENCY(graphics, kernel, UnicodeConverter, kernel_network)
|
||||
|
||||
DEFINES += CRYPTOPP_DISABLE_ASM
|
||||
LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lCryptoPPLib
|
||||
|
||||
Reference in New Issue
Block a user