Skip to content

Commit

Permalink
Remove depends to CSvgFile from HtmlFile2. Add initialize fontsfor svg.
Browse files Browse the repository at this point in the history
  • Loading branch information
K0R0L committed Jan 2, 2025
1 parent 45aa5df commit cef8ac9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
2 changes: 2 additions & 0 deletions DesktopEditor/graphics/pro/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions DesktopEditor/raster/Metafile/MetaFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions DesktopEditor/raster/Metafile/MetaFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
31 changes: 12 additions & 19 deletions HtmlFile2/htmlfile2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -4534,29 +4533,22 @@ class CHtmlFile2_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();

pFontCache->SetStreams(pFonts->GetStreams());
pFontManager->SetOwnerCache(pFontCache);

oSvgReader.SetFontManager(pFontManager);
pFonts->Initialize();

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;
Expand Down Expand Up @@ -4615,19 +4607,20 @@ class CHtmlFile2_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;
}
Expand Down

0 comments on commit cef8ac9

Please sign in to comment.