diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileObjects.h b/DesktopEditor/raster/Metafile/Common/MetaFileObjects.h index 4f11b6c8c2..1c96b94266 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileObjects.h +++ b/DesktopEditor/raster/Metafile/Common/MetaFileObjects.h @@ -33,6 +33,7 @@ #define _METAFILE_COMMON_METAFILEOBJECTS_H #include +#include namespace MetaFile { @@ -70,6 +71,8 @@ namespace MetaFile virtual void GetBounds(double& left, double& top, double& width, double& height) const = 0; virtual void GetCenterPoint(double& dX, double& dY) const = 0; + virtual std::vector> GetGradientColors() const = 0; + virtual void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const = 0; }; diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h b/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h index 389a90df7e..20b41a82de 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h +++ b/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h @@ -1109,12 +1109,18 @@ namespace MetaFile m_pRenderer->put_BrushLinearAngle(pBrush->GetStyleEx()); - long Colors[2]; - Colors[0] = pBrush->GetColor() + (pBrush->GetAlpha() << 24); - Colors[1] = pBrush->GetColor2() + (pBrush->GetAlpha2() << 24); - double Position[2] = {0, 1}; + std::vector> arColors{pBrush->GetGradientColors()}; - m_pRenderer->put_BrushGradientColors(Colors,Position,2); + std::vector arLColors(arColors.size()); + std::vector arDPositions(arColors.size()); + + for (unsigned int unIndex = 0; unIndex < arColors.size(); ++unIndex) + { + arLColors[unIndex] = arColors[unIndex].first; + arDPositions[unIndex] = arColors[unIndex].second; + } + + m_pRenderer->put_BrushGradientColors(arLColors.data(), arDPositions.data(), arColors.size()); } else if ( BS_RADIALGRADIENT == unBrushStyle || diff --git a/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp b/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp index 485cdbc437..78bcbdb27e 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp @@ -155,6 +155,15 @@ namespace MetaFile unHeight = unDibHeigth; } + std::vector > CEmfLogBrushEx::GetGradientColors() const + { + std::vector> arColors(2); + + arColors[0] = std::make_pair(GetColor() + (GetAlpha() << 24), 0.); + arColors[1] = std::make_pair(GetColor2() + (GetAlpha2() << 24), 0.); + + return arColors; + } CEmfLogFont::CEmfLogFont(bool bFixedLength) : m_bFixedLength(bFixedLength) diff --git a/DesktopEditor/raster/Metafile/Emf/EmfObjects.h b/DesktopEditor/raster/Metafile/Emf/EmfObjects.h index b2ba5d7e22..495e51524d 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfObjects.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfObjects.h @@ -77,6 +77,8 @@ namespace MetaFile void GetBounds(double& left, double& top, double& width, double& height) const override; void GetCenterPoint(double& dX, double& dY) const override; void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const override; + + std::vector> GetGradientColors() const override; public: unsigned int unBrushStyle; TRGBA oColor; diff --git a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp index b8b83d6c65..84249fdcee 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp @@ -655,20 +655,15 @@ namespace MetaFile m_oStream >> unPositionCount; - std::vector arBlendPositions(unPositionCount); - - for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex) - m_oStream >> arBlendPositions[unIndex]; - - std::vector arBlendColors(unPositionCount); - - for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex) - m_oStream >> arBlendColors[unIndex]; - - if (1 < unPositionCount) + if (unPositionCount > 1) { - pEmfPlusBrush->oColorBack = arBlendColors[0]; - pEmfPlusBrush->oColor = arBlendColors.back(); + pEmfPlusBrush->arGradientColors.resize(unPositionCount); + + for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex) + m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].second; + + for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex) + m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].first; } } @@ -679,13 +674,40 @@ namespace MetaFile //TODO: реализовать pEmfPlusBrush->unStyle = BS_LINEARGRADIENT; - m_oStream.Skip(8); // BrushDataFlags, WrapMode + int nBrushDataFlags; + m_oStream >> nBrushDataFlags; + + m_oStream.Skip(4); // WrapMode // m_oStream >> pEmfPlusBrush->RectF; m_oStream.Skip(16); m_oStream >> pEmfPlusBrush->oColor; m_oStream >> pEmfPlusBrush->oColorBack; + m_oStream.Skip(8); // Reserved1, Reserved2 + + if (BrushDataTransform & nBrushDataFlags) + { + m_oStream.Skip(24); + } + + if (BrushDataPresetColors & nBrushDataFlags) + { + int nPositionCount; + m_oStream >> nPositionCount; + + if (nPositionCount > 1) + { + pEmfPlusBrush->arGradientColors.resize(nPositionCount); + + for (unsigned int unIndex = 0; unIndex < nPositionCount; ++unIndex) + m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].second; + + for (unsigned int unIndex = 0; unIndex < nPositionCount; ++unIndex) + m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].first; + } + } + break; } default: diff --git a/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.cpp b/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.cpp index 27459c7405..35e4baf05b 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.cpp @@ -79,6 +79,29 @@ namespace MetaFile height = oRectF.dHeight; } + std::vector > CEmfPlusBrush::GetGradientColors() const + { + if (arGradientColors.empty()) + { + std::vector> arColors(2); + + arColors[0] = std::make_pair(GetColor() + (GetAlpha() << 24), 0.); + arColors[1] = std::make_pair(GetColor2() + (GetAlpha2() << 24), 0.); + + return arColors; + } + + std::vector> arColors(arGradientColors.size()); + + for (unsigned int unIndex = 0; unIndex < arGradientColors.size(); ++unIndex) + { + arColors[unIndex].first = METAFILE_RGBA(arGradientColors[unIndex].first.chRed, arGradientColors[unIndex].first.chGreen, arGradientColors[unIndex].first.chBlue, arGradientColors[unIndex].first.chAlpha); + arColors[unIndex].second = arGradientColors[unIndex].second; + } + + return arColors; + } + CEmfPlusPen::CEmfPlusPen() : unStyle(PS_SOLID | PS_GEOMETRIC | PS_STARTCAP_FLAT | PS_ENDCAP_FLAT | PS_JOIN_MITER), dWidth(1), oColor(0, 0, 0), pBrush(NULL), dMiterLimit(0), dDashOffset(0), diff --git a/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h b/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h index 351eb8320e..f473584354 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfPlusObjects.h @@ -189,6 +189,7 @@ namespace MetaFile void GetCenterPoint(double& dX, double& dY) const override; void GetBounds(double& left, double& top, double& width, double& height) const override; + std::vector> GetGradientColors() const override; public: TEmfPlusARGB oColor; TEmfPlusARGB oColorBack; @@ -198,6 +199,8 @@ namespace MetaFile TEmfPlusPointF oCenterPoint; unsigned int unAngle; std::wstring wsDibPatternPath; + + std::vector> arGradientColors; }; class CEmfPlusPen: public CEmfPlusObject, public IPen diff --git a/DesktopEditor/raster/Metafile/StarView/SvmObjects.cpp b/DesktopEditor/raster/Metafile/StarView/SvmObjects.cpp index 4654c35218..99ecfb38aa 100644 --- a/DesktopEditor/raster/Metafile/StarView/SvmObjects.cpp +++ b/DesktopEditor/raster/Metafile/StarView/SvmObjects.cpp @@ -358,6 +358,16 @@ void CSvmBrush::GetBounds(double& left, double& top, double& width, double& heig void CSvmBrush::GetDibPattern(unsigned char **pBuffer, unsigned int &unWidth, unsigned int &unHeight) const {} +std::vector > CSvmBrush::GetGradientColors() const +{ + std::vector> arColors(2); + + arColors[0] = std::make_pair(GetColor() + (GetAlpha() << 24), 0.); + arColors[1] = std::make_pair(GetColor2() + (GetAlpha2() << 24), 0.); + + return arColors; +} + int CSvmPen::GetColor() const { return METAFILE_RGBA(Color.r, Color.g, Color.b, 0); diff --git a/DesktopEditor/raster/Metafile/StarView/SvmObjects.h b/DesktopEditor/raster/Metafile/StarView/SvmObjects.h index ed4dc0fed9..71382438ec 100644 --- a/DesktopEditor/raster/Metafile/StarView/SvmObjects.h +++ b/DesktopEditor/raster/Metafile/StarView/SvmObjects.h @@ -300,6 +300,7 @@ public: void GetBounds(double& left, double& top, double& width, double& height) const override; void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const override; + std::vector> GetGradientColors() const override; public: unsigned short BrushStyleEx; //angle, or .... unsigned short BrushStyle; diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp index a7a3da0b28..809b254256 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp @@ -1276,16 +1276,19 @@ namespace MetaFile std::wstring wsStyleId; - if (BS_LINEARGRADIENT == pBrush->GetStyle() || - BS_RECTGRADIENT == pBrush->GetStyle() || - BS_PATHGRADIENT == pBrush->GetStyle()) + if (BS_LINEARGRADIENT == pBrush->GetStyle() || + BS_RECTGRADIENT == pBrush->GetStyle() || + BS_PATHGRADIENT == pBrush->GetStyle()) { wsStyleId = L"LINEARGRADIENT_" + ConvertToWString(++m_unNumberDefs, 0); - m_wsDefs += L"" + - L"GetColor(), pBrush->GetAlpha()) + L"\"/>" + - L"GetColor2(), pBrush->GetAlpha2()) + L"\"/>" + - L""; + m_wsDefs += L""; + + for (const std::pair parColorData : pBrush->GetGradientColors()) + m_wsDefs += L""; + + m_wsDefs += L""; return wsStyleId; } @@ -2065,4 +2068,12 @@ namespace MetaFile return L"rgba(" + std::to_wstring(uchRed) + L", " + std::to_wstring(uchGreen) + L", " + std::to_wstring(uchBlue) + L", " + ConvertToWString((double)uchAlpha / 255., 3) + L')'; } + + std::wstring CalculateColor(unsigned int unColor) + { + BYTE chAlpha = unColor >> 24; + + return CalculateColor(unColor, chAlpha); + } + } diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h index 5063f58f03..d9779d345c 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h @@ -158,6 +158,7 @@ namespace MetaFile friend class CWmfInterpretatorSvg; }; + std::wstring CalculateColor(unsigned int unColor); std::wstring CalculateColor(unsigned int unColor, BYTE uchAlpha); std::wstring CalculateColor(BYTE uchRed, BYTE uchGreen, BYTE uchBlue, BYTE uchAlpha); } diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfObjects.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfObjects.cpp index babf1854ad..24b65c198f 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfObjects.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfObjects.cpp @@ -162,6 +162,16 @@ namespace MetaFile unHeight = unDibHeigth; } + std::vector > CWmfBrush::GetGradientColors() const + { + std::vector> arColors(2); + + arColors[0] = std::make_pair(GetColor() + (GetAlpha() << 24), 0.); + arColors[1] = std::make_pair(GetColor2() + (GetAlpha2() << 24), 0.); + + return arColors; + } + CWmfFont::CWmfFont() : shHeight(DEFAULT_FONT_SIZE), shWidth(0), shEscapement(0), shOrientation(0), shWeight(400), uchItalic(0x00), uchUnderline(0x00), uchStrikeOut(0x00), uchCharSet(0x01), uchOutPrecision(0x00), diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfObjects.h b/DesktopEditor/raster/Metafile/Wmf/WmfObjects.h index 3c8c9f681b..8b113dccc0 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfObjects.h +++ b/DesktopEditor/raster/Metafile/Wmf/WmfObjects.h @@ -82,6 +82,8 @@ namespace MetaFile void GetBounds(double& left, double& top, double& width, double& height) const override; void GetCenterPoint(double& dX, double& dY) const override; void GetDibPattern(unsigned char** pBuffer, unsigned int &unWidth, unsigned int &unHeight) const override; + + std::vector> GetGradientColors() const override; public: unsigned short ushBrushStyle;