Commit 2bb19410 authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander Trofimov

Переделано открытие EMF на манер WMF, т.е. теперь первоначальный обсчет всех...

Переделано открытие EMF на манер WMF, т.е. теперь первоначальный обсчет всех точек делается в классе CEmfFile, чтобы не было проблем с клипом как в WMF. Реализованы записи ExcludeClipRect и SetArcDirection. Исправлены мелкие баги при открытии EMF.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62391 954022d7-b5bf-4e40-9824-e11837661b57
parent 0ddbb6af
......@@ -26,8 +26,6 @@ namespace MetaFile
virtual void PlayMetaFile() = 0;
virtual void ClearFile() {/* , */}
//virtual double TranslateX(int nX) = 0;
//virtual double TranslateY(int nY) = 0;
virtual TRect* GetDCBounds() = 0;
virtual double GetPixelHeight() = 0;
virtual double GetPixelWidth() = 0;
......
......@@ -608,7 +608,7 @@ namespace MetaFile
BYTE nDashStyle = Aggplus::DashStyleSolid;;
// WinGDI 1px PS_SOLID
if (1 == pPen->GetWidth() && PS_SOLID != ulPenStyle)
if (1 >= pPen->GetWidth() && PS_SOLID != ulPenStyle)
{
dWidth = 0; // 1p
......
......@@ -121,6 +121,9 @@ typedef unsigned char BYTE;
#define PS_GEOMETRIC 0x00010000
#define PS_TYPE_MASK 0x000F0000
#define AD_COUNTERCLOCKWISE 1
#define AD_CLOCKWISE 2
/* Text Alignment Options */
#define TA_NOUPDATECP 0
#define TA_UPDATECP 1
......
......@@ -864,8 +864,7 @@ namespace MetaFile
{
unsigned int unIndex = (unY * unWidth + unX) * 4;
if ((0xff == pCur[unIndex + 0] && 0xff == pCur[unIndex + 1] && 0xff == pCur[unIndex + 2]) ||
(0x00 == pCur[unIndex + 0] && 0x00 == pCur[unIndex + 1] && 0x00 == pCur[unIndex + 2]))
if (0xff == pCur[unIndex + 0] && 0xff == pCur[unIndex + 1] && 0xff == pCur[unIndex + 2])
pCur[unIndex + 3] = 0;
}
}
......@@ -879,8 +878,7 @@ namespace MetaFile
{
unsigned int unIndex = (unY * unWidth + unX) * 4;
if ((0xff == pCur[unIndex + 0] && 0xff == pCur[unIndex + 1] && 0xff == pCur[unIndex + 2]) ||
(0x00 == pCur[unIndex + 0] && 0x00 == pCur[unIndex + 1] && 0x00 == pCur[unIndex + 2]))
if (0 == pCur[unIndex + 0] && 0 == pCur[unIndex + 1] && 0 == pCur[unIndex + 2])
pCur[unIndex + 3] = 0;
}
}
......
......@@ -535,13 +535,11 @@ namespace MetaFile
unsigned short* pUnicode = NULL;
if (oText.fuOptions & ETO_SMALL_CHARS)
{
unsigned char* pString = new unsigned char[oText.cChars + 1];
unsigned char* pString = new unsigned char[oText.cChars];
if (!pString)
return *this;
pString[oText.cChars] = 0x00;
ReadBytes(pString, oText.cChars);
oText.cChars++;
pUnicode = new unsigned short[oText.cChars];
if (!pUnicode)
......@@ -558,13 +556,11 @@ namespace MetaFile
}
else
{
pUnicode = new unsigned short[oText.cChars + 1];
pUnicode = new unsigned short[oText.cChars];
if (!pUnicode)
return *this;
pUnicode[oText.cChars] = 0x0000;
ReadBytes(pUnicode, oText.cChars);
oText.cChars++;
}
oText.TextString = pUnicode;
}
......@@ -920,7 +916,6 @@ namespace MetaFile
void ReadEmrTextA(TEmfEmrText& oText, unsigned int unOffset)
{
ReadEmrTextBase<unsigned char>(oText, unOffset);
// TODO: Charset
}
void ReadEmrTextW(TEmfEmrText& oText, unsigned int unOffset)
{
......
......@@ -30,6 +30,12 @@ namespace MetaFile
pNewCommand = new CEmfClipCommandPath(&pPathCommand->m_oPath, pPathCommand->m_unMode);
break;
}
case EMF_CLIPCOMMAND_EXCLUDE:
{
CEmfClipCommandExclude* pExclude = (CEmfClipCommandExclude*)pCommand;
pNewCommand = new CEmfClipCommandExclude(pExclude->m_oClip, pExclude->m_oBB);
break;
}
}
if (pNewCommand)
......@@ -40,7 +46,7 @@ namespace MetaFile
{
Clear();
}
bool CEmfClip::Intersect(TEmfRectL& oRect)
bool CEmfClip::Intersect(TRectD& oRect)
{
CEmfClipCommandBase* pCommand = new CEmfClipCommandIntersect(oRect);
if (!pCommand)
......@@ -49,6 +55,15 @@ namespace MetaFile
m_vCommands.push_back(pCommand);
return true;
}
bool CEmfClip::Exclude(TRectD& oClip, TRectD& oBB)
{
CEmfClipCommandBase* pCommand = new CEmfClipCommandExclude(oClip, oBB);
if (!pCommand)
return false;
m_vCommands.push_back(pCommand);
return true;
}
bool CEmfClip::SetPath(CEmfPath* pPath, unsigned int unMode)
{
CEmfClipCommandBase* pCommand = new CEmfClipCommandPath(pPath, unMode);
......@@ -72,7 +87,7 @@ namespace MetaFile
case EMF_CLIPCOMMAND_INTERSECT:
{
CEmfClipCommandIntersect* pIntersect = (CEmfClipCommandIntersect*)pCommand;
pOutput->IntersectClip(pIntersect->m_oRect.lLeft, pIntersect->m_oRect.lTop, pIntersect->m_oRect.lRight, pIntersect->m_oRect.lBottom);
pOutput->IntersectClip(pIntersect->m_oRect.dLeft, pIntersect->m_oRect.dTop, pIntersect->m_oRect.dRight, pIntersect->m_oRect.dBottom);
break;
}
case EMF_CLIPCOMMAND_SETPATH:
......@@ -81,6 +96,30 @@ namespace MetaFile
pClipPath->m_oPath.Draw(pOutput, false, false, pClipPath->m_unMode);
break;
}
case EMF_CLIPCOMMAND_EXCLUDE:
{
CEmfClipCommandExclude* pExclude = (CEmfClipCommandExclude*)pCommand;
pOutput->StartClipPath(RGN_AND, ALTERNATE);
TRectD& oClip = pExclude->m_oClip;
TRectD& oBB = pExclude->m_oBB;
pOutput->MoveTo(oClip.dLeft, oClip.dTop);
pOutput->LineTo(oClip.dRight, oClip.dTop);
pOutput->LineTo(oClip.dRight, oClip.dBottom);
pOutput->LineTo(oClip.dLeft, oClip.dBottom);
pOutput->ClosePath();
pOutput->MoveTo(oBB.dLeft, oBB.dTop);
pOutput->LineTo(oBB.dRight, oBB.dTop);
pOutput->LineTo(oBB.dRight, oBB.dBottom);
pOutput->LineTo(oBB.dLeft, oBB.dBottom);
pOutput->ClosePath();
pOutput->EndClipPath(RGN_AND);
break;
}
}
}
......
......@@ -12,7 +12,8 @@ namespace MetaFile
{
EMF_CLIPCOMMAND_UNKNOWN = 0x00,
EMF_CLIPCOMMAND_INTERSECT = 0x01,
EMF_CLIPCOMMAND_SETPATH = 0x02
EMF_CLIPCOMMAND_SETPATH = 0x02,
EMF_CLIPCOMMAND_EXCLUDE = 0x03
} EEmfClipCommandType;
class CEmfClipCommandBase
......@@ -32,7 +33,7 @@ namespace MetaFile
class CEmfClipCommandIntersect : public CEmfClipCommandBase
{
public:
CEmfClipCommandIntersect(TEmfRectL& oRect) : m_oRect(oRect)
CEmfClipCommandIntersect(TRectD& oRect) : m_oRect(oRect)
{
}
~CEmfClipCommandIntersect()
......@@ -44,7 +45,7 @@ namespace MetaFile
}
public:
TEmfRectL m_oRect;
TRectD m_oRect;
};
class CEmfClipCommandPath : public CEmfClipCommandBase
{
......@@ -65,6 +66,24 @@ namespace MetaFile
CEmfPath m_oPath;
unsigned int m_unMode;
};
class CEmfClipCommandExclude : public CEmfClipCommandBase
{
public:
CEmfClipCommandExclude(TRectD& oClip, TRectD& oBB) : m_oClip(oClip), m_oBB(oBB)
{
}
~CEmfClipCommandExclude()
{
}
EEmfClipCommandType GetType()
{
return EMF_CLIPCOMMAND_INTERSECT;
}
public:
TRectD m_oClip;
TRectD m_oBB;
};
class CEmfClip : public IClip
{
......@@ -74,7 +93,8 @@ namespace MetaFile
void operator=(CEmfClip& oClip);
void Reset();
bool Intersect(TEmfRectL& oRect);
bool Intersect(TRectD& oRect);
bool Exclude(TRectD& oClip, TRectD& oBB);
bool SetPath(CEmfPath* pPath, unsigned int umMode);
void ClipOnRenderer(IOutputDevice* pOutput);
......
This diff is collapsed.
......@@ -50,90 +50,30 @@ namespace MetaFile
CEmfPath::~CEmfPath()
{
Clear();
}
bool CEmfPath::MoveTo(TEmfPointS& oPoint)
{
CEmfPathCommandBase* pCommand = new CEmfPathMoveTo(oPoint);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::MoveTo(TEmfPointL& oPoint)
{
CEmfPathCommandBase* pCommand = new CEmfPathMoveTo(oPoint);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::MoveTo(int lX, int lY)
}
bool CEmfPath::MoveTo(double dX, double dY)
{
CEmfPathCommandBase* pCommand = new CEmfPathMoveTo(lX, lY);
CEmfPathCommandBase* pCommand = new CEmfPathMoveTo(dX, dY);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::LineTo(TEmfPointS& oPoint)
{
CEmfPathCommandBase* pCommand = new CEmfPathLineTo(oPoint);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::LineTo(TEmfPointL& oPoint)
}
bool CEmfPath::LineTo(double dX, double dY)
{
CEmfPathCommandBase* pCommand = new CEmfPathLineTo(oPoint);
CEmfPathCommandBase* pCommand = new CEmfPathLineTo(dX, dY);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::LineTo(int lX, int lY)
{
CEmfPathCommandBase* pCommand = new CEmfPathLineTo(lX, lY);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::CurveTo(TEmfPointS& oPoint1, TEmfPointS& oPoint2, TEmfPointS& oPointE)
{
CEmfPathCommandBase* pCommand = new CEmfPathCurveTo(oPoint1, oPoint2, oPointE);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::CurveTo(TEmfPointL& oPoint1, TEmfPointL& oPoint2, TEmfPointL& oPointE)
{
CEmfPathCommandBase* pCommand = new CEmfPathCurveTo(oPoint1, oPoint2, oPointE);
if (!pCommand)
return false;
m_pCommands.push_back(pCommand);
return true;
}
bool CEmfPath::CurveTo(int lX1, int lY1, int lX2, int lY2, int lXE, int lYE)
}
bool CEmfPath::CurveTo(double dX1, double dY1, double dX2, double dY2, double dXE, double dYE)
{
CEmfPathCommandBase* pCommand = new CEmfPathCurveTo(lX1, lY1, lX2, lY2, lXE, lYE);
CEmfPathCommandBase* pCommand = new CEmfPathCurveTo(dX1, dY1, dX2, dY2, dXE, dYE);
if (!pCommand)
return false;
......@@ -141,9 +81,9 @@ namespace MetaFile
return true;
}
bool CEmfPath::ArcTo(int lL, int lT, int lR, int lB, double dStart, double dSweep)
bool CEmfPath::ArcTo(double dL, double dT, double dR, double dB, double dStart, double dSweep)
{
CEmfPathCommandBase* pCommand = new CEmfPathArcTo(lL, lT, lR, lB, dStart, dSweep);
CEmfPathCommandBase* pCommand = new CEmfPathArcTo(dL, dT, dR, dB, dStart, dSweep);
if (!pCommand)
return false;
......
......@@ -32,20 +32,10 @@ namespace MetaFile
class CEmfPathMoveTo : public CEmfPathCommandBase
{
public:
CEmfPathMoveTo(TEmfPointL& oPoint)
CEmfPathMoveTo(double dX, double dY)
{
x = oPoint.x;
y = oPoint.y;
}
CEmfPathMoveTo(TEmfPointS& oPoint)
{
x = oPoint.x;
y = oPoint.y;
}
CEmfPathMoveTo(int lX, int lY)
{
x = lX;
y = lY;
x = dX;
y = dY;
}
virtual ~CEmfPathMoveTo()
{
......@@ -57,26 +47,16 @@ namespace MetaFile
public:
int x;
int y;
double x;
double y;
};
class CEmfPathLineTo : public CEmfPathCommandBase
{
public:
CEmfPathLineTo(TEmfPointL& oPoint)
{
x = oPoint.x;
y = oPoint.y;
}
CEmfPathLineTo(TEmfPointS& oPoint)
CEmfPathLineTo(double dX, double dY)
{
x = oPoint.x;
y = oPoint.y;
}
CEmfPathLineTo(int lX, int lY)
{
x = lX;
y = lY;
x = dX;
y = dY;
}
virtual ~CEmfPathLineTo()
{
......@@ -88,38 +68,20 @@ namespace MetaFile
public:
int x;
int y;
double x;
double y;
};
class CEmfPathCurveTo : public CEmfPathCommandBase
{
public:
CEmfPathCurveTo(TEmfPointL& oPoint1, TEmfPointL& oPoint2, TEmfPointL& oPointE)
{
x1 = oPoint1.x;
y1 = oPoint1.y;
x2 = oPoint2.x;
y2 = oPoint2.y;
xE = oPointE.x;
yE = oPointE.y;
}
CEmfPathCurveTo(TEmfPointS& oPoint1, TEmfPointS& oPoint2, TEmfPointS& oPointE)
{
x1 = oPoint1.x;
y1 = oPoint1.y;
x2 = oPoint2.x;
y2 = oPoint2.y;
xE = oPointE.x;
yE = oPointE.y;
}
CEmfPathCurveTo(int lX1, int lY1, int lX2, int lY2, int lXE, int lYE)
CEmfPathCurveTo(double dX1, double dY1, double dX2, double dY2, double dXE, double dYE)
{
x1 = lX1;
y1 = lY1;
x2 = lX2;
y2 = lY2;
xE = lXE;
yE = lYE;
x1 = dX1;
y1 = dY1;
x2 = dX2;
y2 = dY2;
xE = dXE;
yE = dYE;
}
virtual ~CEmfPathCurveTo()
{
......@@ -131,22 +93,22 @@ namespace MetaFile
public:
int x1;
int y1;
int x2;
int y2;
int xE;
int yE;
double x1;
double y1;
double x2;
double y2;
double xE;
double yE;
};
class CEmfPathArcTo : public CEmfPathCommandBase
{
public:
CEmfPathArcTo(int lL, int lT, int lR, int lB, double dStart, double dSweep)
CEmfPathArcTo(double dL, double dT, double dR, double dB, double dStart, double dSweep)
{
left = lL;
top = lT;
right = lR;
bottom = lB;
left = dL;
top = dT;
right = dR;
bottom = dB;
start = dStart;
sweep = dSweep;
}
......@@ -160,10 +122,10 @@ namespace MetaFile
public:
int left;
int top;
int right;
int bottom;
double left;
double top;
double right;
double bottom;
double start;
double sweep;
};
......@@ -192,16 +154,10 @@ namespace MetaFile
CEmfPath(CEmfPath* pPath);
~CEmfPath();
bool MoveTo(TEmfPointS& oPoint);
bool MoveTo(TEmfPointL& oPoint);
bool MoveTo(int lX, int lY);
bool LineTo(TEmfPointS& oPoint);
bool LineTo(TEmfPointL& oPoint);
bool LineTo(int lX, int lY);
bool CurveTo(TEmfPointS& oPoint1, TEmfPointS& oPoint2, TEmfPointS& oPointE);
bool CurveTo(TEmfPointL& oPoint1, TEmfPointL& oPoint2, TEmfPointL& oPointE);
bool CurveTo(int lX1, int lY1, int lX2, int lY2, int lXE, int lYE);
bool ArcTo(int lL, int lT, int lR, int lB, double dStart, double dSweep);
bool MoveTo(double dX, double dY);
bool LineTo(double dX, double dY);
bool CurveTo(double dX1, double dY1, double dX2, double dY2, double dXE, double dYE);
bool ArcTo(double dL, double dT, double dR, double dB, double dStart, double dSweep);
bool Close();
void Draw(IOutputDevice* pOutput, bool bStroke, bool bFill, unsigned int unClipMode = -1);
......
......@@ -54,7 +54,7 @@ namespace MetaFile
CEmfDC* Copy();
void SetMapMode(unsigned int ulMapMode);
unsigned int GetMapMode();
unsigned int GetMapMode();
TEmfXForm* GetTransform();
TEmfXForm* GetInverseTransform();
void MultiplyTransform(TEmfXForm& oForm, unsigned int ulMode);
......@@ -67,20 +67,20 @@ namespace MetaFile
void RemoveFont(CEmfLogFont* pFont);
CEmfLogFont* GetFont();
void SetTextAlign(unsigned int ulAlign);
unsigned int GetTextAlign();
unsigned int GetTextAlign();
void SetBgMode(unsigned int ulBgMode);
unsigned int GetBgMode();
unsigned int GetBgMode();
void SetBgColor(TEmfColor& oColor);
TEmfColor& GetBgColor();
void SetMiterLimit(unsigned int ulMiter);
unsigned int GetMiterLimit();
unsigned int GetMiterLimit();
void SetFillMode(unsigned int ulFillMode);
unsigned int GetFillMode();
unsigned int GetFillMode();
void SetPen(CEmfLogPen* pPen);
void RemovePen(CEmfLogPen* pPen);
CEmfLogPen* GetPen();
void SetStretchMode(unsigned int& oMode);
unsigned int GetStretchMode();
unsigned int GetStretchMode();
double GetPixelWidth();
double GetPixelHeight();
void SetWindowOrigin(TEmfPointL& oPoint);
......@@ -90,7 +90,7 @@ namespace MetaFile
void SetViewportExtents(TEmfSizeL& oPoint);
TEmfWindow* GetViewport();
void SetRop2Mode(unsigned int& nMode);
unsigned int GetRop2Mode();
unsigned int GetRop2Mode();
void SetPalette(CEmfLogPalette* pPalette);
void RemovePalette(CEmfLogPalette* pPalette);
CEmfLogPalette* GetPalette();
......@@ -99,6 +99,8 @@ namespace MetaFile
TEmfPointL& GetCurPos();
CEmfClip* GetClip();
void ClipToPath(CEmfPath* pPath, unsigned int unMode);
void SetArcDirection(unsigned int unDirection);
unsigned int GetArcDirection();
private:
......@@ -108,8 +110,6 @@ namespace MetaFile
private:
CEmfLogPen m_oDefaultPen;
CEmfLogBrushEx m_oDefaultBrush;
unsigned int m_ulMapMode;
CEmfLogBrushEx* m_pBrush;
CEmfLogPen* m_pPen;
......@@ -131,6 +131,7 @@ namespace MetaFile
TEmfWindow m_oViewport;
TEmfPointL m_oCurPos;
CEmfClip m_oClip;
unsigned int m_unArcDirection;
};
}
......
......@@ -675,11 +675,10 @@ namespace MetaFile
if (!(fuOptions & ETO_NO_RECT))
unSize += 16;
// .
if (fuOptions & ETO_SMALL_CHARS)
unSize += (cChars - 1);
unSize += cChars;
else
unSize += 2 * (cChars - 1);
unSize += 2 * cChars;
return unSize;
}
......
......@@ -160,7 +160,7 @@ namespace MetaFile
if (!pBgraData)
return;
memset(pBgraData, 0x00, nWidth * nHeight * 4);
memset(pBgraData, 0xff, nWidth * nHeight * 4);
CBgraFrame oFrame;
oFrame.put_Data(pBgraData);
oFrame.put_Width(nWidth);
......
......@@ -42,11 +42,11 @@ void ConvertFile(CMetaFile &oMetaFile, std::wstring wsFilePath)
oMetaFile.ConvertToRaster(wsDstFilePath.c_str(), 4, 1000);
}
}
void ConvertFolder(CMetaFile &oMetaFile, std::wstring wsFolderPath)
void ConvertFolder(CMetaFile &oMetaFile, std::wstring wsFolderPath, const int nType)
{
oMetaFile.Close();
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"wmf");
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, nType == c_lMetaEmf ? L"emf" : L"wmf");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{
std::wstring wsFilePath = wsFolderPath;
......@@ -62,20 +62,14 @@ void ConvertFolder(CMetaFile &oMetaFile, std::wstring wsFolderPath)
}
}
#include "../../common/String.h"
void Test()
void main()
{
CApplicationFonts oFonts;
oFonts.Initialize();
CMetaFile oMetaFile(&oFonts);
//ConvertFile(oMetaFile, L"D://Test Files//fulltest.wmf");
ConvertFolder(oMetaFile, L"D://Test Files//Bugs//ALL//");
}
ConvertFolder(oMetaFile, L"D://Test Files//", c_lMetaEmf);
void main()
{
Test();
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
//_CrtDumpMemoryLeaks();
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment