diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp index 589238874f..276a106b15 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.cpp @@ -9,6 +9,8 @@ namespace SVG if (!wsUnicode.empty()) m_wchUnicode = wsUnicode[0]; + + m_oHorizAdvX.SetValue(oNode.GetAttributeOrValue(L"horiz-adv-x")); } wchar_t CGlyph::GetUnicode() const @@ -29,6 +31,8 @@ namespace SVG m_oArguments.m_wsFontVariant = oNode.GetAttribute(L"font-variant"); m_oArguments.m_wsFontStyle = oNode.GetAttribute(L"font-style"); m_oArguments.m_wsFontWidght = oNode.GetAttribute(L"font-weight"); + + m_oHorizAdvX.SetValue(oNode.GetAttributeOrValue(L"horiz-adv-x")); } CFont::~CFont() @@ -45,6 +49,55 @@ namespace SVG bool CFont::Apply(IRenderer *pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) { + return false; + } + + bool CFont::Draw(const std::wstring &wsText, double dX, double dY, IRenderer *pRenderer, const CSvgFile *pFile, CommandeMode oMode, const TSvgStyles *pStyles) const + { + if (NULL == pRenderer) + return false; + + double dM11, dM12, dM21, dM22, dRx, dRy; + + pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dRx, &dRy); + + Aggplus::CMatrix oMatrix(dM11, dM12, dM21, dM22, dRx, dRy); + oMatrix.Translate(dX, dY); + + pRenderer->SetTransform(dM11, dM12, dM21, -dM22, oMatrix.tx(), oMatrix.ty()); + + MGlyphsMap::const_iterator itFound; + TBounds oGlyphBounds; + + for (wchar_t wchGlyph : wsText) + { + itFound = m_mGlyphs.find(wchGlyph); + + if (m_mGlyphs.cend() == itFound) + { + if (NULL == m_pMissingGlyph) + continue; + + m_pMissingGlyph->Draw(pRenderer, pFile, oMode, pStyles); + oMatrix.Translate(m_oHorizAdvX.ToDouble(NSCSS::Pixel), 0); + } + else + { + itFound->second->Draw(pRenderer, pFile, oMode, pStyles); + + if (!itFound->second->m_oHorizAdvX.Empty()) + oMatrix.Translate(itFound->second->m_oHorizAdvX.ToDouble(NSCSS::Pixel), 0); + else + oMatrix.Translate(m_oHorizAdvX.ToDouble(NSCSS::Pixel), 0); + } + + oMatrix.Translate(std::abs(oGlyphBounds.m_dRight - oGlyphBounds.m_dLeft), 0); + + pRenderer->SetTransform(dM11, dM12, dM21, -dM22, oMatrix.tx(), oMatrix.ty()); + } + + pRenderer->SetTransform(dM11, dM12, dM21, dM22, dRx, dRy); + return true; } diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h index ea5242b380..bb1b1627ad 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CFont.h @@ -12,7 +12,10 @@ namespace SVG wchar_t GetUnicode() const; private: - wchar_t m_wchUnicode; + wchar_t m_wchUnicode; + SvgDigit m_oHorizAdvX; + + friend class CFont; }; class CFontFace @@ -40,13 +43,18 @@ namespace SVG void SetData(const std::map &mAttributes, unsigned short ushLevel, bool bHardMode) override; bool Apply(IRenderer* pRenderer, const CSvgFile *pFile, const TBounds &oObjectBounds) override; + bool Draw(const std::wstring& wsText, double dX, double dY, IRenderer* pRenderer, const CSvgFile *pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pStyles = NULL) const; private: void ParseGlyphs(XmlUtils::CXmlNode& oNode); TFontArguments m_oArguments; - std::map m_mGlyphs; + typedef std::map MGlyphsMap; + + MGlyphsMap m_mGlyphs; CPath *m_pMissingGlyph; + + SvgDigit m_oHorizAdvX; }; } diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp index c324690132..377b5d36a6 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.cpp @@ -4,6 +4,7 @@ #include "../SvgUtils.h" #include "../CSvgFile.h" #include "CContainer.h" +#include "CFont.h" #include "CStyle.h" #ifndef MININT8 @@ -152,7 +153,7 @@ namespace SVG double dX, dY; CalculatePosition(dX, dY); - if (!UseExternalFont(pFile)) + if (!UseExternalFont(pFile, dX, dY, pRenderer, pFile, oMode, pOtherStyles)) { ApplyFont(pRenderer, dX, dY); @@ -296,7 +297,7 @@ namespace SVG pRenderer->put_BrushAlpha1(255); } - bool CTSpan::UseExternalFont(const CSvgFile *pFile) const + bool CTSpan::UseExternalFont(const CSvgFile *pFile, double dX, double dY, IRenderer *pRenderer, const CSvgFile *pFile, CommandeMode oMode, const TSvgStyles *pOtherStyles) const { std::wstring wsFontFamily = DefaultFontFamily; @@ -311,6 +312,8 @@ namespace SVG if (NULL == pFont) return false; + pFont->Draw(m_wsText, dX, dY, pRenderer, pFile, oMode, pOtherStyles); + return true; } diff --git a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h index c0a15944ed..840807d01f 100644 --- a/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h +++ b/DesktopEditor/raster/Metafile/svg/SvgObjects/CText.h @@ -31,7 +31,7 @@ namespace SVG void ApplyStyle(IRenderer* pRenderer, const TSvgStyles* pStyles, const CSvgFile* pFile, int& nTypePath) const override; void ApplyFont(IRenderer* pRenderer, double& dX, double& dY) const; - bool UseExternalFont(const CSvgFile* pFile) const; + bool UseExternalFont(const CSvgFile* pFile, double dX, double dY, IRenderer* pRenderer, const CSvgFile* pFile, CommandeMode oMode = CommandeModeDraw, const TSvgStyles* pOtherStyles = NULL) const; TBounds GetBounds() const override;