Refactoring

This commit is contained in:
Green
2025-02-06 16:27:14 +03:00
parent 2a0c84513b
commit 612142f0ae
14 changed files with 108 additions and 86 deletions

View File

@ -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)

View File

@ -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

View File

@ -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");

View File

@ -30,7 +30,6 @@
*
*/
#include "../../../raster/ImageFileFormatChecker.h"
#include "../../../graphics/Image.h"
#include "../Common/MetaFileUtils.h"

View File

@ -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()

View File

@ -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"

View File

@ -67,15 +67,11 @@
#define EMFPLUS_TRANSLATEWORLDTRANSFORM 0x402D
#include <map>
#include <iostream>
#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<CEmfParser>(pBuffer, unSizeBuffer, oSrcRect, arPoints);
}
case MetafileDataTypeWmf:
case MetafileDataTypeWmfPlaceable:
{
return DrawMetafile<CWmfParser>(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;

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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<double> arDx(0);

View File

@ -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))
{

View File

@ -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<int>(std::round(m_oDCRect.Left * dKoef));
m_oDCRect.Top = static_cast<int>(std::round(m_oDCRect.Top * dKoef));
m_oDCRect.Right = static_cast<int>(std::round(m_oDCRect.Right * dKoef));
m_oDCRect.Bottom = static_cast<int>(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<short>(dX), static_cast<short>(dY));
m_pDC->SetCurPos(static_cast<short>(dX), static_cast<short>(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<int>(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<float>(oBox.fMinX);
fW = static_cast<float>(oBox.fMaxX - oBox.fMinX);
}
pFontManager->LoadString1(wsText, 0, 0);
@ -520,7 +530,7 @@ namespace MetaFile
}
else
{
int lLogicalFontHeight = pFont->GetHeight();
int lLogicalFontHeight = static_cast<int>(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<unsigned int>(std::abs(oNewRect.Bottom - oNewRect.Top)))
oNewRect.Bottom = oNewRect.Top + unHeight;
if (unWidth < (oNewRect.Right - oNewRect.Left))
if (unWidth < static_cast<unsigned int>(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);
}

View File

@ -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();