From beb8574dfd1c263bec39eb8e5a2d3bac9d128768 Mon Sep 17 00:00:00 2001 From: Green Date: Mon, 3 Feb 2025 04:46:08 +0300 Subject: [PATCH 1/4] Fix bug #72962 --- .../raster/Metafile/Common/MetaFileRenderer.h | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h b/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h index 507ee0082f..fe042dc3bf 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h +++ b/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h @@ -1218,30 +1218,56 @@ namespace MetaFile else if (PS_JOIN_MITER == ulPenJoin) nJoinStyle = Aggplus::LineJoinMiter; - const double dWidth = pPen->GetWidth() * m_dScaleX; - const double dMiterLimit = (0 != pPen->GetMiterLimit()) ? pPen->GetMiterLimit() : m_pFile->GetMiterLimit() * m_dScaleX; + double dWidth = pPen->GetWidth(); - BYTE nDashStyle = Aggplus::DashStyleSolid; + // Повторение кода из Graphics для вычисления минимальной ширины пера + double dM11, dM12, dM21, dM22, dDx, dDy; + m_pRenderer->GetTransform(&dM11, &dM12, &dM21, &dM22, &dDx, &dDy); + + Aggplus::CMatrix oMatrix; + + oMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy); + oMatrix.Scale(1. / m_dScaleX, 1. / m_dScaleY); double *pDataDash; unsigned int unSizeDash; pPen->GetDashData(pDataDash, unSizeDash); + // Вычисление минимально возможной ширины пера + // # Код явялется дублированным из Graphics + const double dSqrtDet = sqrt(abs(oMatrix.Determinant())); + const double dWidthMinSize = (dSqrtDet != 0) ? (1.0 / dSqrtDet) : dWidth; + + if (0 == pPen->GetWidth()) + { + double dX = 0.72, dY = 0.72; + + oMatrix.Invert(); + oMatrix.TransformPoint(dX, dY); + dX -= oMatrix.OffsetX(); + dY -= oMatrix.OffsetY(); + dWidth = std::min(abs(dX), abs(dY)); + } + //------------------------ + else + dWidth *= m_dScaleX; + + if (dWidth < dWidthMinSize) + dWidth = dWidthMinSize; + + const double dMiterLimit = (0 != pPen->GetMiterLimit()) ? pPen->GetMiterLimit() : m_pFile->GetMiterLimit() * m_dScaleX; + + BYTE nDashStyle = Aggplus::DashStyleSolid; + if (NULL != pDataDash && 0 != unSizeDash) { m_pRenderer->put_PenDashOffset(pPen->GetDashOffset()); - double dM11, dTemp; - m_pRenderer->GetTransform(&dM11, &dTemp, &dTemp, &dTemp, &dTemp, &dTemp); - double dDpi; - m_pRenderer->get_DpiX(&dDpi); - const double dNewWidth{dWidth * dM11 * dDpi / 25.4}; - std::vector arDashes(unSizeDash); for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex) - arDashes[unIndex] = pDataDash[unIndex] * dNewWidth; + arDashes[unIndex] = pDataDash[unIndex] * dWidth; m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash); @@ -1251,45 +1277,39 @@ namespace MetaFile { std::vector arDashPattern; - double dM11, dTemp; - m_pRenderer->GetTransform(&dM11, &dTemp, &dTemp, &dTemp, &dTemp, &dTemp); - double dDpi; - m_pRenderer->get_DpiX(&dDpi); - const double dNewWidth{dWidth * dM11 * dDpi / 25.4}; - switch (ulPenStyle) { case PS_DASH: { - arDashPattern.push_back(9 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); + arDashPattern.push_back(9 * dWidth); + arDashPattern.push_back(3 * dWidth); break; } case PS_DOT: { - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); + arDashPattern.push_back(3 * dWidth); + arDashPattern.push_back(3 * dWidth); break; } case PS_DASHDOT: { - arDashPattern.push_back(9 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); + arDashPattern.push_back(9 * dWidth); + arDashPattern.push_back(6 * dWidth); + arDashPattern.push_back(3 * dWidth); + arDashPattern.push_back(6 * dWidth); break; } case PS_DASHDOTDOT: { - arDashPattern.push_back(9 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); - arDashPattern.push_back(3 * dNewWidth); + arDashPattern.push_back(9 * dWidth); + arDashPattern.push_back(6 * dWidth); + arDashPattern.push_back(3 * dWidth); + arDashPattern.push_back(6 * dWidth); + arDashPattern.push_back(3 * dWidth); + arDashPattern.push_back(6 * dWidth); break; } From b7d346460924746698f70e3127af95ca6d1ffb87 Mon Sep 17 00:00:00 2001 From: Green Date: Thu, 6 Feb 2025 13:41:28 +0300 Subject: [PATCH 2/4] Edited default mode ShapeRendering for metafile to svg conversion --- DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.cpp | 2 +- DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.cpp b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.cpp index cffcbabb82..b69bafd5d3 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.cpp @@ -763,7 +763,7 @@ namespace MetaFile if (InterpretatorType::Svg == oInterpretatorType) { CEmfInterpretatorSvg *pEmfInterpretatorSvg = new CEmfInterpretatorSvg(this, dWidth, dHeight); - pEmfInterpretatorSvg->SetShapeRendering(EShapeRendering::CrispEdges); + pEmfInterpretatorSvg->SetShapeRendering(EShapeRendering::OptimizeSpeed); m_pInterpretator = pEmfInterpretatorSvg; } } diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp index b8d03f538e..c0d82821f1 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp @@ -196,7 +196,7 @@ namespace MetaFile if (InterpretatorType::Svg == oInterpretatorType) { CWmfInterpretatorSvg *pWmfInterpretatorSvg = new CWmfInterpretatorSvg(this, unWidth, unHeight); - pWmfInterpretatorSvg->SetShapeRendering(EShapeRendering::CrispEdges); + pWmfInterpretatorSvg->SetShapeRendering(EShapeRendering::OptimizeSpeed); m_pInterpretator = pWmfInterpretatorSvg; } } From 2a0c84513b93f7b6be5b614b42f3d3520faf5c94 Mon Sep 17 00:00:00 2001 From: Green Date: Thu, 6 Feb 2025 15:34:29 +0300 Subject: [PATCH 3/4] For bug #72962 --- .../raster/Metafile/Common/MetaFileRenderer.h | 128 ++++++++++-------- 1 file changed, 72 insertions(+), 56 deletions(-) diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h b/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h index fe042dc3bf..bc2351eab7 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h +++ b/DesktopEditor/raster/Metafile/Common/MetaFileRenderer.h @@ -100,8 +100,6 @@ namespace MetaFile m_bStartedPath = false; m_bUpdatedClip = true; - m_pRenderer->CommandLong(c_nPenWidth0As1px, 1); - //int alpha = 0xff; //m_pRenderer->put_BrushAlpha1(alpha); //m_pRenderer->put_BrushType(c_BrushTypeSolid); @@ -1229,11 +1227,6 @@ namespace MetaFile oMatrix.SetElements(dM11, dM12, dM21, dM22, dDx, dDy); oMatrix.Scale(1. / m_dScaleX, 1. / m_dScaleY); - double *pDataDash; - unsigned int unSizeDash; - - pPen->GetDashData(pDataDash, unSizeDash); - // Вычисление минимально возможной ширины пера // # Код явялется дублированным из Graphics const double dSqrtDet = sqrt(abs(oMatrix.Determinant())); @@ -1251,77 +1244,100 @@ namespace MetaFile } //------------------------ else + { dWidth *= m_dScaleX; - if (dWidth < dWidthMinSize) - dWidth = dWidthMinSize; + if (dWidth < dWidthMinSize) + dWidth = dWidthMinSize; + } const double dMiterLimit = (0 != pPen->GetMiterLimit()) ? pPen->GetMiterLimit() : m_pFile->GetMiterLimit() * m_dScaleX; BYTE nDashStyle = Aggplus::DashStyleSolid; - if (NULL != pDataDash && 0 != unSizeDash) + double *pDataDash; + unsigned int unSizeDash; + + pPen->GetDashData(pDataDash, unSizeDash); + + if ((NULL != pDataDash && 0 != unSizeDash) || PS_SOLID != ulPenStyle) { - m_pRenderer->put_PenDashOffset(pPen->GetDashOffset()); + // Дублированный код из Graphics + // Без этого используется оригинальный код в Graphics, который отрисовывает уже неверно + double dDashWidth{dWidth}; + + if (!Equals(dWidthMinSize, dWidth)) + { + double dDet = oMatrix.Determinant(); + + if (fabs(dDet) < 0.0001) + dDashWidth *= dSqrtDet; + } + // ----------------------------- - std::vector arDashes(unSizeDash); + if (NULL != pDataDash && 0 != unSizeDash) + { + m_pRenderer->put_PenDashOffset(pPen->GetDashOffset()); - for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex) - arDashes[unIndex] = pDataDash[unIndex] * dWidth; + std::vector arDashes(unSizeDash); - m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash); + for (unsigned int unIndex = 0; unIndex < unSizeDash; ++unIndex) + arDashes[unIndex] = pDataDash[unIndex] * dDashWidth; - nDashStyle = Aggplus::DashStyleCustom; - } - else if (PS_SOLID != ulPenStyle) - { - std::vector arDashPattern; + m_pRenderer->PenDashPattern(arDashes.data(), unSizeDash); - switch (ulPenStyle) + nDashStyle = Aggplus::DashStyleCustom; + } + else { - case PS_DASH: - { - arDashPattern.push_back(9 * dWidth); - arDashPattern.push_back(3 * dWidth); + std::vector arDashPattern; - break; - } - case PS_DOT: + switch (ulPenStyle) { - arDashPattern.push_back(3 * dWidth); - arDashPattern.push_back(3 * dWidth); + case PS_DASH: + { + arDashPattern.push_back(9 * dDashWidth); + arDashPattern.push_back(3 * dDashWidth); - break; - } - case PS_DASHDOT: - { - arDashPattern.push_back(9 * dWidth); - arDashPattern.push_back(6 * dWidth); - arDashPattern.push_back(3 * dWidth); - arDashPattern.push_back(6 * dWidth); + break; + } + case PS_DOT: + { + arDashPattern.push_back(3 * dDashWidth); + arDashPattern.push_back(3 * dDashWidth); + + break; + } + case PS_DASHDOT: + { + arDashPattern.push_back(9 * dDashWidth); + arDashPattern.push_back(6 * dDashWidth); + arDashPattern.push_back(3 * dDashWidth); + arDashPattern.push_back(6 * dDashWidth); - break; + break; + } + case PS_DASHDOTDOT: + { + arDashPattern.push_back(9 * dDashWidth); + arDashPattern.push_back(6 * dDashWidth); + arDashPattern.push_back(3 * dDashWidth); + arDashPattern.push_back(6 * dDashWidth); + arDashPattern.push_back(3 * dDashWidth); + arDashPattern.push_back(6 * dDashWidth); + + break; + } } - case PS_DASHDOTDOT: + + if (!arDashPattern.empty()) { - arDashPattern.push_back(9 * dWidth); - arDashPattern.push_back(6 * dWidth); - arDashPattern.push_back(3 * dWidth); - arDashPattern.push_back(6 * dWidth); - arDashPattern.push_back(3 * dWidth); - arDashPattern.push_back(6 * dWidth); - - break; + m_pRenderer->PenDashPattern(arDashPattern.data(), arDashPattern.size()); + nDashStyle = Aggplus::DashStyleCustom; + nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat; + nJoinStyle = Aggplus::LineJoinMiter; } } - - if (!arDashPattern.empty()) - { - m_pRenderer->PenDashPattern(arDashPattern.data(), arDashPattern.size()); - nDashStyle = Aggplus::DashStyleCustom; - nStartCapStyle = nEndCapStyle = Aggplus::LineCapFlat; - nJoinStyle = Aggplus::LineJoinMiter; - } } m_pRenderer->put_PenDashStyle(nDashStyle); From 612142f0ae4ec7c7a11332dedd30d4c73d64f59a Mon Sep 17 00:00:00 2001 From: Green Date: Thu, 6 Feb 2025 16:27:14 +0300 Subject: [PATCH 4/4] Refactoring --- .../raster/Metafile/Common/MetaFileTypes.cpp | 16 ++++- .../raster/Metafile/Common/MetaFileTypes.h | 2 + .../raster/Metafile/Common/MetaFileUtils.cpp | 38 ++++-------- .../raster/Metafile/Emf/EmfObjects.cpp | 1 - .../Metafile/Emf/EmfParser/CEmfParser.cpp | 10 ++++ .../Metafile/Emf/EmfParser/CEmfParserBase.h | 4 -- .../Metafile/Emf/EmfParser/CEmfPlusParser.cpp | 60 ++++++++----------- .../Metafile/Emf/EmfParser/CEmfPlusParser.h | 2 - .../raster/Metafile/Emf/EmfPlusTypes.h | 10 ++++ .../raster/Metafile/StarView/SvmFile.cpp | 2 + .../WmfInterpretator/CWmfInterpretatorSvg.cpp | 8 ++- .../Metafile/Wmf/WmfParser/CWmfParser.cpp | 2 +- .../Metafile/Wmf/WmfParser/CWmfParserBase.cpp | 38 +++++++----- .../Metafile/Wmf/WmfParser/CWmfParserBase.h | 1 + 14 files changed, 108 insertions(+), 86 deletions(-) diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileTypes.cpp b/DesktopEditor/raster/Metafile/Common/MetaFileTypes.cpp index b6293a91ce..697c9440ff 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileTypes.cpp +++ b/DesktopEditor/raster/Metafile/Common/MetaFileTypes.cpp @@ -44,7 +44,8 @@ namespace MetaFile : r(_r), g(_g), b(_b), a(_a) {} - TRGBA::TRGBA(int nValue) : r((nValue >> 0) & 0xFF), g((nValue >> 8) & 0xFF), b((nValue >> 16) & 0xFF), a((nValue >> 24) & 0xFF) + TRGBA::TRGBA(int nValue) + : r((nValue >> 0) & 0xFF), g((nValue >> 8) & 0xFF), b((nValue >> 16) & 0xFF), a((nValue >> 24) & 0xFF) {} void TRGBA::Set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a) @@ -94,7 +95,18 @@ namespace MetaFile return a; } - TXForm::TXForm() : M11(1), M12(0), M21(0), M22(1), Dx(0), Dy(0) + TRGBA& TRGBA::operator=(const TRGBA& oRGBA) + { + r = oRGBA.r; + g = oRGBA.g; + b = oRGBA.b; + a = oRGBA.a; + + return *this; + } + + TXForm::TXForm() + : M11(1), M12(0), M21(0), M22(1), Dx(0), Dy(0) {} TXForm::TXForm(const TXForm &oXForm) diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileTypes.h b/DesktopEditor/raster/Metafile/Common/MetaFileTypes.h index 4bd9ff3da7..09ff44864a 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileTypes.h +++ b/DesktopEditor/raster/Metafile/Common/MetaFileTypes.h @@ -558,6 +558,8 @@ namespace MetaFile unsigned char GetGreen() const; unsigned char GetBlue() const; unsigned char GetAlpha() const; + + TRGBA& operator=(const TRGBA& oRGBA); }; struct TXForm diff --git a/DesktopEditor/raster/Metafile/Common/MetaFileUtils.cpp b/DesktopEditor/raster/Metafile/Common/MetaFileUtils.cpp index 29ab635fda..ed46d2c551 100644 --- a/DesktopEditor/raster/Metafile/Common/MetaFileUtils.cpp +++ b/DesktopEditor/raster/Metafile/Common/MetaFileUtils.cpp @@ -237,7 +237,9 @@ namespace MetaFile } for (int nAddIndex = 0; nAddIndex < nAdditBytes; nAddIndex++) { - int nByte = *pBuffer; pBuffer++; lBufLen--; + // int nByte = *pBuffer; + ++pBuffer; + --lBufLen; } } } @@ -271,7 +273,9 @@ namespace MetaFile } for (int nAddIndex = 0; nAddIndex < nAdditBytes; nAddIndex++) { - int nByte = *pBuffer; pBuffer++; lBufLen--; + // int nByte = *pBuffer; + ++pBuffer; + --lBufLen; } } } @@ -490,7 +494,12 @@ namespace MetaFile } if (lBufLen < (nWidth + nAdd) * abs(nHeight)) + { + if (pUncompressedBuffer) + delete[] pUncompressedBuffer; + return false; + } pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)]; if (NULL == pBgraBuffer) @@ -643,7 +652,7 @@ namespace MetaFile *pulWidth = ulWidth; *pulHeight = ulHeight; - return false; + return true; } else if (BI_BITCOUNT_5 == ushBitCount) { @@ -990,29 +999,6 @@ namespace MetaFile } } - std::wstring ascii_to_unicode(const char *src) - { - size_t nSize = mbstowcs(0, src, 0); - wchar_t* pBuffer = new wchar_t[nSize]; - nSize = mbstowcs(pBuffer, src, nSize); - std::wstring sRes; - if (nSize != (size_t)-1) - sRes = std::wstring(pBuffer, nSize); - delete[] pBuffer; - return sRes; - } - std::string unicode_to_ascii(const wchar_t *src) - { - size_t nSize = wcstombs(0, src, 0); - char* pBuffer = new char[nSize]; - nSize = wcstombs(pBuffer, src, nSize); - std::string sRes; - if (nSize != (size_t)-1) - sRes = std::string(pBuffer, nSize); - delete[] pBuffer; - return sRes; - } - std::wstring GetTempFilename(const std::wstring& sFolder) { std::wstring sTmpFile = NSFile::CFileBinary::CreateTempFileWithUniqueName(sFolder.empty() ? NSFile::CFileBinary::GetTempPath() : sFolder, L"wmf"); diff --git a/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp b/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp index 09f8874ced..cd1518e567 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfObjects.cpp @@ -30,7 +30,6 @@ * */ #include "../../../raster/ImageFileFormatChecker.h" -#include "../../../graphics/Image.h" #include "../Common/MetaFileUtils.h" diff --git a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParser.cpp b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParser.cpp index 6f4bdc8e00..62360a3586 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParser.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParser.cpp @@ -593,6 +593,8 @@ namespace MetaFile if (!BanEMFProcesses()) HANDLE_EMR_CREATEBRUSHINDIRECT(ulBrushIndex, pBrush); + else + delete pBrush; } void CEmfParser::Read_EMR_SETTEXTCOLOR() @@ -630,6 +632,8 @@ namespace MetaFile if (!BanEMFProcesses()) HANDLE_EMR_EXTCREATEFONTINDIRECTW(ulIndex, pFont); + else + delete pFont; } void CEmfParser::Read_EMR_SETTEXTALIGN() @@ -722,6 +726,8 @@ namespace MetaFile if (!BanEMFProcesses()) HANDLE_EMR_EXTCREATEPEN(ulPenIndex, pPen, arUnused); + else + delete pPen; } void CEmfParser::Read_EMR_CREATEPEN() @@ -744,6 +750,8 @@ namespace MetaFile if (!BanEMFProcesses()) HANDLE_EMR_CREATEPEN(ulPenIndex, widthX, pPen); + else + delete pPen; } void CEmfParser::Read_EMR_SETPOLYFILLMODE() @@ -1011,6 +1019,8 @@ namespace MetaFile if (!BanEMFProcesses()) HANDLE_EMR_CREATEPALETTE(ulPaletteIndex, pPalette); + else + delete pPalette; } void CEmfParser::Read_EMR_SELECTPALETTE() diff --git a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.h b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.h index 20a460aa48..d52dfd9434 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfParserBase.h @@ -1,10 +1,6 @@ #ifndef CEMFPARSERBASE_H #define CEMFPARSERBASE_H -//#include "../EmfTypes.h" -//#include "../EmfObjects.h" -//#include "../../Common/MetaFileUtils.h" - #include "../EmfPlayer.h" #include "../../Common/MetaFile.h" diff --git a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp index 713cb4c95d..5ae466d3c1 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp +++ b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.cpp @@ -67,15 +67,11 @@ #define EMFPLUS_TRANSLATEWORLDTRANSFORM 0x402D #include -#include #include "CEmfParser.h" -#include "../../Wmf/WmfFile.h" -#include "../../Wmf/WmfInterpretator/CWmfInterpretatorSvg.h" #include "../EmfInterpretator/CEmfInterpretator.h" #include "../EmfInterpretator/CEmfInterpretatorSvg.h" -#include "../EmfInterpretator/CEmfInterpretatorArray.h" #include "../EmfInterpretator/CEmfInterpretatorRender.h" #ifdef METAFILE_SUPPORT_WMF_EMF_XML @@ -665,8 +661,8 @@ namespace MetaFile for (unsigned int unIndex = 0; unIndex < unPositionCount; ++unIndex) m_oStream >> pEmfPlusBrush->arGradientColors[unIndex].first; - pEmfPlusBrush->oColor = pEmfPlusBrush->arGradientColors[unPositionCount - 1].first; - pEmfPlusBrush->oColorBack = pEmfPlusBrush->arGradientColors[0].first; + pEmfPlusBrush->oColor = pEmfPlusBrush->arGradientColors.back() .first; + pEmfPlusBrush->oColorBack = pEmfPlusBrush->arGradientColors.front().first; } } @@ -775,7 +771,7 @@ namespace MetaFile switch (nEndCap) { - case 0: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_FLAT; break; + case 0: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_FLAT; break; case 1: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_SQUARE; break; case 2: pEmfPlusPen->unStyle |= PS_ENDCAP_MASK & PS_ENDCAP_ROUND; break; } @@ -788,7 +784,7 @@ namespace MetaFile switch (nJoin) { - case 0: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_MITER; break; + case 0: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_MITER; break; case 1: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_JOIN_BEVEL; break; case 2: pEmfPlusPen->unStyle |= PS_JOIN_MASK & PS_ENDCAP_ROUND; break; } @@ -874,7 +870,7 @@ namespace MetaFile m_oStream >> *pLineCapData; if (CustomLineCapDataFillPath == pLineCapData->unCustomLineCapDataFlags || - CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags) + CustomLineCapDataLinePath == pLineCapData->unCustomLineCapDataFlags) { m_oStream.Skip(4); // FillPathLength or LinePathLength pLineCapData->pPath = ReadPath(); @@ -1346,7 +1342,7 @@ namespace MetaFile if (oImageAttributes.eWrapMode == WrapModeClamp) { if (oRectangle.dX < 0 || oRectangle.dX < 0 || - oRectangle.dX >= oRectangle.dWidth || oRectangle.dY >= oRectangle.dHeight) + oRectangle.dX >= oRectangle.dWidth || oRectangle.dY >= oRectangle.dHeight) return oImageAttributes.oClampColor; } @@ -1544,14 +1540,10 @@ namespace MetaFile case MetafileDataTypeEmf: case MetafileDataTypeEmfPlusOnly: case MetafileDataTypeEmfPlusDual: - { return DrawMetafile(pBuffer, unSizeBuffer, oSrcRect, arPoints); - } case MetafileDataTypeWmf: case MetafileDataTypeWmfPlaceable: - { return DrawMetafile(pBuffer, unSizeBuffer, oSrcRect, arPoints); - } } } } @@ -1664,7 +1656,7 @@ namespace MetaFile BYTE* pNewBuffer = GetClipedImage(pPixels, nWidth, nHeight, oClipRect, nW, nH); m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X - m_pDC->GetPixelWidth(), arPoints[2].Y - arPoints[0].Y - m_pDC->GetPixelHeight(), - (NULL != pNewBuffer) ? pNewBuffer : pPixels, nW, nH); + (NULL != pNewBuffer) ? pNewBuffer : pPixels, nW, nH); RELEASEINTERFACE(pGrRenderer); RELEASEARRAYOBJECTS(pNewBuffer); @@ -1743,7 +1735,7 @@ namespace MetaFile BYTE* pNewBuffer = GetClipedImage(pBytes, unWidth, unHeight, oClipRect, nW, nH); m_pInterpretator->DrawBitmap(arPoints[0].X, arPoints[0].Y, arPoints[1].X - arPoints[0].X, arPoints[2].Y - arPoints[0].Y, - (NULL != pNewBuffer) ? pNewBuffer : pBytes, nW, nH); + (NULL != pNewBuffer) ? pNewBuffer : pBytes, nW, nH); if (!bExternalBuffer) RELEASEARRAYOBJECTS(pBytes); @@ -1806,17 +1798,15 @@ namespace MetaFile m_pDC->SetPen(pPen); if (AD_COUNTERCLOCKWISE != m_pDC->GetArcDirection()) - { dSweepAngle = dSweepAngle - 360; - } TEmfPlusRectF oConvertedRect = GetConvertedRectangle(oRect); MoveTo(oConvertedRect.dX, oConvertedRect.dY); ArcTo(oConvertedRect.dX, oConvertedRect.dY, - oConvertedRect.dX + oConvertedRect.dWidth, - oConvertedRect.dY + oConvertedRect.dHeight, - dStartAngle, dSweepAngle); + oConvertedRect.dX + oConvertedRect.dWidth, + oConvertedRect.dY + oConvertedRect.dHeight, + dStartAngle, dSweepAngle); DrawPath(true, false); if (NULL != m_pInterpretator) @@ -2293,13 +2283,13 @@ namespace MetaFile if (NULL != m_pInterpretator) { - CPathConverter oPathConverter; - CPath oNewPath, oLineCapPath; - - oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen); - if (InterpretatorType::Render == m_pInterpretator->GetType()) { + CPathConverter oPathConverter; + CPath oNewPath, oLineCapPath; + + oPathConverter.GetUpdatedPath(oNewPath, oLineCapPath, *pPath, *pEmfPlusPen); + oNewPath.DrawOn(m_pInterpretator, true, false); oLineCapPath.DrawOn(m_pInterpretator, false, true); } @@ -2836,7 +2826,7 @@ namespace MetaFile void CEmfPlusParser::Read_EMFPLUS_FILLREGION(unsigned short unShFlags) { - short shOgjectIndex = ExpressValue(unShFlags, 0, 7); + // short shOgjectIndex = ExpressValue(unShFlags, 0, 7); unsigned int unBrushId; m_oStream >> unBrushId; @@ -2995,34 +2985,34 @@ namespace MetaFile void CEmfPlusParser::Read_EMFPLUS_SETANTIALIASMODE(unsigned short unShFlags) { - short shSmoothingMode = ExpressValue(unShFlags, 1, 7); + // short shSmoothingMode = ExpressValue(unShFlags, 1, 7); //TODO: реализовать } void CEmfPlusParser::Read_EMFPLUS_SETCOMPOSITINGMODE(unsigned short unShFlags) { - short shCompositingMode = ExpressValue(unShFlags, 0, 7); + // short shCompositingMode = ExpressValue(unShFlags, 0, 7); //TODO: реализовать } void CEmfPlusParser::Read_EMFPLUS_SETCOMPOSITINGQUALITY(unsigned short unShFlags) { - short shCompositingQuality = ExpressValue(unShFlags, 0, 7); + // short shCompositingQuality = ExpressValue(unShFlags, 0, 7); //TODO: реализовать } void CEmfPlusParser::Read_EMFPLUS_SETINTERPOLATIONMODE(unsigned short unShFlags) { - short shInterpolationMode = ExpressValue(unShFlags, 0, 7); + // short shInterpolationMode = ExpressValue(unShFlags, 0, 7); //TODO: реализовать } void CEmfPlusParser::Read_EMFPLUS_SETPIXELOFFSETMODE(unsigned short unShFlags) { - short shPixelOffsetMode = ExpressValue(unShFlags, 0, 7); + // short shPixelOffsetMode = ExpressValue(unShFlags, 0, 7); //TODO: реализовать } @@ -3039,20 +3029,20 @@ namespace MetaFile void CEmfPlusParser::Read_EMFPLUS_SETTEXTCONTRAST(unsigned short unShFlags) { - short shTextContrast = ExpressValue(unShFlags, 0, 11); + // short shTextContrast = ExpressValue(unShFlags, 0, 11); //TODO: реализовать } void CEmfPlusParser::Read_EMRPLUS_SETTEXTRENDERINGHINT(unsigned short unShFlags) { - short shTextRenderingHint = ExpressValue(unShFlags, 0, 7); + // short shTextRenderingHint = ExpressValue(unShFlags, 0, 7); //TODO: реализовать } void CEmfPlusParser::Read_EMFPLUS_BEGINCONTAINER(unsigned short unShFlags) { - short shPageUnit = ExpressValue(unShFlags, 8, 15); + // short shPageUnit = ExpressValue(unShFlags, 8, 15); TEmfPlusRectF oDestRect, oSrcRect; unsigned int unStackIndex; diff --git a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.h b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.h index d78d497131..a1930b6e7e 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfParser/CEmfPlusParser.h @@ -1,8 +1,6 @@ #ifndef CEMFPLUSPARSER_H #define CEMFPLUSPARSER_H -//#include "../../Common/MetaFileUtils.h" -//#include "../../Common/MetaFile.h" #include "../EmfPlusObjects.h" #include "CEmfParserBase.h" #include "../EmfPlusTypes.h" diff --git a/DesktopEditor/raster/Metafile/Emf/EmfPlusTypes.h b/DesktopEditor/raster/Metafile/Emf/EmfPlusTypes.h index 0e49ce3500..421ee792b7 100644 --- a/DesktopEditor/raster/Metafile/Emf/EmfPlusTypes.h +++ b/DesktopEditor/raster/Metafile/Emf/EmfPlusTypes.h @@ -106,6 +106,16 @@ namespace MetaFile chRed = oARGB.chRed; chAlpha = oARGB.chAlpha; } + + TEmfPlusARGB& operator=(const TEmfPlusARGB& oARGB) + { + chBlue = oARGB.chBlue; + chGreen = oARGB.chGreen; + chRed = oARGB.chRed; + chAlpha = oARGB.chAlpha; + + return *this; + } }; struct TGUID diff --git a/DesktopEditor/raster/Metafile/StarView/SvmFile.cpp b/DesktopEditor/raster/Metafile/StarView/SvmFile.cpp index 1a95477427..05f1ffe372 100644 --- a/DesktopEditor/raster/Metafile/StarView/SvmFile.cpp +++ b/DesktopEditor/raster/Metafile/StarView/SvmFile.cpp @@ -266,6 +266,7 @@ void CSvmFile::Read_META_LINE() { case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break; case LINE_DASH: last_pen->PenStyle = PS_DASH ; break; + default: break; } } } @@ -323,6 +324,7 @@ void CSvmFile::Read_META_POLYLINE() { case LINE_SOLID: last_pen->PenStyle = PS_SOLID ; break; case LINE_DASH: last_pen->PenStyle = PS_DASH ; break; + default: break; } if (last_pen->Width < 1) diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp index 0201d9d9dd..c15aed926b 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfInterpretator/CWmfInterpretatorSvg.cpp @@ -153,7 +153,13 @@ namespace MetaFile const std::wstring wsText{ConvertToUnicode(pString, (long)shStringLength, (NULL != pFont) ? pFont->GetCharSet() : DEFAULT_CHARSET)}; - TPointD oScale((m_pParser->IsWindowFlippedX()) ? -1 : 1, (m_pParser->IsWindowFlippedY()) ? -1 : 1); + TPointD oScale(1, 1); + + if (NULL != m_pParser) + { + oScale.X = m_pParser->IsWindowFlippedX() ? -1 : 1; + oScale.Y = m_pParser->IsWindowFlippedY() ? -1 : 1; + } std::vector arDx(0); diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParser.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParser.cpp index 214b314d83..cada341c75 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParser.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParser.cpp @@ -298,7 +298,7 @@ namespace MetaFile m_oStream >> oBitmap; unsigned int unRecordSizeDWORD = m_unRecordSize >> 1; - unsigned int unValue = (META_STRETCHBLT >> 8) + 3; + // unsigned int unValue = (META_STRETCHBLT >> 8) + 3; if (unRecordSizeDWORD == ((META_STRETCHBLT >> 8) + 3)) { diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp index c0d82821f1..5dd8d104a7 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp +++ b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.cpp @@ -241,10 +241,10 @@ namespace MetaFile { const double dKoef = 96. / (double)m_oPlaceable.ushInch; - m_oDCRect.Left = std::round(m_oDCRect.Left * dKoef); - m_oDCRect.Top = std::round(m_oDCRect.Top * dKoef); - m_oDCRect.Right = std::round(m_oDCRect.Right * dKoef); - m_oDCRect.Bottom = std::round(m_oDCRect.Bottom * dKoef); + m_oDCRect.Left = static_cast(std::round(m_oDCRect.Left * dKoef)); + m_oDCRect.Top = static_cast(std::round(m_oDCRect.Top * dKoef)); + m_oDCRect.Right = static_cast(std::round(m_oDCRect.Right * dKoef)); + m_oDCRect.Bottom = static_cast(std::round(m_oDCRect.Bottom * dKoef)); } // Иногда m_oPlaceable.BoundingBox задается нулевой ширины и высоты @@ -292,6 +292,16 @@ namespace MetaFile m_pDC->SetCurPos(shX, shY); } + void CWmfParserBase::MoveToD(double dX, double dY) + { + if (NULL != m_pInterpretator) + m_pInterpretator->MoveTo(dX, dY); + else + RegisterPoint(static_cast(dX), static_cast(dY)); + + m_pDC->SetCurPos(static_cast(dX), static_cast(dY)); + } + void CWmfParserBase::LineTo(short shX, short shY) { if (NULL != m_pInterpretator) @@ -396,7 +406,7 @@ namespace MetaFile NSFonts::IFontManager* pFontManager = GetFontManager(); if (pFontManager) { - int lLogicalFontHeight = pFont->GetHeight(); + int lLogicalFontHeight = static_cast(pFont->GetHeight()); if (lLogicalFontHeight < 0) lLogicalFontHeight = -lLogicalFontHeight; if (lLogicalFontHeight < 0.01) @@ -444,8 +454,8 @@ namespace MetaFile { pFontManager->LoadString1(wsText, 0, 0); TBBox oBox = pFontManager->MeasureString2(); - fL = (float)(oBox.fMinX); - fW = (float)(oBox.fMaxX - oBox.fMinX); + fL = static_cast(oBox.fMinX); + fW = static_cast(oBox.fMaxX - oBox.fMinX); } pFontManager->LoadString1(wsText, 0, 0); @@ -520,7 +530,7 @@ namespace MetaFile } else { - int lLogicalFontHeight = pFont->GetHeight(); + int lLogicalFontHeight = static_cast(pFont->GetHeight()); if (lLogicalFontHeight < 0) lLogicalFontHeight = -lLogicalFontHeight; if (lLogicalFontHeight < 0.01) @@ -548,7 +558,7 @@ namespace MetaFile fW = (float)(dFontHeight * wsText.length()); } - fH = dFontHeight * 1.2; + fH = (float)dFontHeight * 1.2f; double dTheta = -((((double)pFont->GetEscapement()) / 10) * 3.14159265358979323846 / 180); double dCosTheta = (float)cos(dTheta); @@ -724,17 +734,17 @@ namespace MetaFile oNewRect.Top < 0 || oNewRect.Bottom < 0) return NULL; - if (unHeight < (oNewRect.Bottom - oNewRect.Top)) - oNewRect.Bottom = oNewRect.Top + unWidth; + if (unHeight < static_cast(std::abs(oNewRect.Bottom - oNewRect.Top))) + oNewRect.Bottom = oNewRect.Top + unHeight; - if (unWidth < (oNewRect.Right - oNewRect.Left)) + if (unWidth < static_cast(std::abs(oNewRect.Right - oNewRect.Left))) oNewRect.Right = oNewRect.Left + unWidth; if (unHeight == (oNewRect.Bottom - oNewRect.Top) && unWidth == (oNewRect.Right - oNewRect.Left)) return NULL; - int nBeginX, nBeginY, nEndX, nEndY; + ULONG nBeginX, nBeginY, nEndX, nEndY; nBeginX = (std::min)(oNewRect.Left, oNewRect.Right); nBeginY = (std::min)(oNewRect.Top, oNewRect.Bottom); @@ -924,7 +934,7 @@ namespace MetaFile double dSweepAngle = GetSweepAngle(dStartAngle, dEndAngle); - MoveTo(dX1, dY1); + MoveToD(dX1, dY1); ArcTo(shLeft, shTop, shRight, shBottom, dStartAngle, dSweepAngle); DrawPath(true, false); } diff --git a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.h b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.h index 5716462b35..b1d7f8f58b 100644 --- a/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.h +++ b/DesktopEditor/raster/Metafile/Wmf/WmfParser/CWmfParserBase.h @@ -188,6 +188,7 @@ namespace MetaFile inline double GetSweepAngle(const double& dStartAngle, const double& dEndAngle) const; void MoveTo(short shX, short shY); + void MoveToD(double dX, double dY); void LineTo(short shX, short shY); void ArcTo(short shL, short shT, short shR, short shB, double dStart, double dSweep); void ClosePath();