Merge pull request #1466 from ONLYOFFICE/fix/mht

Improved html and mht conversion
This commit is contained in:
Oleg Korshul
2024-04-19 20:50:11 +03:00
committed by GitHub
27 changed files with 2925 additions and 1825 deletions

View File

@ -20,6 +20,12 @@ bool CSvgFile::ReadFromBuffer(BYTE *pBuffer, unsigned int unSize)
return false;
}
bool CSvgFile::ReadFromWString(const std::wstring &wsContext)
{
Clear();
return m_oParser.LoadFromString(wsContext, &m_oContainer, this);
}
bool CSvgFile::OpenFromFile(const std::wstring &wsFile)
{
Clear();
@ -38,13 +44,34 @@ bool CSvgFile::GetBounds(double &dX, double &dY, double &dWidth, double &dHeight
dX = oWindow.m_oX .ToDouble(NSCSS::Pixel, SVG_FILE_WIDTH);
dY = oWindow.m_oY .ToDouble(NSCSS::Pixel, SVG_FILE_HEIGHT);
dWidth = oWindow.m_oWidth .ToDouble(NSCSS::Pixel, SVG_FILE_WIDTH);
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel, SVG_FILE_HEIGHT);
if (SVG::Equals(0., dWidth))
dWidth = (!m_oContainer.GetViewBox().m_oWidth.Empty()) ? m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel) : SVG_FILE_WIDTH;
if (SVG::Equals(0., dHeight))
dHeight = (!m_oContainer.GetViewBox().m_oHeight.Empty()) ? m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel) : SVG_FILE_HEIGHT;
dWidth = 0.;
dHeight = 0.;
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero())
{
if (NSCSS::Percent != oWindow.m_oWidth.GetUnitMeasure() && !m_oContainer.GetViewBox().m_oWidth.Empty() && !m_oContainer.GetViewBox().m_oWidth.Zero())
dWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel, m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel));
else
dWidth = oWindow.m_oWidth.ToDouble(NSCSS::Pixel);
}
else if (!m_oContainer.GetViewBox().m_oWidth.Empty() && !m_oContainer.GetViewBox().m_oWidth.Zero())
dWidth = m_oContainer.GetViewBox().m_oWidth.ToDouble(NSCSS::Pixel);
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero())
{
if (NSCSS::Percent != oWindow.m_oHeight.GetUnitMeasure() && !m_oContainer.GetViewBox().m_oHeight.Empty() && !m_oContainer.GetViewBox().m_oHeight.Zero())
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel, m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel));
else
dHeight = oWindow.m_oHeight.ToDouble(NSCSS::Pixel);
}
else if (!m_oContainer.GetViewBox().m_oHeight.Empty() && !m_oContainer.GetViewBox().m_oHeight.Zero())
dHeight = m_oContainer.GetViewBox().m_oHeight.ToDouble(NSCSS::Pixel);
if (0. == dWidth)
dWidth = SVG_FILE_WIDTH;
if (0. == dHeight)
dHeight = SVG_FILE_HEIGHT;
return true;
}
@ -59,6 +86,11 @@ void CSvgFile::SetFontManager(NSFonts::IFontManager *pFontManager)
m_oParser.SetFontManager(pFontManager);
}
void CSvgFile::SetWorkingDirectory(const std::wstring &wsWorkingDirectory)
{
m_wsWorkingDirectory = wsWorkingDirectory;
}
bool CSvgFile::MarkObject(SVG::CObject *pObject)
{
if (NULL == pObject || pObject->GetId().empty())
@ -146,21 +178,15 @@ bool CSvgFile::Draw(IRenderer *pRenderer, double dX, double dY, double dWidth, d
pRenderer->GetTransform(&oldTransform[0], &oldTransform[1], &oldTransform[2], &oldTransform[3], &oldTransform[4], &oldTransform[5]);
pRenderer->ResetTransform();
double dM11 = 1;
double dM22 = 1;
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero())
dM11 = dWidth / dWindowWidth;
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero())
dM22 = dHeight / dWindowHeight;
double dM11 = dWidth / dWindowWidth;
double dM22 = dHeight / dWindowHeight;
double dScaleX = 1, dScaleY = 1;
if (!oWindow.m_oWidth.Empty() && !oWindow.m_oWidth.Zero() && !oViewBox.m_oWidth.Empty() && !oViewBox.m_oWidth.Zero())
if (!SVG::Equals(0., dViewBoxWidth))
dScaleX = dWindowWidth / dViewBoxWidth;
if (!oWindow.m_oHeight.Empty() && !oWindow.m_oHeight.Zero() && !oViewBox.m_oHeight.Empty() && !oViewBox.m_oHeight.Zero())
if (!SVG::Equals(0., dViewBoxHeight))
dScaleY = dWindowHeight / dViewBoxHeight;
double dMinScale = std::min(dScaleX, dScaleY);

View File

@ -7,19 +7,23 @@
#include "CSvgParser.h"
#include "SvgObjects/CStyle.h"
class CSvgFile
#define SVG_DECL_IMPORT Q_DECL_IMPORT
class SVG_DECL_IMPORT CSvgFile
{
public:
CSvgFile();
~CSvgFile();
bool ReadFromBuffer(BYTE* pBuffer, unsigned int unSize);
bool ReadFromWString(const std::wstring& wsContext);
bool OpenFromFile(const std::wstring& wsFile);
bool GetBounds(double& dX, double& dY, double& dWidth, double& dHeight) const;
const SVG::CSvgCalculator* GetSvgCalculator() const;
void SetFontManager(NSFonts::IFontManager* pFontManager);
void SetWorkingDirectory(const std::wstring& wsWorkingDirectory);
bool MarkObject(SVG::CObject* pObject);
SVG::CObject* GetMarkedObject(const std::wstring& wsId) const;

View File

@ -1,7 +1,6 @@
#ifndef CSVGPARSER_H
#define CSVGPARSER_H
#include "../../graphics/pro/Fonts.h"
#include "../../../common/Directory.h"
#include "../../../xml/include/xmlutils.h"

View File

@ -59,21 +59,23 @@ namespace SVG
NSBase64::Base64Decode(wsImageData.c_str(), wsImageData.length(), pBuffer, &(int&)ulSize);
}
#ifndef METAFILE_DISABLE_FILESYSTEM
std::wstring wsFilePath = NSSystemPath::ShortenPath(m_wsHref);
else
{
std::wstring wsFilePath = NSSystemPath::ShortenPath(m_wsHref);
bool bIsAllowExternalLocalFiles = true;
if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP))
bIsAllowExternalLocalFiles = NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP);
bool bIsAllowExternalLocalFiles = true;
if (NSProcessEnv::IsPresent(NSProcessEnv::Converter::gc_allowPrivateIP))
bIsAllowExternalLocalFiles = NSProcessEnv::GetBoolValue(NSProcessEnv::Converter::gc_allowPrivateIP);
if (!bIsAllowExternalLocalFiles && wsFilePath.length() >= 3 && L"../" == wsFilePath.substr(0, 3))
return true;
wsFilePath = pFile->GetWorkingDirectory() + L'/' + wsFilePath;
if (!NSFile::CFileBinary::Exists(wsFilePath) || !NSFile::CFileBinary::ReadAllBytes(wsFilePath, &pBuffer, ulSize))
return false;
if (!bIsAllowExternalLocalFiles && wsFilePath.length() >= 3 && L"../" == wsFilePath.substr(0, 3))
return false;
wsFilePath = pFile->GetWorkingDirectory() + L'/' + wsFilePath;
if (!NSFile::CFileBinary::Exists(wsFilePath) || !NSFile::CFileBinary::ReadAllBytes(wsFilePath, &pBuffer, ulSize))
return false;
}
#endif
if (NULL == pBuffer)