From 87a09faefbdc4ed9a2078170166aa6c601735d15 Mon Sep 17 00:00:00 2001 From: Green Date: Wed, 23 Oct 2024 14:39:51 +0300 Subject: [PATCH 1/2] Fix bug #71134 --- .../3dParty/html/css/src/CCompiledStyle.cpp | 33 ++++++------ Common/3dParty/html/css/src/CCompiledStyle.h | 1 + .../3dParty/html/css/src/StyleProperties.cpp | 50 +++++++++++-------- Common/3dParty/html/css/src/StyleProperties.h | 16 +++--- .../raster/Metafile/Common/MetaFile.h | 2 +- 5 files changed, 56 insertions(+), 46 deletions(-) diff --git a/Common/3dParty/html/css/src/CCompiledStyle.cpp b/Common/3dParty/html/css/src/CCompiledStyle.cpp index ee46db33ee..059140bc77 100644 --- a/Common/3dParty/html/css/src/CCompiledStyle.cpp +++ b/Common/3dParty/html/css/src/CCompiledStyle.cpp @@ -18,12 +18,12 @@ namespace NSCSS { typedef std::map::const_iterator styles_iterator; - CCompiledStyle::CCompiledStyle() : m_nDpi(96), m_UnitMeasure(Point) + CCompiledStyle::CCompiledStyle() : m_nDpi(96), m_UnitMeasure(Point), m_dCoreFontSize(DEFAULT_FONT_SIZE) {} CCompiledStyle::CCompiledStyle(const CCompiledStyle& oStyle) : m_arParentsStyles(oStyle.m_arParentsStyles), m_sId(oStyle.m_sId), - m_nDpi(oStyle.m_nDpi), m_UnitMeasure(oStyle.m_UnitMeasure), + m_nDpi(oStyle.m_nDpi), m_UnitMeasure(oStyle.m_UnitMeasure), m_dCoreFontSize(oStyle.m_dCoreFontSize), m_oFont(oStyle.m_oFont), m_oMargin(oStyle.m_oMargin), m_oPadding(oStyle.m_oPadding), m_oBackground(oStyle.m_oBackground), m_oText(oStyle.m_oText), m_oBorder(oStyle.m_oBorder), m_oDisplay(oStyle.m_oDisplay){} @@ -116,7 +116,10 @@ namespace NSCSS void CCompiledStyle::AddStyle(const std::map& mStyle, const unsigned int unLevel, const bool& bHardMode) { const bool bIsThereBorder = (m_oBorder.Empty()) ? false : true; - const double dFontSize = (!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Point) : DEFAULT_FONT_SIZE; + const double dParentFontSize = (!m_oFont.GetSize().Empty()) ? m_oFont.GetSize().ToDouble(NSCSS::Point) : DEFAULT_FONT_SIZE; + + if (0 == unLevel) + m_dCoreFontSize = dParentFontSize; for (std::pair pPropertie : mStyle) { @@ -128,15 +131,15 @@ namespace NSCSS CASE(L"font"): { m_oFont.SetValue(pPropertie.second, unLevel, bHardMode); - m_oFont.UpdateSize(dFontSize); - m_oFont.UpdateLineHeight(dFontSize); + m_oFont.UpdateSize(dParentFontSize, m_dCoreFontSize); + m_oFont.UpdateLineHeight(dParentFontSize, m_dCoreFontSize); break; } CASE(L"font-size"): CASE(L"font-size-adjust"): { m_oFont.SetSize(pPropertie.second, unLevel, bHardMode); - m_oFont.UpdateSize(dFontSize); + m_oFont.UpdateSize(dParentFontSize, m_dCoreFontSize); break; } CASE(L"font-stretch"): @@ -176,7 +179,7 @@ namespace NSCSS break; m_oMargin.SetValues(pPropertie.second, unLevel, bHardMode); - m_oMargin.UpdateAll(dFontSize); + m_oMargin.UpdateAll(dParentFontSize, m_dCoreFontSize); break; } CASE(L"margin-top"): @@ -196,7 +199,7 @@ namespace NSCSS break; m_oMargin.SetRight(pPropertie.second, unLevel, bHardMode); - m_oMargin.UpdateRight(dFontSize); + m_oMargin.UpdateRight(dParentFontSize, m_dCoreFontSize); break; } CASE(L"margin-bottom"): @@ -206,7 +209,7 @@ namespace NSCSS break; m_oMargin.SetBottom(pPropertie.second, unLevel, bHardMode); - m_oMargin.UpdateBottom(dFontSize); + m_oMargin.UpdateBottom(dParentFontSize, m_dCoreFontSize); break; } CASE(L"margin-left"): @@ -217,7 +220,7 @@ namespace NSCSS break; m_oMargin.SetLeft(pPropertie.second, unLevel, bHardMode); - m_oMargin.UpdateLeft(dFontSize); + m_oMargin.UpdateLeft(dParentFontSize, m_dCoreFontSize); break; } //PADDING @@ -225,35 +228,35 @@ namespace NSCSS CASE(L"mso-padding-alt"): { m_oPadding.SetValues(pPropertie.second, unLevel, bHardMode); - m_oPadding.UpdateAll(dFontSize); + m_oPadding.UpdateAll(dParentFontSize, m_dCoreFontSize); break; } CASE(L"padding-top"): CASE(L"mso-padding-top-alt"): { m_oPadding.SetTop(pPropertie.second, unLevel, bHardMode); - m_oPadding.UpdateTop(dFontSize); + m_oPadding.UpdateTop(dParentFontSize, m_dCoreFontSize); break; } CASE(L"padding-right"): CASE(L"mso-padding-right-alt"): { m_oPadding.SetRight(pPropertie.second, unLevel, bHardMode); - m_oPadding.UpdateRight(dFontSize); + m_oPadding.UpdateRight(dParentFontSize, m_dCoreFontSize); break; } CASE(L"padding-bottom"): CASE(L"mso-padding-bottom-alt"): { m_oPadding.SetBottom(pPropertie.second, unLevel, bHardMode); - m_oPadding.UpdateBottom(dFontSize); + m_oPadding.UpdateBottom(dParentFontSize, m_dCoreFontSize); break; } CASE(L"padding-left"): CASE(L"mso-padding-left-alt"): { m_oPadding.SetLeft(pPropertie.second, unLevel, bHardMode); - m_oPadding.UpdateLeft(dFontSize); + m_oPadding.UpdateLeft(dParentFontSize, m_dCoreFontSize); break; } // TEXT diff --git a/Common/3dParty/html/css/src/CCompiledStyle.h b/Common/3dParty/html/css/src/CCompiledStyle.h index 7877945a6b..530e41b4a3 100644 --- a/Common/3dParty/html/css/src/CCompiledStyle.h +++ b/Common/3dParty/html/css/src/CCompiledStyle.h @@ -22,6 +22,7 @@ namespace NSCSS unsigned short int m_nDpi; UnitMeasure m_UnitMeasure; + double m_dCoreFontSize; public: NSProperties::CFont m_oFont; NSProperties::CIndent m_oMargin; diff --git a/Common/3dParty/html/css/src/StyleProperties.cpp b/Common/3dParty/html/css/src/StyleProperties.cpp index fcfc62b0e3..eff2556758 100644 --- a/Common/3dParty/html/css/src/StyleProperties.cpp +++ b/Common/3dParty/html/css/src/StyleProperties.cpp @@ -2301,32 +2301,32 @@ namespace NSCSS return m_oLeft.SetValue(dValue, unLevel, bHardMode); } - void CIndent::UpdateAll(double dFontSize) + void CIndent::UpdateAll(const double& dParentFontSize, const double& dCoreFontSize) { - UpdateTop (dFontSize); - UpdateRight (dFontSize); - UpdateBottom(dFontSize); - UpdateLeft (dFontSize); + UpdateTop (dParentFontSize, dCoreFontSize); + UpdateRight (dParentFontSize, dCoreFontSize); + UpdateBottom(dParentFontSize, dCoreFontSize); + UpdateLeft (dParentFontSize, dCoreFontSize); } - void CIndent::UpdateTop(double dFontSize) + void CIndent::UpdateTop(const double& dParentFontSize, const double& dCoreFontSize) { - UpdateSide(m_oTop, dFontSize); + UpdateSide(m_oTop, dParentFontSize, dCoreFontSize); } - void CIndent::UpdateRight(double dFontSize) + void CIndent::UpdateRight(const double& dParentFontSize, const double& dCoreFontSize) { - UpdateSide(m_oRight, dFontSize); + UpdateSide(m_oRight, dParentFontSize, dCoreFontSize); } - void CIndent::UpdateBottom(double dFontSize) + void CIndent::UpdateBottom(const double& dParentFontSize, const double& dCoreFontSize) { - UpdateSide(m_oBottom, dFontSize); + UpdateSide(m_oBottom, dParentFontSize, dCoreFontSize); } - void CIndent::UpdateLeft(double dFontSize) + void CIndent::UpdateLeft(const double& dParentFontSize, const double& dCoreFontSize) { - UpdateSide(m_oLeft, dFontSize); + UpdateSide(m_oLeft, dParentFontSize, dCoreFontSize); } const CDigit &CIndent::GetTop() const @@ -2395,13 +2395,15 @@ namespace NSCSS return bTopResult || bRightResult || bBottomResult || bLeftResult; } - void CIndent::UpdateSide(CDigit &oSide, double dFontSize) + void CIndent::UpdateSide(CDigit &oSide, const double& dParentFontSize, const double& dCoreFontSize) { if (oSide.Empty()) return; - if (NSCSS::Em == oSide.GetUnitMeasure() || NSCSS::Rem == oSide.GetUnitMeasure()) - oSide.ConvertTo(NSCSS::Twips, dFontSize); + if (NSCSS::Em == oSide.GetUnitMeasure()) + oSide.ConvertTo(NSCSS::Twips, dParentFontSize); + else if (NSCSS::Rem == oSide.GetUnitMeasure()) + oSide.ConvertTo(NSCSS::Twips, dCoreFontSize); } // FONT @@ -2644,16 +2646,20 @@ namespace NSCSS std::make_pair(L"700", L"bold"), std::make_pair(L"800", L"bold"), std::make_pair(L"900", L"bold")}, unLevel, bHardMode); } - void CFont::UpdateSize(double dFontSize) + void CFont::UpdateSize(const double& dParentFontSize, const double& dCoreFontSize) { - if (NSCSS::Em == m_oSize.GetUnitMeasure() || NSCSS::Rem == m_oSize.GetUnitMeasure() || NSCSS::Percent == m_oSize.GetUnitMeasure()) - m_oSize.ConvertTo(NSCSS::Point, dFontSize); + if (NSCSS::Em == m_oSize.GetUnitMeasure() || NSCSS::Percent == m_oSize.GetUnitMeasure()) + m_oSize.ConvertTo(NSCSS::Point, dParentFontSize); + else if (NSCSS::Rem == m_oSize.GetUnitMeasure()) + m_oSize.ConvertTo(NSCSS::Point, dCoreFontSize); } - void CFont::UpdateLineHeight(double dFontSize) + void CFont::UpdateLineHeight(const double& dParentFontSize, const double& dCoreFontSize) { - if (NSCSS::Em == m_oLineHeight.GetUnitMeasure() || NSCSS::Rem == m_oLineHeight.GetUnitMeasure()) - m_oLineHeight.ConvertTo(NSCSS::Twips, dFontSize); + if (NSCSS::Em == m_oLineHeight.GetUnitMeasure()) + m_oLineHeight.ConvertTo(NSCSS::Twips, dParentFontSize); + else if (NSCSS::Rem == m_oLineHeight.GetUnitMeasure()) + m_oLineHeight.ConvertTo(NSCSS::Twips, dCoreFontSize); } bool CFont::Bold() const diff --git a/Common/3dParty/html/css/src/StyleProperties.h b/Common/3dParty/html/css/src/StyleProperties.h index 91a9afb2f9..92713238c2 100644 --- a/Common/3dParty/html/css/src/StyleProperties.h +++ b/Common/3dParty/html/css/src/StyleProperties.h @@ -656,11 +656,11 @@ namespace NSCSS bool SetLeft (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); bool SetLeft (const double& dValue, unsigned int unLevel, bool bHardMode = false); - void UpdateAll (double dFontSize); - void UpdateTop (double dFontSize); - void UpdateRight (double dFontSize); - void UpdateBottom(double dFontSize); - void UpdateLeft (double dFontSize); + void UpdateAll (const double& dParentFontSize, const double& dCoreFontSize); + void UpdateTop (const double& dParentFontSize, const double& dCoreFontSize); + void UpdateRight (const double& dParentFontSize, const double& dCoreFontSize); + void UpdateBottom(const double& dParentFontSize, const double& dCoreFontSize); + void UpdateLeft (const double& dParentFontSize, const double& dCoreFontSize); const CDigit& GetTop () const; const CDigit& GetRight () const; @@ -675,7 +675,7 @@ namespace NSCSS bool operator!=(const CIndent& oIndent) const; private: bool SetValues(const std::wstring& wsTopValue, const std::wstring& wsRightValue, const std::wstring& wsBottomValue, const std::wstring& wsLeftValue, unsigned int unLevel, bool bHardMode = false); - void UpdateSide(CDigit& oSide, double dFontSize); + void UpdateSide(CDigit& oSide, const double& dParentFontSize, const double& dCoreFontSize); CDigit m_oLeft; CDigit m_oTop; @@ -702,8 +702,8 @@ namespace NSCSS bool SetVariant (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); bool SetWeight (const std::wstring& wsValue, unsigned int unLevel, bool bHardMode = false); - void UpdateSize(double dFontSize); - void UpdateLineHeight(double dFontSize); + void UpdateSize(const double& dParentFontSize, const double& dCoreFontSize); + void UpdateLineHeight(const double& dParentFontSize, const double& dCoreFontSize); void Clear(); diff --git a/DesktopEditor/raster/Metafile/Common/MetaFile.h b/DesktopEditor/raster/Metafile/Common/MetaFile.h index 0bd2dbc146..4e0d19f671 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFile.h +++ b/DesktopEditor/raster/Metafile/Common/MetaFile.h @@ -45,7 +45,7 @@ namespace MetaFile { public: IMetaFileBase() - : m_pOutput(NULL), m_pBufferData(NULL), m_bIsExternalBuffer(false), m_bError(false), m_pParent(NULL) + : m_pOutput(NULL), m_pParent(NULL), m_pBufferData(NULL), m_bIsExternalBuffer(false), m_bError(false) { m_oStream.SetStream(NULL, 0); } From 19694bf32df27eb8480ae1c1f1a7f135c8940186 Mon Sep 17 00:00:00 2001 From: Green Date: Fri, 25 Oct 2024 12:49:34 +0300 Subject: [PATCH 2/2] Adjusted the definition of the possibility of obtaining a local image in html --- EpubFile/src/CEpubFile.cpp | 1 + HtmlFile2/htmlfile2.cpp | 18 +++++++++++++++--- HtmlFile2/htmlfile2.h | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/EpubFile/src/CEpubFile.cpp b/EpubFile/src/CEpubFile.cpp index 587fa3fda5..0ee795bb15 100644 --- a/EpubFile/src/CEpubFile.cpp +++ b/EpubFile/src/CEpubFile.cpp @@ -155,6 +155,7 @@ HRESULT CEpubFile::Convert(const std::wstring& sInputFile, const std::wstring& s std::wstring sDocxFileTempDir = m_sTempDir + L"/tmp"; NSDirectory::CreateDirectory(sDocxFileTempDir); oFile.SetTmpDirectory(sDocxFileTempDir); + oFile.SetCoreDirectory(NSFile::GetDirectoryName(sContent)); std::vector arFiles; for (const CBookContentItem& oContent : m_arContents) diff --git a/HtmlFile2/htmlfile2.cpp b/HtmlFile2/htmlfile2.cpp index 9c3bfda306..d0eeb0f31c 100644 --- a/HtmlFile2/htmlfile2.cpp +++ b/HtmlFile2/htmlfile2.cpp @@ -1400,11 +1400,17 @@ bool GetStatusUsingExternalLocalFiles() return true; } -bool CanUseThisPath(const std::wstring& wsPath, bool bIsAllowExternalLocalFiles) +bool CanUseThisPath(const std::wstring& wsPath, const std::wstring& wsSrcPath, const std::wstring& wsCorePath, bool bIsAllowExternalLocalFiles) { if (bIsAllowExternalLocalFiles) return true; + if (!wsCorePath.empty()) + { + const std::wstring wsFullPath = NSSystemPath::ShortenPath(NSSystemPath::Combine(wsSrcPath, wsPath)); + return boost::starts_with(wsFullPath, wsCorePath); + } + if (wsPath.length() >= 3 && L"../" == wsPath.substr(0, 3)) return false; @@ -1424,6 +1430,7 @@ public: std::wstring m_sSrc; // Директория источника std::wstring m_sDst; // Директория назначения std::wstring m_sBase; // Полный базовый адрес + std::wstring m_sCore; // Путь до корневого файла (используется для работы с Epub) NSCSS::CTree m_oTree; // Дерево body html-файла @@ -4205,7 +4212,7 @@ private: { sSrcM = NSSystemPath::ShortenPath(sSrcM); - if (!CanUseThisPath(sSrcM, bIsAllowExternalLocalFiles)) + if (!CanUseThisPath(sSrcM, m_sSrc, m_sCore, bIsAllowExternalLocalFiles)) return true; } @@ -4683,7 +4690,12 @@ bool CHtmlFile2::IsMhtFile(const std::wstring& sFile) void CHtmlFile2::SetTmpDirectory(const std::wstring& sFolder) { - m_internal->m_sTmp = sFolder; + m_internal->m_sTmp = NSSystemPath::NormalizePath(sFolder); +} + +void CHtmlFile2::SetCoreDirectory(const std::wstring& wsFolder) +{ + m_internal->m_sCore = NSSystemPath::NormalizePath(wsFolder); } HRESULT CHtmlFile2::OpenHtml(const std::wstring& sSrc, const std::wstring& sDst, CHtmlParams* oParams) diff --git a/HtmlFile2/htmlfile2.h b/HtmlFile2/htmlfile2.h index 80ed8f1214..a7c70f9ae8 100644 --- a/HtmlFile2/htmlfile2.h +++ b/HtmlFile2/htmlfile2.h @@ -84,6 +84,7 @@ public: bool IsHtmlFile(const std::wstring& sFile); bool IsMhtFile (const std::wstring& sFile); void SetTmpDirectory(const std::wstring& sFolder); + void SetCoreDirectory(const std::wstring& wsFolder); HRESULT OpenHtml(const std::wstring& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL); HRESULT OpenMht (const std::wstring& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL); HRESULT OpenBatchHtml(const std::vector& sPath, const std::wstring& sDirectory, CHtmlParams* oParams = NULL);