From 8eb5a078d8ae7f1ff5067c69210b1eb9ad999426 Mon Sep 17 00:00:00 2001 From: Kirill Polyakov Date: Wed, 27 Dec 2023 13:00:00 +0300 Subject: [PATCH] Fix bug #65284 --- .../EmfInterpretator/CEmfInterpretatorSvg.cpp | 72 ++------------ .../CInterpretatorSvgBase.cpp | 99 +++++++++++++++++++ .../WmfInterpretator/CInterpretatorSvgBase.h | 2 + .../WmfInterpretator/CWmfInterpretatorSvg.cpp | 69 ++----------- 4 files changed, 115 insertions(+), 127 deletions(-) diff --git a/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp b/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp index e14f238695..4d38adc273 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfInterpretator/CEmfInterpretatorSvg.cpp @@ -45,10 +45,10 @@ namespace MetaFile void CEmfInterpretatorSvg::HANDLE_EMR_HEADER(const TEmfHeader &oTEmfHeader) { - m_oViewport.dLeft = oTEmfHeader.oFramePx.Left; - m_oViewport.dTop = oTEmfHeader.oFramePx.Top; - m_oViewport.dRight = oTEmfHeader.oFramePx.Right; - m_oViewport.dBottom = oTEmfHeader.oFramePx.Bottom; + m_oViewport.dLeft = std::min(oTEmfHeader.oFramePx.Left, oTEmfHeader.oFramePx.Right ); + m_oViewport.dTop = std::min(oTEmfHeader.oFramePx.Top, oTEmfHeader.oFramePx.Bottom); + m_oViewport.dRight = std::max(oTEmfHeader.oFramePx.Left, oTEmfHeader.oFramePx.Right ); + m_oViewport.dBottom = std::max(oTEmfHeader.oFramePx.Top, oTEmfHeader.oFramePx.Bottom); m_pXmlWriter->WriteNodeBegin(L"svg", true); m_pXmlWriter->WriteAttribute(L"xmlns", L"http://www.w3.org/2000/svg"); @@ -1412,73 +1412,17 @@ namespace MetaFile { } - + void CEmfInterpretatorSvg::HANDLE_EMFPLUS_RESTORE(unsigned int) { m_bUpdatedClip = false; } - void CEmfInterpretatorSvg::DrawBitmap(double dX, double dY, double dW, double dH, BYTE* pBuffer, unsigned int unWidth, unsigned int unHeight) + void CEmfInterpretatorSvg::DrawBitmap(double dX, double dY, double dW, double dH, BYTE *pBuffer, unsigned int unWidth, unsigned int unHeight) { - if (NULL == pBuffer || 0 == dW || 0 == dH || 0 == unWidth || 0 == unHeight) - return; - - if (1 == unWidth && 1 == unHeight) - { - NodeAttributes arAttributes = {{L"x", ConvertToWString(dX)}, - {L"y", ConvertToWString(dY)}, - {L"width", ConvertToWString(dW)}, - {L"height", ConvertToWString(dH)}, - {L"fill", CalculateColor(pBuffer[2], pBuffer[1], pBuffer[0], 255)}}; - - AddTransform(arAttributes); - - WriteNode(L"rect", arAttributes); - - return; - } - - CBgraFrame oFrame; - - oFrame.put_Data(pBuffer); - oFrame.put_Width(unWidth); - oFrame.put_Height(unHeight); - - BYTE* pNewBuffer = NULL; - int nNewSize = 0; - - oFrame.Encode(pNewBuffer, nNewSize, 4); - oFrame.put_Data(NULL); - - if (0 < nNewSize) - { - int nImageSize = NSBase64::Base64EncodeGetRequiredLength(nNewSize); - unsigned char* ucValue = new unsigned char[nImageSize]; - - if (NULL == ucValue) - return; - - NSBase64::Base64Encode(pNewBuffer, nNewSize, ucValue, &nImageSize); - std::wstring wsValue(ucValue, ucValue + nImageSize); - - RELEASEARRAYOBJECTS(ucValue); - - NodeAttributes arAttributes = {{L"x", ConvertToWString(dX)}, - {L"y", ConvertToWString(dY)}, - {L"width", ConvertToWString(dW)}, - {L"height", ConvertToWString(dH)}, - {L"xlink:href", L"data:image/png;base64," + wsValue}}; - - AddTransform(arAttributes); - AddClip(); - - WriteNode(L"image", arAttributes); - } - - if (NULL != pNewBuffer) - delete [] pNewBuffer; + CInterpretatorSvgBase::DrawBitmap(dX, dY, dW, dH, pBuffer, unWidth, unHeight); } - + void CEmfInterpretatorSvg::ResetClip() { CInterpretatorSvgBase::ResetClip(); diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp index bd34f35333..dd52fb8bc5 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.cpp @@ -444,6 +444,105 @@ namespace MetaFile m_pXmlWriter->WriteNodeEnd(L"g"); } + void CInterpretatorSvgBase::DrawBitmap(double dX, double dY, double dW, double dH, BYTE *pBuffer, unsigned int unWidth, unsigned int unHeight) + { + if (NULL == pBuffer || Equals(0., dW) || Equals(0., dH) || 0 == unWidth || 0 == unHeight) + return; + + TXForm oTransform; + oTransform.Copy(m_pParser->GetTransform()); + + if (dW < 0 || dH < 0) + { + double dKx = 1, dKy = 1, dShiftKoefX = 0, dShiftKoefY = 0; + if (dW < 0) + { + dKx = -1; + dShiftKoefX = 2 * dX + dW; + + dW = -dW; + dX -= dW; + } + + if (dH < 0) + { + dKy = -1; + dShiftKoefY = 2 * dY + dH; + + dH = -dH; + dY -= dH; + } + + oTransform.Dx += dShiftKoefX * oTransform.M11 + dShiftKoefY * oTransform.M21; + oTransform.Dy += dShiftKoefX * oTransform.M12 + dShiftKoefY * oTransform.M22; + oTransform.M11 *= dKx; + oTransform.M12 *= dKx; + oTransform.M21 *= dKy; + oTransform.M22 *= dKy; + } + + if (1 == unWidth && 1 == unHeight) + { + NodeAttributes arAttributes = {{L"x", ConvertToWString(dX)}, + {L"y", ConvertToWString(dY)}, + {L"width", ConvertToWString(dW)}, + {L"height", ConvertToWString(dH)}, + {L"fill", CalculateColor(pBuffer[2], pBuffer[1], pBuffer[0], 255)}}; + + AddTransform(arAttributes, &oTransform); + + WriteNode(L"rect", arAttributes); + + return; + } + + CBgraFrame oFrame; + + oFrame.put_Data(pBuffer); + oFrame.put_Width(unWidth); + oFrame.put_Height(unHeight); + + BYTE* pNewBuffer = NULL; + int nNewSize = 0; + + if (!oFrame.Encode(pNewBuffer, nNewSize, 4)) + { + oFrame.put_Data(NULL); + return; + } + + oFrame.put_Data(NULL); + + if (0 < nNewSize) + { + int nImageSize = NSBase64::Base64EncodeGetRequiredLength(nNewSize); + unsigned char* ucValue = new unsigned char[nImageSize]; + + if (NULL == ucValue) + return; + + NSBase64::Base64Encode(pNewBuffer, nNewSize, ucValue, &nImageSize); + std::wstring wsValue(ucValue, ucValue + nImageSize); + + RELEASEARRAYOBJECTS(ucValue); + + NodeAttributes arAttributes = {{L"x", ConvertToWString(dX)}, + {L"y", ConvertToWString(dY)}, + {L"width", ConvertToWString(dW)}, + {L"height", ConvertToWString(dH)}, + {L"preserveAspectRatio", L"xMinYMin slice"}, + {L"xlink:href", L"data:image/png;base64," + wsValue}}; + + AddTransform(arAttributes, &oTransform); + AddClip(); + + WriteNode(L"image", arAttributes); + } + + if (NULL != pNewBuffer) + delete [] pNewBuffer; + } + void CInterpretatorSvgBase::ResetClip() { m_oClip.Reset(); diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h index eef3df644a..943d5b46db 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CInterpretatorSvgBase.h @@ -98,6 +98,8 @@ namespace MetaFile void WriteNodeEnd(const std::wstring& wsNodeName); void WriteText(const std::wstring& wsText, const TPointD& oCoord, const TRectL& oBounds = TRectL(), const TPointD& oScale = TPointD(1, 1), const std::vector& arDx = {}); + void DrawBitmap(double dX, double dY, double dW, double dH, BYTE* pBuffer, unsigned int unWidth, unsigned int unHeight) override; + void ResetClip() override; void IntersectClip(const TRectD& oClip) override; void ExcludeClip(const TRectD& oClip, const TRectD& oBB) override; diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp index 7f7bda29fb..68a13e3c20 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp @@ -30,10 +30,10 @@ namespace MetaFile TRectL *pBounds = m_pParser->GetDCBounds(); - m_oViewport.dLeft = pBounds->Left; - m_oViewport.dTop = pBounds->Top; - m_oViewport.dRight = pBounds->Right; - m_oViewport.dBottom = pBounds->Bottom; + m_oViewport.dLeft = std::min(pBounds->Left, pBounds->Right ); + m_oViewport.dTop = std::min(pBounds->Top, pBounds->Bottom); + m_oViewport.dRight = std::max(pBounds->Left, pBounds->Right ); + m_oViewport.dBottom = std::max(pBounds->Top, pBounds->Bottom); UpdateSize(); @@ -514,66 +514,9 @@ namespace MetaFile m_bUpdatedClip = false; } - void CWmfInterpretatorSvg::DrawBitmap(double dX, double dY, double dW, double dH, BYTE* pBuffer, unsigned int unWidth, unsigned int unHeight) + void CWmfInterpretatorSvg::DrawBitmap(double dX, double dY, double dW, double dH, BYTE *pBuffer, unsigned int unWidth, unsigned int unHeight) { - if (NULL == pBuffer || 0 == dW || 0 == dH || 0 == unWidth || 0 == unHeight) - return; - - if (1 == unWidth && 1 == unHeight) - { - NodeAttributes arAttributes = {{L"x", ConvertToWString(dX)}, - {L"y", ConvertToWString(dY)}, - {L"width", ConvertToWString(dW)}, - {L"height", ConvertToWString(dH)}, - {L"fill", CalculateColor(pBuffer[2], pBuffer[1], pBuffer[0], 255)}}; - - AddTransform(arAttributes); - - WriteNode(L"rect", arAttributes); - - return; - } - - CBgraFrame oFrame; - - oFrame.put_Data(pBuffer); - oFrame.put_Width(unWidth); - oFrame.put_Height(unHeight); - - BYTE* pNewBuffer = NULL; - int nNewSize = 0; - - oFrame.Encode(pNewBuffer, nNewSize, 4); - oFrame.put_Data(NULL); - - if (0 < nNewSize) - { - int nImageSize = NSBase64::Base64EncodeGetRequiredLength(nNewSize); - unsigned char* ucValue = new unsigned char[nImageSize]; - - if (NULL == ucValue) - return; - - NSBase64::Base64Encode(pNewBuffer, nNewSize, ucValue, &nImageSize); - std::wstring wsValue(ucValue, ucValue + nImageSize); - - RELEASEARRAYOBJECTS(ucValue); - - NodeAttributes arAttributes = {{L"x", ConvertToWString(dX)}, - {L"y", ConvertToWString(dY)}, - {L"width", ConvertToWString(dW)}, - {L"height", ConvertToWString(dH)}, - {L"preserveAspectRatio", L"xMinYMin slice"}, - {L"xlink:href", L"data:image/png;base64," + wsValue}}; - - AddTransform(arAttributes); - AddClip(); - - WriteNode(L"image", arAttributes); - } - - if (NULL != pNewBuffer) - delete [] pNewBuffer; + CInterpretatorSvgBase::DrawBitmap(dX, dY, dW, dH, pBuffer, unWidth, unHeight); } void CWmfInterpretatorSvg::ResetClip()