mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Remove depends to CSvgFile from HtmlFile2. Add initialize fontsfor svg.
This commit is contained in:
@ -123,6 +123,7 @@ namespace MetaFile
|
||||
|
||||
virtual bool LoadFromFile(const wchar_t* wsFilePath) = 0;
|
||||
virtual bool LoadFromBuffer(BYTE* pBuffer, unsigned int unSize) = 0;
|
||||
virtual bool LoadFromString(const std::wstring& data) = 0;
|
||||
virtual bool DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight) = 0;
|
||||
virtual void Close() = 0;
|
||||
virtual void GetBounds(double* pdX, double* pdY, double* pdW, double* pdH) = 0;
|
||||
@ -131,6 +132,7 @@ namespace MetaFile
|
||||
virtual NSFonts::IFontManager* get_FontManager() = 0;
|
||||
|
||||
virtual std::wstring ConvertToSvg(unsigned int unWidth = 0, unsigned int unHeight = 0) = 0;
|
||||
virtual void SetTempDirectory(const std::wstring& dir) = 0;
|
||||
|
||||
//Для тестов
|
||||
#ifdef METAFILE_SUPPORT_WMF_EMF
|
||||
|
||||
@ -448,6 +448,37 @@ namespace MetaFile
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CMetaFile::LoadFromString(const std::wstring& data)
|
||||
{
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
RELEASEINTERFACE(m_pFontManager);
|
||||
|
||||
if (m_pAppFonts)
|
||||
{
|
||||
m_pFontManager = m_pAppFonts->GenerateFontManager();
|
||||
NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create();
|
||||
pMeasurerCache->SetStreams(m_pAppFonts->GetStreams());
|
||||
m_pFontManager->SetOwnerCache(pMeasurerCache);
|
||||
}
|
||||
|
||||
m_oSvgFile.SetFontManager(m_pFontManager);
|
||||
|
||||
if (m_oSvgFile.ReadFromWString(data) == true)
|
||||
{
|
||||
m_lType = c_lMetaSvg;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void CMetaFile::SetTempDirectory(const std::wstring& dir)
|
||||
{
|
||||
#ifdef METAFILE_SUPPORT_SVG
|
||||
m_oSvgFile.SetWorkingDirectory(dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CMetaFile::DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight)
|
||||
{
|
||||
if (NULL == pRenderer)
|
||||
|
||||
@ -64,6 +64,7 @@ namespace MetaFile
|
||||
|
||||
bool LoadFromFile(const wchar_t* wsFilePath);
|
||||
bool LoadFromBuffer(BYTE* pBuffer, unsigned int unSize);
|
||||
bool LoadFromString(const std::wstring& data);
|
||||
bool DrawOnRenderer(IRenderer* pRenderer, double dX, double dY, double dWidth, double dHeight);
|
||||
void Close();
|
||||
void GetBounds(double* pdX, double* pdY, double* pdW, double* pdH);
|
||||
@ -75,6 +76,8 @@ namespace MetaFile
|
||||
//конвертация в Svg
|
||||
std::wstring ConvertToSvg(unsigned int unWidth = 0, unsigned int unHeight = 0);
|
||||
|
||||
void SetTempDirectory(const std::wstring& dir);
|
||||
|
||||
//Для тестов
|
||||
#ifdef METAFILE_SUPPORT_WMF_EMF
|
||||
void ConvertToXml(const wchar_t *wsFilePath);
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
#include "../DesktopEditor/xml/include/xmlutils.h"
|
||||
#include "../DesktopEditor/raster/BgraFrame.h"
|
||||
#include "../DesktopEditor/graphics/pro/Graphics.h"
|
||||
#include "../DesktopEditor/raster/Metafile/svg/CSvgFile.h"
|
||||
|
||||
#include "htmlfile2.h"
|
||||
#include "src/Languages.h"
|
||||
@ -4534,29 +4533,22 @@ private:
|
||||
if (wsSvg.empty())
|
||||
return false;
|
||||
|
||||
CSvgFile oSvgReader;
|
||||
|
||||
NSFonts::IApplicationFonts* pFonts = NSFonts::NSApplication::Create();
|
||||
NSFonts::IFontManager* pFontManager = pFonts->GenerateFontManager();
|
||||
NSFonts::IFontsCache* pFontCache = NSFonts::NSFontCache::Create();
|
||||
pFonts->Initialize();
|
||||
|
||||
pFontCache->SetStreams(pFonts->GetStreams());
|
||||
pFontManager->SetOwnerCache(pFontCache);
|
||||
|
||||
oSvgReader.SetFontManager(pFontManager);
|
||||
|
||||
if (!oSvgReader.ReadFromWString(wsSvg))
|
||||
MetaFile::IMetaFile* pSvgReader = MetaFile::Create(pFonts);
|
||||
if (!pSvgReader->LoadFromString(wsSvg))
|
||||
{
|
||||
RELEASEINTERFACE(pFontManager);
|
||||
pFonts->Release();
|
||||
RELEASEINTERFACE(pSvgReader);
|
||||
RELEASEINTERFACE(pFonts);
|
||||
return false;
|
||||
}
|
||||
|
||||
NSGraphics::IGraphicsRenderer* pGrRenderer = NSGraphics::Create();
|
||||
pGrRenderer->SetFontManager(pFontManager);
|
||||
pGrRenderer->SetFontManager(pSvgReader->get_FontManager());
|
||||
|
||||
double dX, dY, dW, dH;
|
||||
oSvgReader.GetBounds(dX, dY, dW, dH);
|
||||
pSvgReader->GetBounds(&dX, &dY, &dW, &dH);
|
||||
|
||||
if (dW < 0) dW = -dW;
|
||||
if (dH < 0) dH = -dH;
|
||||
@ -4615,19 +4607,20 @@ private:
|
||||
pGrRenderer->put_Width(dWidth);
|
||||
pGrRenderer->put_Height(dHeight);
|
||||
|
||||
oSvgReader.SetWorkingDirectory(m_sSrc);
|
||||
oSvgReader.Draw(pGrRenderer, 0, 0, dWidth, dHeight);
|
||||
// TODO: src directory as tmp - it's not good idea
|
||||
pSvgReader->SetTempDirectory(m_sSrc);
|
||||
pSvgReader->DrawOnRenderer(pGrRenderer, 0, 0, dWidth, dHeight);
|
||||
|
||||
oFrame.SaveFile(m_sDst + L"/word/media/i" + std::to_wstring(m_arrImages.size()) + L".png", 4);
|
||||
oFrame.put_Data(NULL);
|
||||
|
||||
RELEASEINTERFACE(pFontManager);
|
||||
RELEASEINTERFACE(pGrRenderer);
|
||||
|
||||
if (pBgraData)
|
||||
free(pBgraData);
|
||||
|
||||
pFonts->Release();
|
||||
RELEASEINTERFACE(pSvgReader);
|
||||
RELEASEINTERFACE(pFonts);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user