From 22aecb56ec2fca55a95f59a621879237b33e2603 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Thu, 6 Nov 2025 22:32:17 +0300 Subject: [PATCH] Fix bug in svg --- .../raster/Metafile/svg/CSvgParser.cpp | 2 +- .../raster/Metafile/svg/SvgObjects/CFont.cpp | 37 ++++++++++--------- .../raster/Metafile/svg/SvgObjects/CFont.h | 8 ++-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/DesktopEditor/raster/Metafile/svg/CSvgParser.cpp b/DesktopEditor/raster/Metafile/svg/CSvgParser.cpp index 8fa44c791e..209bdada77 100644 --- a/DesktopEditor/raster/Metafile/svg/CSvgParser.cpp +++ b/DesktopEditor/raster/Metafile/svg/CSvgParser.cpp @@ -294,7 +294,7 @@ namespace SVG } else if ("font" == sElementName) { - pObject = CObject::Create(oReader, pFile); + pObject = CObject::Create(oReader, pFile, pFile); } if (NULL == pObject) diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp index e7b465da49..2781dc40f8 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp @@ -2,22 +2,23 @@ namespace SVG { - CGlyph::CGlyph(CSvgReader& oReader) + CGlyph::CGlyph(CSvgReader& oReader, CSvgFile* pFile) : CPath(oReader) - { - START_READ_ATTRIBUTES(oReader) - { - if ("unicode" == sAttributeName) - { - const std::wstring wsUnicode{oReader.GetText()}; + {} - if (!wsUnicode.empty()) - m_wchUnicode = wsUnicode[0]; - } - else if ("horiz-adv-x" == sAttributeName) - m_oHorizAdvX.SetValue(oReader.GetText()); + void CGlyph::SetAttribute(const std::string& sName, CSvgReader& oReader) + { + if ("unicode" == sName) + { + const std::wstring wsUnicode{oReader.GetText()}; + + if (!wsUnicode.empty()) + m_wchUnicode = wsUnicode[0]; } - END_READ_ATTRIBUTES(oReader) + else if ("horiz-adv-x" == sName) + m_oHorizAdvX.SetValue(oReader.GetText()); + else + CPath::SetAttribute(sName, oReader); } wchar_t CGlyph::GetUnicode() const @@ -28,10 +29,10 @@ namespace SVG CFontFace::CFontFace(CSvgReader& oReader) {} - CFont::CFont(CSvgReader& oReader) + CFont::CFont(CSvgReader& oReader, CSvgFile* pFile) : CAppliedObject(oReader), m_pMissingGlyph(NULL) { - ParseGlyphs(oReader); + ParseGlyphs(oReader, pFile); } CFont::~CFont() @@ -95,7 +96,7 @@ namespace SVG { \ oMatrix.Scale(1. / dGlyphScale, -1. / dGlyphScale); \ pRenderer->SetTransform(oMatrix.sx(), oMatrix.shy(), oMatrix.shx(), oMatrix.sy(), oMatrix.tx(), oMatrix.ty()); \ - } \ + } for (wchar_t wchGlyph : wsText) { @@ -128,13 +129,13 @@ namespace SVG return true; } - void CFont::ParseGlyphs(CSvgReader& oReader) + void CFont::ParseGlyphs(CSvgReader& oReader, CSvgFile* pFile) { WHILE_READ_NEXT_NODE_WITH_NAME(oReader) { if ("glyph" == sNodeName) { - CGlyph *pGlyph = new CGlyph(oReader); + CGlyph *pGlyph = CObject::Create(oReader, pFile, pFile); if (NULL == pGlyph) continue; diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h index eb13af2d19..a79330c9db 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h @@ -8,7 +8,9 @@ namespace SVG class CGlyph : public CPath { public: - CGlyph(CSvgReader& oReader); + CGlyph(CSvgReader& oReader, CSvgFile* pFile = nullptr); + + void SetAttribute(const std::string& sName, CSvgReader& oReader) override; wchar_t GetUnicode() const; private: @@ -37,7 +39,7 @@ namespace SVG class CFont : public CAppliedObject { friend class CObject; - CFont(CSvgReader& oReader); + CFont(CSvgReader& oReader, CSvgFile* pFile = nullptr); public: ~CFont(); @@ -48,7 +50,7 @@ namespace SVG bool Apply(IRenderer* pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) override; bool Draw(const std::wstring& wsText, const double& dX, const double& dY, const double& dFontHeight, IRenderer* pRenderer, const CSvgFile *pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pStyles = NULL, const CRenderedObject* pContexObject = NULL) const; private: - void ParseGlyphs(CSvgReader& oReader); + void ParseGlyphs(CSvgReader& oReader, CSvgFile* pFile = nullptr); TFontArguments m_oArguments;