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

Рендеринг Emf переделан на общий класс IOutputDevice, сам класс CEmfFile...

Рендеринг Emf переделан на общий класс IOutputDevice, сам класс CEmfFile теперь наследуется от базового CMetaFileBase, в который перенесены основные функции. Все это сделано, чтобы переделать Wmf на такую же схему, чтобы у обоих форматов использовался общий рендерер. В самом Wmf добавлены классы для новой реализации формата по вышеописанной схеме.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62334 954022d7-b5bf-4e40-9824-e11837661b57
parent a915c61b
......@@ -59,7 +59,7 @@ namespace NSFile
wchar_t* pUnicode = new wchar_t[lCount + 1];
for (LONG i = 0; i < lCount; ++i)
pUnicode[i] = (wchar_t)pData[i];
pUnicode[i] = (wchar_t)(BYTE)pData[i];
pUnicode[lCount] = 0;
......@@ -475,7 +475,7 @@ namespace NSFile
{
GetUtf16StringFromUnicode_4bytes(pUnicodes, lCount, data.Data, data.Length);
}
static std::wstring GetWStringFromUTF16(const CStringUtf16& data)
{
if (0 == data.Length)
......@@ -513,6 +513,15 @@ namespace NSFile
RELEASEARRAYOBJECTS(pWChar);
return sRet;
}
static std::wstring GetWStringFromUTF16(const unsigned short* pUtf16, LONG lCount)
{
CStringUtf16 oString;
oString.Data = (BYTE*)pUtf16;
oString.Length = lCount * 2;
std::wstring wsResult = GetWStringFromUTF16(oString);
oString.Data = NULL;
return wsResult;
}
};
class CFileBinary
......
......@@ -292,7 +292,7 @@ namespace MetaFile
*this >> oFont.Weight;
*this >> oFont.Italic;
*this >> oFont.Underline;
*this >> oFont.StrikOut;
*this >> oFont.StrikeOut;
*this >> oFont.CharSet;
*this >> oFont.OutPrecision;
*this >> oFont.ClipPrecision;
......
#ifndef _INTERFACE_OUTPUT_DEVICE_H
#define _INTERFACE_OUTPUT_DEVICE_H
#ifndef _METAFILE_COMMON_IOUTPUTDEVICE_H
#define _METAFILE_COMMON_IOUTPUTDEVICE_H
#include "../Wmf/WmfTypes.h"
......@@ -19,7 +19,7 @@ namespace MetaFile
// pBuffer - BGRA ulWidth, ulHeight,
virtual void DrawBitmap(int nX, int nY, int nW, int nH, BYTE* pBuffer, unsigned int unWidth, unsigned int unHeight) = 0;
virtual void DrawText(const wchar_t* wsText, unsigned int unCharsCount, int nX, int nY, int nTextW, bool bWithOutLast) = 0;
virtual void DrawText(std::wstring& wsText, unsigned int unCharsCount, int nX, int nY, int nTextW, bool bWithOutLast) = 0;
virtual void StartPath() = 0;
virtual void MoveTo(int nX, int nY) = 0;
......@@ -40,4 +40,4 @@ namespace MetaFile
}
#endif //_INTERFACE_OUTPUT_DEVICE_H
\ No newline at end of file
#endif //_METAFILE_COMMON_IOUTPUTDEVICE_H
\ No newline at end of file
......@@ -8,53 +8,111 @@
namespace MetaFile
{
class CMetaFileBase
class IMetaFileBase
{
public:
CMetaFileBase(){}
virtual ~CMetaFileBase(){}
IMetaFileBase()
{
m_pBufferData = NULL;
m_bError = false;
m_pOutput = NULL;
m_oStream.SetStream(NULL, 0);
}
virtual ~IMetaFileBase()
{
this->Close();
}
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;
virtual int GetTextColor() = 0;
virtual CFont* GetFont() = 0;
virtual CBrush* GetBrush() = 0;
virtual CPen* GetPen() = 0;
virtual IFont* GetFont() = 0;
virtual IBrush* GetBrush() = 0;
virtual IPen* GetPen() = 0;
virtual unsigned int GetTextAlign() = 0;
virtual unsigned int GetTextBgMode() = 0;
virtual int GetTextBgColor() = 0;
virtual unsigned int GetFillMode() = 0;
virtual TPointL GetCurPos() = 0;
virtual TEmfXForm* GetInverseTransform() = 0;
virtual TEmfXForm* GetTransform() = 0;
virtual TXForm* GetInverseTransform() = 0;
virtual TXForm* GetTransform() = 0;
virtual unsigned int GetMiterLimit() = 0;
virtual unsigned int GetRop2Mode() = 0;
virtual CClip* GetClip() = 0;
virtual IClip* GetClip() = 0;
bool OpenFromFile(const wchar_t* wsFilePath)
{
this->Close();
NSFile::CFileBinary oFile;
oFile.OpenFile(wsFilePath);
int lFileSize = oFile.GetFileSize();
m_pBufferData = new BYTE[lFileSize];
if (!m_pBufferData)
return false;
DWORD lReadedSize;
oFile.ReadFile(m_pBufferData, lFileSize, lReadedSize);
m_oStream.SetStream(m_pBufferData, lFileSize);
return true;
}
void Close()
{
RELEASEARRAYOBJECTS(m_pBufferData);
m_pOutput = NULL;
m_oStream.SetStream(NULL, 0);
m_bError = false;
this->ClearFile();
}
void Scan()
{
IOutputDevice* pOutput = m_pOutput;
m_pOutput = NULL;
PlayMetaFile();
m_pOutput = pOutput;
ClearFile();
}
CFontManager* GetFontManager()
{
return m_pFontManager;
}
void SetFontManager(CFontManager* pFontManager)
void SetFontManager(CFontManager* pFontManager)
{
m_pFontManager = pFontManager;
}
void SetError()
void SetOutputDevice(IOutputDevice* pOutput)
{
m_pOutput = pOutput;
}
void SetError()
{
m_bError = true;
}
bool CheckError()
bool CheckError()
{
return m_bError;
}
protected:
CDataStream m_oStream;
IOutputDevice* m_pOutput;
private:
CFontManager* m_pFontManager;
bool m_bError;
BYTE* m_pBufferData;
CFontManager* m_pFontManager;
bool m_bError;
};
}
......
......@@ -5,11 +5,11 @@
namespace MetaFile
{
class CClip
class IClip
{
public:
CClip(){}
virtual ~CClip(){}
IClip(){}
virtual ~IClip(){}
virtual void ClipOnRenderer(IOutputDevice* pOutput) = 0;
};
}
......
#ifndef _METAFILE_OBJECTS_H
#define _METAFILE_OBJECTS_H
#ifndef _METAFILE_COMMON_METAFILEOBJECTS_H
#define _METAFILE_COMMON_METAFILEOBJECTS_H
namespace MetaFile
{
class CFont
class IFont
{
public:
CFont(){}
virtual ~CFont(){}
IFont(){}
virtual ~IFont(){}
virtual int GetHeight() = 0;
virtual std::wstring GetFaceName() = 0;
......@@ -18,11 +18,11 @@ namespace MetaFile
virtual int GetEscapement() = 0;
};
class CBrush
class IBrush
{
public:
CBrush(){}
virtual ~CBrush(){}
IBrush(){}
virtual ~IBrush(){}
virtual int GetColor() = 0;
virtual unsigned int GetStyle() = 0;
......@@ -31,11 +31,11 @@ namespace MetaFile
virtual std::wstring GetDibPatterPath() = 0;
};
class CPen
class IPen
{
public:
CPen(){}
virtual ~CPen(){}
IPen(){}
virtual ~IPen(){}
virtual int GetColor() = 0;
virtual unsigned int GetStyle() = 0;
......@@ -43,4 +43,4 @@ namespace MetaFile
};
}
#endif //_METAFILE_OBJECTS_H
\ No newline at end of file
#endif //_METAFILE_COMMON_METAFILEOBJECTS_H
\ No newline at end of file
#include "MetaFilePlayer.h"
namespace MetaFile
{
template<typename CMetaFileDC> CMetaFilePlayer<CMetaFileDC>::CMetaFilePlayer(CMetaFileBase* pFile) : m_pFile(pFile)
{
CMetaFileDC* pDC = new CMetaFileDC();
if (!pDC)
{
pFile->SetError();
return;
}
m_pDC = pDC;
m_vDCStack.push_back(pDC);
InitStockObjects();
};
template<typename CMetaFileDC> CMetaFilePlayer<CMetaFileDC>::~CMetaFilePlayer()
{
for (int nIndex = 0; nIndex < m_vDCStack.size(); nIndex++)
{
CMetaFileDC* pDC = m_vDCStack.at(nIndex);
delete pDC;
}
m_vDCStack.clear();
for (CMetaFileObjectMap::iterator oIterator = m_mObjects.begin(); oIterator != m_mObjects.end(); oIterator++)
{
CMetaFileObjectBase* pOldObject = oIterator->second;
delete pOldObject;
}
m_mObjects.clear();
}
template<typename CMetaFileDC> void CMetaFilePlayer<CMetaFileDC>::Clear()
{
for (int nIndex = 0; nIndex < m_vDCStack.size(); nIndex++)
{
CMetaFileDC* pDC = m_vDCStack.at(nIndex);
delete pDC;
}
m_vDCStack.clear();
for (CMetaFileObjectMap::iterator oIterator = m_mObjects.begin(); oIterator != m_mObjects.end(); oIterator++)
{
CMetaFileObjectBase* pOldObject = oIterator->second;
delete pOldObject;
}
m_mObjects.clear();
CMetaFileDC* pDC = new CMetaFileDC();
if (!pDC)
{
m_pFile->SetError();
return;
}
m_pDC = pDC;
m_vDCStack.push_back(pDC);
InitStockObjects();
}
template<typename CMetaFileDC> CMetaFileDC* CMetaFilePlayer<CMetaFileDC>::SaveDC()
{
if (!m_pDC)
{
m_pFile->SetError();
return NULL;
}
CMetaFileDC* pNewDC = m_pDC->Copy();
if (!pNewDC)
{
m_pFile->SetError();
return NULL;
}
m_vDCStack.push_back(pNewDC);
m_pDC = pNewDC;
return pNewDC;
}
template<typename CMetaFileDC> CMetaFileDC* CMetaFilePlayer<CMetaFileDC>::RestoreDC()
{
if (m_vDCStack.size() <= 1)
{
m_pFile->SetError();
return m_pDC;
}
CMetaFileDC* pDC = m_vDCStack.at(m_vDCStack.size() - 1);
m_vDCStack.pop_back();
delete pDC;
pDC = m_vDCStack.at(m_vDCStack.size() - 1);
m_pDC = pDC;
return m_pDC;
}
template<typename CMetaFileDC> CMetaFileDC* CMetaFilePlayer<CMetaFileDC>::GetDC()
{
return m_pDC;
}
template<typename CMetaFileDC> void CMetaFilePlayer<CMetaFileDC>::RegisterObject(unsigned int ulIndex, CMetaFileObjectBase* pObject)
{
CMetaFileObjectMap::const_iterator oPos = m_mObjects.find(ulIndex);
if (m_mObjects.end() != oPos)
{
CMetaFileObjectBase* pOldObject = oPos->second;
delete pOldObject;
m_mObjects.erase(ulIndex);
}
m_mObjects.insert(std::pair<unsigned int, CMetaFileObjectBase*>(ulIndex, pObject));
}
template<typename CMetaFileDC> void CMetaFilePlayer<CMetaFileDC>::SelectObject(unsigned int ulIndex)
{
CMetaFileObjectMap::const_iterator oPos = m_mObjects.find(ulIndex);
if (m_mObjects.end() != oPos)
{
CMetaFileObjectBase* pObject = oPos->second;
for (int nIndex = 0; nIndex < m_vDCStack.size(); nIndex++)
{
CMetaFileDC* pDC = m_vDCStack.at(nIndex);
switch (pObject->GetType())
{
case METAFILE_OBJECT_BRUSH: m_pDC->SetBrush(pObject); break;
case METAFILE_OBJECT_FONT : m_pDC->SetFont(pObject); break;
case METAFILE_OBJECT_PEN : m_pDC->SetPen(pObject); break;
}
}
}
}
template<typename CMetaFileDC> void CMetaFilePlayer<CMetaFileDC>::SelectPalette(unsigned int ulIndex)
{
CEmfObjectMap::const_iterator oPos = m_mObjects.find(ulIndex);
if (m_mObjects.end() != oPos)
{
CEmfObjectBase* pObject = oPos->second;
if (METAFILE_OBJECT_PALETTE == pObject->GetType())
m_pDC->SetPalette(pObject);
}
}
template<typename CMetaFileDC> void CMetaFilePlayer<CMetaFileDC>::DeleteObject(unsigned int ulIndex)
{
// TODO: DC_BRUSH DC_PEN
CEmfObjectMap::const_iterator oPos = m_mObjects.find(ulIndex);
if (m_mObjects.end() != oPos)
{
CEmfObjectBase* pObject = oPos->second;
switch (pObject->GetType())
{
case METAFILE_OBJECT_BRUSH: m_pDC->RemoveBrush(pObject); break;
case METAFILE_OBJECT_FONT: m_pDC->RemoveFont(pObject); break;
case METAFILE_OBJECT_PEN: m_pDC->RemovePen(pObject); break;
}
delete pObject;
m_mObjects.erase(ulIndex);
}
}
template<typename CMetaFileDC> void CMetaFilePlayer<CMetaFileDC>::InitStockObjects()
{
}
}
\ No newline at end of file
#ifndef _METAFILE_COMMON_H
#define _METAFILE_COMMON_H
#include <map>
#include <vector>
#include "MetaFileObjects.h"
#include "MetaFile.h"
namespace MetaFile
{
template <typename CMetaFileDC> class CMetaFilePlayer
{
public:
CMetaFilePlayer(CMetaFileBase* pFile);
~CMetaFilePlayer();
void Clear();
CMetaFileDC* SaveDC();
CMetaFileDC* RestoreDC();
CMetaFileDC* GetDC();
void RegisterObject(unsigned int ulIndex, CMetaFileObjectBase* pObject);
void SelectObject(unsigned int ulIndex);
void DeleteObject(unsigned int ulIndex);
void SelectPalette(unsigned int ulIndex);
private:
virtual void InitStockObjects();
private:
typedef std::map<unsigned int, CMetaFileObjectBase*> CMetaFileObjectMap;
CMetaFileDC* m_pDC;
std::vector<CMetaFileDC*> m_vDCStack;
CMetaFileBase* m_pFile;
CMetaFileObjectMap m_mObjects;
};
}
#endif //_METAFILE_COMMON_H
\ No newline at end of file
#ifndef _METAFILE_RENDERER_OUPUT_EMF_H
#define _METAFILE_RENDERER_OUPUT_EMF_H
#ifndef _METAFILE_COMMON_METAFILERENDERER_H
#define _METAFILE_COMMON_METAFILERENDERER_H
#include "../../../graphics/IRenderer.h"
......@@ -21,7 +21,7 @@ namespace MetaFile
{
public:
CMetaFileRenderer(CMetaFileBase *pFile, IRenderer *pRenderer, double dX, double dY, double dWidth, double dHeight)
CMetaFileRenderer(IMetaFileBase *pFile, IRenderer *pRenderer, double dX, double dY, double dWidth, double dHeight)
{
m_pFile = pFile;
......@@ -38,13 +38,13 @@ namespace MetaFile
m_pRenderer = pRenderer;
TRect* pBounds = m_pFile->GetDCBounds();
int lL = pBounds->lLeft;
int lR = pBounds->lRight;
int lT = pBounds->lTop;
int lB = pBounds->lBottom;
int nL = pBounds->nLeft;
int nR = pBounds->nRight;
int nT = pBounds->nTop;
int nB = pBounds->nBottom;
m_dScaleX = (lR - lL <= 0) ? 1 : m_dW / (double)(lR - lL);
m_dScaleY = (lB - lT <= 0) ? 1 : m_dH / (double)(lB - lT);
m_dScaleX = (nR - nL <= 0) ? 1 : m_dW / (double)(nR - nL);
m_dScaleY = (nB - nT <= 0) ? 1 : m_dH / (double)(nB - nT);
m_bStartedPath = false;
}
......@@ -84,14 +84,14 @@ namespace MetaFile
TPointD oBR = TranslatePoint(lX + lW, lY + lH);
m_pRenderer->DrawImage(&oImage, oTL.x, oTL.y, oBR.x - oTL.x, oBR.y - oTL.y);
}
void DrawText(const wchar_t* wsText, unsigned int ulCharsCount, int lX, int lY, int nTextW, bool bWithOutLast)
void DrawText(std::wstring& wsText, unsigned int ulCharsCount, int lX, int lY, int nTextW, bool bWithOutLast)
{
CheckEndPath();
UpdateTransform();
UpdateClip();
CFont* pFont = m_pFile->GetFont();
IFont* pFont = m_pFile->GetFont();
if (!pFont)
return;
......@@ -150,18 +150,22 @@ namespace MetaFile
if (0 != nTextW && ulCharsCount > 1)
{
wchar_t* wsTempText = new wchar_t[ulCharsCount + 1];
if (!wsTempText)
return;
std::wstring wsTempText = wsText;
if (bWithOutLast)
wsTempText.erase(ulCharsCount - 1);
wsTempText[ulCharsCount] = 0x0000;
for (unsigned int unIndex = 0; unIndex < ulCharsCount; unIndex++)
{
wsTempText[unIndex] = wsText[unIndex];
}
//wchar_t* wsTempText = new wchar_t[ulCharsCount + 1];
//if (!wsTempText)
// return;
if (bWithOutLast)
wsTempText[ulCharsCount - 1] = 0x0000;
//wsTempText[ulCharsCount] = 0x0000;
//for (unsigned int unIndex = 0; unIndex < ulCharsCount; unIndex++)
//{
// wsTempText[unIndex] = wsText[unIndex];
//}
//if (bWithOutLast)
// wsTempText[ulCharsCount - 1] = 0x0000;
pFontManager->LoadString1(wsTempText, 0, 0);
......@@ -182,7 +186,7 @@ namespace MetaFile
m_pRenderer->put_FontCharSpace(dCharSpace * 25.4 / 72);
}
delete[] wsTempText;
/*delete[] wsTempText;*/
pFontManager->LoadString1(wsText, 0, 0);
oBox = pFontManager->MeasureString2();
......@@ -510,8 +514,8 @@ namespace MetaFile
// . ,
// .
TRect* pBounds = m_pFile->GetDCBounds();
double dT = pBounds->lTop;
double dL = pBounds->lLeft;
double dT = pBounds->nTop;
double dL = pBounds->nLeft;
TEmfXForm* pInverse = m_pFile->GetInverseTransform();
TEmfXForm* pTransform = m_pFile->GetTransform();
......@@ -528,7 +532,7 @@ namespace MetaFile
bool UpdateBrush()
{
CBrush* pBrush = m_pFile->GetBrush();
IBrush* pBrush = m_pFile->GetBrush();
if (!pBrush)
return false;
......@@ -561,7 +565,7 @@ namespace MetaFile
}
bool UpdatePen()
{
CPen* pPen = m_pFile->GetPen();
IPen* pPen = m_pFile->GetPen();
if (!pPen)
return false;
......@@ -633,7 +637,7 @@ namespace MetaFile
}
bool UpdateClip()
{
CClip* pClip = m_pFile->GetClip();
IClip* pClip = m_pFile->GetClip();
if (!pClip)
return false;
......@@ -645,6 +649,7 @@ namespace MetaFile
private:
IRenderer* m_pRenderer;
IMetaFileBase* m_pFile;
int m_lDrawPathType;
double m_dX; //
double m_dY; //
......@@ -652,8 +657,7 @@ namespace MetaFile
double m_dH; //
double m_dScaleX; // /,
double m_dScaleY; // .
CMetaFileBase* m_pFile;
bool m_bStartedPath;
};
}
#endif // _METAFILE_RENDERER_OUPUT_EMF_H
\ No newline at end of file
#endif // _METAFILE_COMMON_METAFILERENDERER_H
\ No newline at end of file
#include "MetaFileTypes.h"
#include "../Emf/EmfTypes.h"
#include "../Wmf/WmfTypes.h"
namespace MetaFile
{
TRect::TRect()
{
nLeft = 0;
nTop = 0;
nRight = 1024;
nBottom = 1024;
}
TRect& TRect::operator=(TWmfRect& oRect)
{
nLeft = oRect.Left;
nTop = oRect.Top;
nRight = oRect.Right;
nBottom = oRect.Bottom;
return *this;
}
TPointL::TPointL()
{
x = 0;
y = 0;
}
TPointL::TPointL(TEmfPointL& oPoint)
{
x = oPoint.x;
y = oPoint.y;
}
TPointL::TPointL(TWmfPointS& oPoint)
{
x = oPoint.x;
y = oPoint.y;
}
TPointL& TPointL::operator=(TWmfPointS& oPoint)
{
x = oPoint.x;
y = oPoint.y;
return *this;
}
TPointL& TPointL::operator=(TEmfPointL& oPoint)
{
x = oPoint.x;
y = oPoint.y;
return *this;
}
}
\ No newline at end of file
......@@ -3,18 +3,70 @@
namespace MetaFile
{
struct TEmfPointL;
struct TWmfPointS;
struct TWmfRect;
struct TRect
{
long lLeft;
long lTop;
long lRight;
long lBottom;
int nLeft;
int nTop;
int nRight;
int nBottom;
TRect();
TRect& operator=(TWmfRect& oRect);
};
struct TRectD
{
double dLeft;
double dTop;
double dRight;
double dBottom;
TRectD()
{
dLeft = 0;
dTop = 0;
dRight = 1024;
dBottom = 1024;
}
TRectD(TRect& oRect)
{
dLeft = (double)oRect.nLeft;
dTop = (double)oRect.nTop;
dRight = (double)oRect.nRight;
dBottom = (double)oRect.nBottom;
}
TRectD& operator=(TRect& oRect)
{
dLeft = (double)oRect.nLeft;
dTop = (double)oRect.nTop;
dRight = (double)oRect.nRight;
dBottom = (double)oRect.nBottom;
return *this;
}
TRectD& operator*=(double& dValue)
{
dLeft *= dValue;
dTop *= dValue;
dRight *= dValue;
dBottom *= dValue;
return *this;
}
};
struct TPointL
{
int x;
int y;
TPointL();
TPointL(TWmfPointS& oPoint);
TPointL(TEmfPointL& oPoint);
TPointL& operator=(TWmfPointS& oPoint);
TPointL& operator=(TEmfPointL& oPoint);
};
struct TPointD
......@@ -29,6 +81,95 @@ namespace MetaFile
unsigned char g;
unsigned char b;
};
#define MWT_IDENTITY 0x01
#define MWT_LEFTMULTIPLY 0x02
#define MWT_RIGHTMULTIPLY 0x03
#define MWT_SET 0x04
struct TXForm
{
double M11;
double M12;
double M21;
double M22;
double Dx;
double Dy;
void Init()
{
M11 = 1;
M12 = 0;
M21 = 0;
M22 = 1;
Dx = 0;
Dy = 0;
}
void Copy(TXForm* pOther)
{
M11 = pOther->M11;
M12 = pOther->M12;
M21 = pOther->M21;
M22 = pOther->M22;
Dx = pOther->Dx;
Dy = pOther->Dy;
}
void Multiply(TXForm &oOther, unsigned int ulMode)
{
if (MWT_IDENTITY == ulMode)
Init();
else if (MWT_LEFTMULTIPLY == ulMode)
{
// oOther ,
double dM11 = oOther.M11 * M11 + oOther.M12 * M21;
double dM12 = oOther.M11 * M21 + oOther.M12 * M22;
double dM21 = oOther.M21 * M11 + oOther.M22 * M21;
double dM22 = oOther.M21 * M21 + oOther.M22 * M22;
double dDx = oOther.Dx * M11 + oOther.Dy * M21 + Dx;
double dDy = oOther.Dx * M21 + oOther.Dy * M22 + Dy;
M11 = dM11;
M12 = dM12;
M21 = dM21;
M22 = dM22;
Dx = dDx;
Dy = dDy;
}
else if (MWT_RIGHTMULTIPLY == ulMode)
{
// oOther ,
double dM11 = M11 * oOther.M11 + M12 * oOther.M21;
double dM12 = M11 * oOther.M21 + M12 * oOther.M22;
double dM21 = M21 * oOther.M11 + M22 * oOther.M21;
double dM22 = M21 * oOther.M21 + M22 * oOther.M22;
double dDx = Dx * oOther.M11 + Dy * oOther.M21 + oOther.Dx;
double dDy = Dx * oOther.M21 + Dy * oOther.M22 + oOther.Dy;
M11 = dM11;
M12 = dM12;
M21 = dM21;
M22 = dM22;
Dx = dDx;
Dy = dDy;
}
else //if (MWT_SET == ulMode)
{
Copy(&oOther);
}
}
void Apply(double& dX, double& dY)
{
double _dX = dX;
double _dY = dY;
dX = _dX * M11 + _dY * M21 + Dx;
dY = _dX * M12 + _dY * M22 + Dy;
}
};
}
#endif //_METAFILE_COMMON_METAFILETYPES_H
\ No newline at end of file
#include "EmfClip.h"
#include "EmfOutputDevice.h"
namespace MetaFile
{
......@@ -59,7 +58,7 @@ namespace MetaFile
m_vCommands.push_back(pCommand);
return true;
}
void CEmfClip::ClipOnRenderer(CEmfOutputDevice* pOutput)
void CEmfClip::ClipOnRenderer(IOutputDevice* pOutput)
{
if (!pOutput)
return;
......
#ifndef _EMF_CLIP_H
#define _EMF_CLIP_H
#ifndef _METAFILE_EMF_EMFCLIP_H
#define _METAFILE_EMF_EMFCLIP_H
#include <vector>
#include "EmfTypes.h"
#include "EmfPath.h"
#include "../Common/MetaFileClip.h"
namespace MetaFile
{
class CEmfOutputDevice;
typedef enum
{
EMF_CLIPCOMMAND_UNKNOWN = 0x00,
......@@ -67,7 +66,7 @@ namespace MetaFile
unsigned int m_unMode;
};
class CEmfClip
class CEmfClip : public IClip
{
public:
CEmfClip();
......@@ -77,7 +76,7 @@ namespace MetaFile
void Reset();
bool Intersect(TEmfRectL& oRect);
bool SetPath(CEmfPath* pPath, unsigned int umMode);
void ClipOnRenderer(CEmfOutputDevice* pOutput);
void ClipOnRenderer(IOutputDevice* pOutput);
private:
......@@ -89,4 +88,4 @@ namespace MetaFile
};
}
#endif // _EMF_CLIP_H
\ No newline at end of file
#endif // _METAFILE_EMF_EMFCLIP_H
\ No newline at end of file
#ifndef _EMF_FILE_H
#define _EMF_FILE_H
#ifndef _METAFILE_EMF_EMFFILE_H
#define _METAFILE_EMF_EMFFILE_H
#include "../Wmf/WmfUtils.h"
#include "../Wmf/WmfTypes.h"
......@@ -7,7 +7,6 @@
#include "../Common.h"
#include "EmfTypes.h"
#include "EmfOutputDevice.h"
#include "EmfPlayer.h"
#include "EmfPath.h"
......@@ -17,85 +16,27 @@
namespace MetaFile
{
class CEmfFile
class CEmfFile : virtual public IMetaFileBase
{
public:
CEmfFile() : m_oPlayer(this)
{
m_pBufferData = NULL;
m_bError = false;
m_pOutput = NULL;
m_pPath = NULL;
m_oStream.SetStream(NULL, 0);
m_pDC = m_oPlayer.GetDC();
m_pPath = NULL;
m_pDC = m_oPlayer.GetDC();
};
~CEmfFile()
{
Close();
ClearFile();
};
bool OpenFromFile(const wchar_t* wsFilePath)
{
Close();
NSFile::CFileBinary oFile;
oFile.OpenFile(wsFilePath);
int lFileSize = oFile.GetFileSize();
m_pBufferData = new BYTE[lFileSize];
if (!m_pBufferData)
return false;
DWORD lReadedSize;
oFile.ReadFile(m_pBufferData, lFileSize, lReadedSize);
m_oStream.SetStream(m_pBufferData, lFileSize);
return true;
}
void Close()
{
RELEASEOBJECT(m_pBufferData);
RELEASEOBJECT(m_pPath);
m_pOutput = NULL;
m_oStream.SetStream(NULL, 0);
m_bError = false;
m_oPlayer.Clear();
m_pDC = m_oPlayer.GetDC();
}
TEmfRectL* GetBounds()
{
return &m_oHeader.oFrame;
}
void SetOutputDevice(CEmfOutputDevice* pOutput)
{
m_pOutput = pOutput;
}
void Scan()
{
CEmfOutputDevice* pOutput = m_pOutput;
m_pOutput = NULL;
PlayMetaFile();
m_pOutput = pOutput;
RELEASEOBJECT(m_pPath);
m_oPlayer.Clear();
m_pDC = m_oPlayer.GetDC();
}
bool CheckError()
{
return m_bError;
}
void SetFontManager(CFontManager* pManager)
{
m_pFontManager = pManager;
}
void PlayMetaFile()
void PlayMetaFile()
{
if (!m_oStream.IsValid())
SetError();
......@@ -264,21 +205,127 @@ namespace MetaFile
if (m_pOutput)
m_pOutput->End();
}
void ClearFile()
{
RELEASEOBJECT(m_pPath);
m_oPlayer.Clear();
m_pDC = m_oPlayer.GetDC();
}
double TranslateX(int nSrcX)
{
double dDstX;
private:
TEmfWindow* pWindow = m_pDC->GetWindow();
TEmfWindow* pViewport = m_pDC->GetViewport();
void SetError()
{
m_bError = true;
dDstX = (double)((double)(nSrcX - pWindow->lX) * m_pDC->GetPixelWidth()) + pViewport->lX;
return dDstX;
}
CEmfDC* GetDC()
double TranslateY(int nSrcY)
{
return m_pDC;
double dDstY;
TEmfWindow* pWindow = m_pDC->GetWindow();
TEmfWindow* pViewport = m_pDC->GetViewport();
dDstY = (double)((double)(nSrcY - pWindow->lY) * m_pDC->GetPixelHeight()) + pViewport->lY;
return dDstY;
}
TEmfRectL* GetDCBounds()
TRect* GetDCBounds()
{
return &m_oHeader.oFrameToBounds;
}
double GetPixelHeight()
{
return m_pDC->GetPixelHeight();
}
double GetPixelWidth()
{
return m_pDC->GetPixelWidth();
}
int GetTextColor()
{
TEmfColor& oColor = m_pDC->GetTextColor();
return METAFILE_RGBA(oColor.r, oColor.g, oColor.b);
}
IFont* GetFont()
{
CEmfLogFont* pFont = m_pDC->GetFont();
if (!pFont)
return NULL;
return (IFont*)pFont;
}
IBrush* GetBrush()
{
CEmfLogBrushEx* pBrush = m_pDC->GetBrush();
if (!pBrush)
return NULL;
return (IBrush*)pBrush;
}
IPen* GetPen()
{
CEmfLogPen* pPen = m_pDC->GetPen();
if (!pPen)
return NULL;
return (IPen*)pPen;
}
unsigned int GetTextAlign()
{
return m_pDC->GetTextAlign();
}
unsigned int GetTextBgMode()
{
return m_pDC->GetBgMode();
}
int GetTextBgColor()
{
TEmfColor& oColor = m_pDC->GetBgColor();
return METAFILE_RGBA(oColor.r, oColor.g, oColor.b);
}
unsigned int GetFillMode()
{
return m_pDC->GetFillMode();
}
TPointL GetCurPos()
{
TPointL oPoint = m_pDC->GetCurPos();
return oPoint;
}
TXForm* GetInverseTransform()
{
return m_pDC->GetInverseTransform();
}
TXForm* GetTransform()
{
return m_pDC->GetTransform();
}
unsigned int GetMiterLimit()
{
return m_pDC->GetMiterLimit();
}
unsigned int GetRop2Mode()
{
return m_pDC->GetRop2Mode();
}
IClip* GetClip()
{
CEmfClip* pClip = m_pDC->GetClip();
if (!pClip)
return NULL;
return (IClip*)pClip;
}
private:
CEmfDC* GetDC()
{
return m_pDC;
}
bool ReadImage(unsigned int offBmi, unsigned int cbBmi, unsigned int offBits, unsigned int cbBits, unsigned int ulSkip, BYTE** ppBgraBuffer, unsigned int* pulWidth, unsigned int* pulHeight)
{
int lHeaderOffset = offBmi - ulSkip;
......@@ -329,27 +376,6 @@ namespace MetaFile
return true;
}
double TranslateX(int lSrcX)
{
double dDstX;
TEmfWindow* pWindow = m_pDC->GetWindow();
TEmfWindow* pViewport = m_pDC->GetViewport();
dDstX = (double)((double)(lSrcX - pWindow->lX) * m_pDC->GetPixelWidth()) + pViewport->lX;
return dDstX;
}
double TranslateY(int lSrcY)
{
double dDstY;
TEmfWindow* pWindow = m_pDC->GetWindow();
TEmfWindow* pViewport = m_pDC->GetViewport();
dDstY = (double)((double)(lSrcY - pWindow->lY) * m_pDC->GetPixelHeight()) + pViewport->lY;
return dDstY;
}
void MoveTo(TEmfPointL& oPoint)
{
......@@ -472,7 +498,7 @@ namespace MetaFile
if (m_pOutput)
{
m_pOutput->DrawText(wsString.c_str(), unCharsCount, nX, nY, nTextW, bWithOutLast);
m_pOutput->DrawText(wsString, unCharsCount, nX, nY, nTextW, bWithOutLast);
}
}
void DrawTextA(TEmfEmrText& oText)
......@@ -565,16 +591,16 @@ namespace MetaFile
double dW = dR - dL;
double dH = dB - dT;
int lL = (int)floor(dL + 0.5);
int lT = (int)floor(dT + 0.5);
int lR = (int)floor(dW + 0.5) + lL;
int lB = (int)floor(dH + 0.5) + lT;
int nL = (int)floor(dL + 0.5);
int nT = (int)floor(dT + 0.5);
int nR = (int)floor(dW + 0.5) + nL;
int nB = (int)floor(dH + 0.5) + nT;
// , oBounds, , .
m_oHeader.oFrameToBounds.lLeft = lL;
m_oHeader.oFrameToBounds.lRight = lR;
m_oHeader.oFrameToBounds.lTop = lT;
m_oHeader.oFrameToBounds.lBottom = lB;
m_oHeader.oFrameToBounds.nLeft = nL;
m_oHeader.oFrameToBounds.nRight = nR;
m_oHeader.oFrameToBounds.nTop = nT;
m_oHeader.oFrameToBounds.nBottom = nB;
}
void Read_EMR_ALPHABLEND()
{
......@@ -1756,23 +1782,14 @@ namespace MetaFile
private:
CDataStream m_oStream;
BYTE* m_pBufferData;
bool m_bError;
CFontManager* m_pFontManager;
TEmfHeader m_oHeader;
unsigned int m_ulRecordSize;
CEmfOutputDevice* m_pOutput;
CEmfDC* m_pDC;
CEmfPlayer m_oPlayer;
CEmfPath* m_pPath;
friend class CEmfRendererOutput;
friend class CEmfPlayer;
};
}
#endif // _EMF_FILE_H
#endif // _METAFILE_EMF_EMFFILE_H
#include "EmfObjects.h"
#include "../../../raster/ImageFileFormatChecker.h"
#include "../../../graphics/Image.h"
#include "../Common.h"
namespace MetaFile
{
......@@ -60,4 +61,12 @@ namespace MetaFile
BrushStyle = BS_DIBPATTERN;
DibPatternPath = wsTempFileName;
}
int CEmfLogBrushEx::GetColor()
{
return METAFILE_RGBA(Color.r, Color.g, Color.b);
}
int CEmfLogPen::GetColor()
{
return METAFILE_RGBA(Color.r, Color.g, Color.b);
}
}
#ifndef _EMF_OBJECTS_H
#define _EMF_OBJECTS_H
#ifndef _METAFILE_EMF_EMFOBJECTS_H
#define _METAFILE_EMF_EMFOBJECTS_H
#include "EmfTypes.h"
#include "../Wmf/WmfUtils.h"
#include "../Wmf/WmfTypes.h"
#include "../../common/Types.h"
#include "../Common/MetaFileObjects.h"
#include "../../../common/File.h"
namespace MetaFile
{
......@@ -29,8 +30,7 @@ namespace MetaFile
}
};
class CEmfLogBrushEx : public CEmfObjectBase
class CEmfLogBrushEx : public CEmfObjectBase, public IBrush
{
public:
......@@ -42,6 +42,25 @@ namespace MetaFile
}
void SetDibPattern(unsigned char* pBuffer, unsigned int ulWidth, unsigned int ulHeight);
// IBrush
int GetColor();
unsigned int GetStyle()
{
return BrushStyle;
}
unsigned int GetHatch()
{
return BrushHatch;
}
unsigned int GetAlpha()
{
return BrushAlpha;
}
std::wstring GetDibPatterPath()
{
return DibPatternPath;
}
public:
unsigned int BrushStyle;
TEmfColor Color;
......@@ -53,7 +72,7 @@ namespace MetaFile
unsigned int DibHeigth;
};
class CEmfLogFont : public CEmfObjectBase
class CEmfLogFont : public CEmfObjectBase, public IFont
{
public:
CEmfLogFont()
......@@ -70,13 +89,43 @@ namespace MetaFile
return EMF_OBJECT_FONT;
}
// IFont
int GetHeight()
{
return LogFontEx.LogFont.Height;
}
std::wstring GetFaceName()
{
return NSFile::CUtf8Converter::GetWStringFromUTF16(LogFontEx.LogFont.FaceName, 32);
}
int GetWeight()
{
return LogFontEx.LogFont.Weight;
}
bool IsItalic()
{
return (0x01 == LogFontEx.LogFont.Italic ? true : false);
}
bool IsStrikeOut()
{
return (0x01 == LogFontEx.LogFont.StrikeOut ? true : false);
}
bool IsUnderline()
{
return (0x01 == LogFontEx.LogFont.Underline ? true : false);
}
int GetEscapement()
{
return LogFontEx.LogFont.Escapement;
}
public:
TEmfLogFontEx LogFontEx;
TEmfDesignVector DesignVector;
};
class CEmfLogPen : public CEmfObjectBase
class CEmfLogPen : public CEmfObjectBase, public IPen
{
public:
CEmfLogPen() : PenStyle(PS_SOLID), Width(1), Color(0, 0, 0)
......@@ -93,11 +142,22 @@ namespace MetaFile
return EMF_OBJECT_PEN;
}
// IPen
int GetColor();
unsigned int GetStyle()
{
return PenStyle;
}
unsigned int GetWidth()
{
return Width;
}
public:
unsigned int PenStyle;
unsigned int Width;
TEmfColor Color;
TEmfColor Color;
unsigned int NumStyleEntries;
unsigned int* StyleEntry;
};
......@@ -127,4 +187,4 @@ namespace MetaFile
};
}
#endif // _EMF_OBJECTS_H
#endif // _METAFILE_EMF_EMFOBJECTS_H
#ifndef _EMF_OUTPUT_DEVICE_H
#define _EMF_OUTPUT_DEVICE_H
#include "../Wmf/WmfTypes.h"
namespace MetaFile
{
class CEmfOutputDevice
{
public:
CEmfOutputDevice() {}
virtual ~CEmfOutputDevice() {}
//
virtual void Begin() = 0;
virtual void End() = 0;
// pBuffer - BGRA ulWidth, ulHeight,
virtual void DrawBitmap(int lX, int lY, int lW, int lH, BYTE* pBuffer, unsigned int ulWidth, unsigned int ulHeight) = 0;
virtual void DrawText(const wchar_t* wsText, unsigned int ulCharsCount, int lX, int lY, int nTextW, bool bWithOutLast) = 0;
virtual void StartPath() = 0;
virtual void MoveTo(int lX, int lY) = 0;
virtual void LineTo(int lX, int lY) = 0;
virtual void CurveTo(int lX1, int lY1, int lX2, int lY2, int lXe, int lYe) = 0;
virtual void ArcTo(int lLeft, int lTop, int lRight, int lBottom, double dStartAngle, double dSweepAngle) = 0;
virtual void ClosePath() = 0;
virtual void DrawPath(int lType = 0) = 0;
virtual void EndPath() = 0;
virtual void ResetClip() = 0;
virtual void IntersectClip(int lLeft, int lTop, int lRight, int lBottom) = 0;
virtual void StartClipPath(unsigned int unMode) = 0;
virtual void EndClipPath(unsigned int unMode) = 0;
virtual void UpdateDC() = 0;
};
}
#endif //_EMF_OUTPUT_DEVICE_H
\ No newline at end of file
#include "EmfPath.h"
#include "EmfOutputDevice.h"
namespace MetaFile
{
......@@ -162,7 +161,7 @@ namespace MetaFile
return true;
}
void CEmfPath::Draw(CEmfOutputDevice* pOutput, bool bStroke, bool bFill, unsigned int unClipMode)
void CEmfPath::Draw(IOutputDevice* pOutput, bool bStroke, bool bFill, unsigned int unClipMode)
{
if (pOutput)
{
......
#ifndef _EMF_PATH_H
#define _EMF_PATH_H
#ifndef _METAFILE_EMF_EMFPATH_H
#define _METAFILE_EMF_EMFPATH_H
#include "EmfTypes.h"
#include "../Wmf/WmfTypes.h"
#include <vector>
#include "../Common/IOutputDevice.h"
namespace MetaFile
{
class CEmfOutputDevice;
typedef enum
{
EMF_PATHCOMMAND_UNKNOWN = 0x00,
......@@ -204,7 +203,7 @@ namespace MetaFile
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 Close();
void Draw(CEmfOutputDevice* pOutput, bool bStroke, bool bFill, unsigned int unClipMode = -1);
void Draw(IOutputDevice* pOutput, bool bStroke, bool bFill, unsigned int unClipMode = -1);
private:
......@@ -216,4 +215,4 @@ namespace MetaFile
};
}
#endif //_EMF_PATH_H
\ No newline at end of file
#endif //_METAFILE_EMF_EMFPATH_H
\ No newline at end of file
#ifndef _EMF_PLAYER_H
#define _EMF_PLAYER_H
#ifndef _METAFILE_EMF_EMFPLAYER_H
#define _METAFILE_EMF_EMFPLAYER_H
#include <vector>
#include <map>
......@@ -133,4 +133,4 @@ namespace MetaFile
};
}
#endif //_EMF_PLAYER_H
\ No newline at end of file
#endif //_METAFILE_EMF_EMFPLAYER_H
\ No newline at end of file
#ifndef _EMF_TYPES_H
#define _EMF_TYPES_H
#ifndef _METAFILE_EMF_EMFTYPES_H
#define _METAFILE_EMF_EMFTYPES_H
#include "../../../common/Types.h"
#include "../Common/MetaFileTypes.h"
#if !defined(_WIN32) && !defined(_WIN64)
//from wingdi.h
......@@ -309,7 +310,7 @@ namespace MetaFile
unsigned int ulPalEntries;
TEmfSizeL oDevice;
TEmfSizeL oMillimeters;
TEmfRectL oFrameToBounds;
TRect oFrameToBounds;
};
struct TEmfStretchDIBITS
......@@ -331,94 +332,90 @@ namespace MetaFile
int cyDest;
};
#define MWT_IDENTITY 0x01
#define MWT_LEFTMULTIPLY 0x02
#define MWT_RIGHTMULTIPLY 0x03
#define MWT_SET 0x04
struct TEmfXForm
{
double M11;
double M12;
double M21;
double M22;
double Dx;
double Dy;
void Init()
{
M11 = 1;
M12 = 0;
M21 = 0;
M22 = 1;
Dx = 0;
Dy = 0;
}
void Copy(TEmfXForm* pOther)
{
M11 = pOther->M11;
M12 = pOther->M12;
M21 = pOther->M21;
M22 = pOther->M22;
Dx = pOther->Dx;
Dy = pOther->Dy;
}
void Multiply(TEmfXForm &oOther, unsigned int ulMode)
{
if (MWT_IDENTITY == ulMode)
Init();
else if (MWT_LEFTMULTIPLY == ulMode)
{
// oOther ,
double dM11 = oOther.M11 * M11 + oOther.M12 * M21;
double dM12 = oOther.M11 * M21 + oOther.M12 * M22;
double dM21 = oOther.M21 * M11 + oOther.M22 * M21;
double dM22 = oOther.M21 * M21 + oOther.M22 * M22;
double dDx = oOther.Dx * M11 + oOther.Dy * M21 + Dx;
double dDy = oOther.Dx * M21 + oOther.Dy * M22 + Dy;
M11 = dM11;
M12 = dM12;
M21 = dM21;
M22 = dM22;
Dx = dDx;
Dy = dDy;
}
else if (MWT_RIGHTMULTIPLY == ulMode)
{
// oOther ,
double dM11 = M11 * oOther.M11 + M12 * oOther.M21;
double dM12 = M11 * oOther.M21 + M12 * oOther.M22;
double dM21 = M21 * oOther.M11 + M22 * oOther.M21;
double dM22 = M21 * oOther.M21 + M22 * oOther.M22;
double dDx = Dx * oOther.M11 + Dy * oOther.M21 + oOther.Dx;
double dDy = Dx * oOther.M21 + Dy * oOther.M22 + oOther.Dy;
M11 = dM11;
M12 = dM12;
M21 = dM21;
M22 = dM22;
Dx = dDx;
Dy = dDy;
}
else //if (MWT_SET == ulMode)
{
Copy(&oOther);
}
}
void Apply(double& dX, double& dY)
{
double _dX = dX;
double _dY = dY;
dX = _dX * M11 + _dY * M21 + Dx;
dY = _dX * M12 + _dY * M22 + Dy;
}
};
#define TEmfXForm TXForm
//struct TEmfXForm
//{
// double M11;
// double M12;
// double M21;
// double M22;
// double Dx;
// double Dy;
// void Init()
// {
// M11 = 1;
// M12 = 0;
// M21 = 0;
// M22 = 1;
// Dx = 0;
// Dy = 0;
// }
// void Copy(TEmfXForm* pOther)
// {
// M11 = pOther->M11;
// M12 = pOther->M12;
// M21 = pOther->M21;
// M22 = pOther->M22;
// Dx = pOther->Dx;
// Dy = pOther->Dy;
// }
// void Multiply(TEmfXForm &oOther, unsigned int ulMode)
// {
// if (MWT_IDENTITY == ulMode)
// Init();
// else if (MWT_LEFTMULTIPLY == ulMode)
// {
// // oOther ,
// double dM11 = oOther.M11 * M11 + oOther.M12 * M21;
// double dM12 = oOther.M11 * M21 + oOther.M12 * M22;
// double dM21 = oOther.M21 * M11 + oOther.M22 * M21;
// double dM22 = oOther.M21 * M21 + oOther.M22 * M22;
// double dDx = oOther.Dx * M11 + oOther.Dy * M21 + Dx;
// double dDy = oOther.Dx * M21 + oOther.Dy * M22 + Dy;
// M11 = dM11;
// M12 = dM12;
// M21 = dM21;
// M22 = dM22;
// Dx = dDx;
// Dy = dDy;
// }
// else if (MWT_RIGHTMULTIPLY == ulMode)
// {
// // oOther ,
// double dM11 = M11 * oOther.M11 + M12 * oOther.M21;
// double dM12 = M11 * oOther.M21 + M12 * oOther.M22;
// double dM21 = M21 * oOther.M11 + M22 * oOther.M21;
// double dM22 = M21 * oOther.M21 + M22 * oOther.M22;
// double dDx = Dx * oOther.M11 + Dy * oOther.M21 + oOther.Dx;
// double dDy = Dx * oOther.M21 + Dy * oOther.M22 + oOther.Dy;
// M11 = dM11;
// M12 = dM12;
// M21 = dM21;
// M22 = dM22;
// Dx = dDx;
// Dy = dDy;
// }
// else //if (MWT_SET == ulMode)
// {
// Copy(&oOther);
// }
// }
// void Apply(double& dX, double& dY)
// {
// double _dX = dX;
// double _dY = dY;
// dX = _dX * M11 + _dY * M21 + Dx;
// dY = _dX * M12 + _dY * M22 + Dy;
// }
//};
struct TEmfEmrText
{
......@@ -571,7 +568,7 @@ namespace MetaFile
int Weight;
unsigned char Italic;
unsigned char Underline;
unsigned char StrikOut;
unsigned char StrikeOut;
unsigned char CharSet;
unsigned char OutPrecision;
unsigned char ClipPrecision;
......@@ -714,4 +711,4 @@ namespace MetaFile
const unsigned int c_nTEmfAlphaBlendSize = 100;
};
#endif //_EMF_TYPES_H
#endif //_METAFILE_EMF_EMFTYPES_H
This diff is collapsed.
......@@ -3,7 +3,7 @@
#include "../../graphics/GraphicsRenderer.h"
#include "../../raster/BgraFrame.h"
#include "Emf/RendererOutput.h"
#include "Common/MetaFileRenderer.h"
#ifndef NEW_WMF
#include "Wmf/RendererOutput.h"
#endif
......@@ -77,6 +77,9 @@ namespace MetaFile
if (c_lMetaWmf == m_lType)
{
#ifdef NEW_WMF
CMetaFileRenderer oWmfOut(&m_oWmfFile, pRenderer, dX, dY, dWidth, dHeight);
m_oWmfFile.SetOutputDevice((IOutputDevice*)&oWmfOut);
m_oWmfFile.PlayMetaFile();
#else
double dRendererDpix, dRendererDpiY;
pRenderer->get_DpiX(&dRendererDpix);
......@@ -122,8 +125,8 @@ namespace MetaFile
}
else if (c_lMetaEmf == m_lType)
{
CEmfRendererOutput oEmfOut(&m_oEmfFile, pRenderer, dX, dY, dWidth, dHeight);
m_oEmfFile.SetOutputDevice(&oEmfOut);
CMetaFileRenderer oEmfOut(&m_oEmfFile, pRenderer, dX, dY, dWidth, dHeight);
m_oEmfFile.SetOutputDevice((IOutputDevice*)&oEmfOut);
m_oEmfFile.PlayMetaFile();
}
......@@ -145,10 +148,19 @@ namespace MetaFile
{
if (c_lMetaWmf == m_lType)
{
#ifdef NEW_WMF
TRectD& oRect = m_oWmfFile.GetBounds();
*pdX = oRect.dLeft;
*pdY = oRect.dTop;
*pdW = oRect.dRight - oRect.dLeft;
*pdH = oRect.dBottom - oRect.dTop;
#else
*pdX = m_oWmfRect.oTL.fX;
*pdY = m_oWmfRect.oTL.fY;
*pdW = m_oWmfRect.oBR.fX - m_oWmfRect.oTL.fX;
*pdH = m_oWmfRect.oBR.fY - m_oWmfRect.oTL.fY;
#endif
}
else if (c_lMetaEmf == m_lType)
{
......
#ifndef _METAFILE_H
#define _METAFILE_H
//#define NEW_WMF 1
#define NEW_WMF 1
#include "../../fontengine/ApplicationFonts.h"
#include "../../graphics/IRenderer.h"
......@@ -36,7 +36,7 @@ namespace MetaFile
CWmfFile m_oWmfFile;
TWmfRectF m_oWmfRect;
CEmfFile m_oEmfFile;
int m_lType;
int m_lType;
};
}
......
......@@ -184,6 +184,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="Common.cpp" />
<ClCompile Include="Common\MetaFileTypes.cpp" />
<ClCompile Include="Emf\EmfClip.cpp" />
<ClCompile Include="Emf\EmfObjects.cpp" />
<ClCompile Include="Emf\EmfPath.cpp" />
......
......@@ -155,5 +155,8 @@
<ClCompile Include="Wmf\WmfObjects.cpp">
<Filter>Wmf</Filter>
</ClCompile>
<ClCompile Include="Common\MetaFileTypes.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -47,7 +47,7 @@ void ConvertFolder(CMetaFile &oMetaFile, std::wstring wsFolderPath)
{
oMetaFile.Close();
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"emf");
std::vector<std::wstring> vFiles = GetAllFilesInFolder(wsFolderPath, L"wmf");
for (int nIndex = 0; nIndex < vFiles.size(); nIndex++)
{
std::wstring wsFilePath = wsFolderPath;
......
This diff is collapsed.
#include "WmfObjects.h"
#include "../../../raster/ImageFileFormatChecker.h"
#include "../../../graphics/Image.h"
#include "../Common.h"
namespace MetaFile
{
......@@ -33,7 +34,7 @@ namespace MetaFile
if (DibBuffer)
delete[] DibBuffer;
}
void CWmfBrush::SetDibPattern(unsigned char* pBuffer, unsigned int ulWidth, unsigned int ulHeight)
void CWmfBrush::SetDibPattern(unsigned char* pBuffer, unsigned int ulWidth, unsigned int ulHeight)
{
DibBuffer = pBuffer;
DibWidth = ulWidth;
......@@ -69,4 +70,29 @@ namespace MetaFile
BrushStyle = BS_DIBPATTERN;
DibPatternPath = wsTempFileName;
}
int CWmfBrush::GetColor()
{
return METAFILE_RGBA(Color.r, Color.g, Color.b);
}
unsigned int CWmfBrush::GetStyle()
{
return BrushStyle;
}
unsigned int CWmfBrush::GetHatch()
{
return BrushHatch;
}
unsigned int CWmfBrush::GetAlpha()
{
return 255;
}
std::wstring CWmfBrush::GetDibPatterPath()
{
return DibPatternPath;
}
int CWmfPen::GetColor()
{
return METAFILE_RGBA(Color.r, Color.g, Color.b);
}
}
......@@ -3,6 +3,7 @@
#include "WmfTypes.h"
#include "WmfUtils.h"
#include "../Common/MetaFileObjects.h"
namespace MetaFile
{
......@@ -25,7 +26,7 @@ namespace MetaFile
return WMF_OBJECT_UNKNOWN;
}
};
class CWmfBrush : public CWmfObjectBase
class CWmfBrush : public CWmfObjectBase, public IBrush
{
public:
CWmfBrush();
......@@ -37,6 +38,13 @@ namespace MetaFile
}
void SetDibPattern(unsigned char* pBuffer, unsigned int unWidth, unsigned int unHeight);
// IBrush
int GetColor();
unsigned int GetStyle();
unsigned int GetHatch();
unsigned int GetAlpha();
std::wstring GetDibPatterPath();
public:
unsigned short BrushStyle;
......@@ -47,7 +55,7 @@ namespace MetaFile
unsigned int DibWidth;
unsigned int DibHeigth;
};
class CWmfFont : public CWmfObjectBase
class CWmfFont : public CWmfObjectBase, public IFont
{
public:
......@@ -65,6 +73,36 @@ namespace MetaFile
return WMF_OBJECT_FONT;
}
// IFont
int GetHeight()
{
return (int)Height;
}
std::wstring GetFaceName()
{
return NSFile::CUtf8Converter::GetUnicodeFromCharPtr((const char*)Facename, 32, FALSE);
}
int GetWeight()
{
return (int)Weight;
}
bool IsItalic()
{
return (0x01 == Italic ? true : false);
}
bool IsStrikeOut()
{
return (0x01 == StrikeOut ? true : false);
}
bool IsUnderline()
{
return (0x01 == Underline ? true : false);
}
int GetEscapement()
{
return (int)Escapement;
}
public:
short Height;
......@@ -104,7 +142,7 @@ namespace MetaFile
unsigned short NumberOfEntries;
TWmfPaletteEntry* aPaletteEntries;
};
class CWmfPen : public CWmfObjectBase
class CWmfPen : public CWmfObjectBase, public IPen
{
public:
CWmfPen()
......@@ -119,6 +157,18 @@ namespace MetaFile
{
return WMF_OBJECT_PEN;
}
// IPen
int GetColor();
unsigned int GetStyle()
{
return (unsigned int)PenStyle;
}
unsigned int GetWidth()
{
return (unsigned int)Width.x;
}
public:
unsigned short PenStyle;
TWmfPointS Width;
......
......@@ -193,6 +193,18 @@ namespace MetaFile
delete pObject;
m_mObjects.erase(ushIndex);
}
if (ushIndex < m_ushIndex)
{
if (std::find(m_vAvailableIndexes.begin(), m_vAvailableIndexes.end(), ushIndex) != m_vAvailableIndexes.end())
{
//
}
else
{
m_vAvailableIndexes.push_back(ushIndex);
}
}
}
CWmfDC::CWmfDC()
......@@ -207,6 +219,17 @@ namespace MetaFile
m_dPixelHeight = 1;
m_oWindow.Init();
m_oViewport.Init();
m_oTextColor.Set(0, 0, 0);
m_oTextBgColor.Set(255, 255, 255);
m_oCurPos.Set(0, 0);
m_ushTextBgMode = TRANSPARENT;
m_ushLayout = LAYOUT_LTR;
m_ushPolyFillMode = WINDING;
m_ushRop2Mode = R2_COPYPEN;
m_ushStretchBltMode = COLORONCOLOR;
m_ushTextAlign = TA_TOP | TA_LEFT | TA_NOUPDATECP;
m_ushCharSpacing = 0;
m_oTransform.Init();
}
CWmfDC::~CWmfDC()
{
......@@ -218,16 +241,27 @@ namespace MetaFile
if (!pNewDC)
return NULL;
pNewDC->m_pBrush = (m_pBrush == &m_oDefaultBrush ? &pNewDC->m_oDefaultBrush : m_pBrush);
pNewDC->m_pPen = (m_pPen == &m_oDefaultPen ? &pNewDC->m_oDefaultPen : m_pPen);
pNewDC->m_pPalette = m_pPalette;
pNewDC->m_pFont = m_pFont;
pNewDC->m_pRegion = m_pRegion;
pNewDC->m_ushMapMode = m_ushMapMode;
pNewDC->m_dPixelWidth = m_dPixelWidth;
pNewDC->m_dPixelHeight = m_dPixelHeight;
pNewDC->m_pBrush = (m_pBrush == &m_oDefaultBrush ? &pNewDC->m_oDefaultBrush : m_pBrush);
pNewDC->m_pPen = (m_pPen == &m_oDefaultPen ? &pNewDC->m_oDefaultPen : m_pPen);
pNewDC->m_pPalette = m_pPalette;
pNewDC->m_pFont = m_pFont;
pNewDC->m_pRegion = m_pRegion;
pNewDC->m_ushMapMode = m_ushMapMode;
pNewDC->m_dPixelWidth = m_dPixelWidth;
pNewDC->m_dPixelHeight = m_dPixelHeight;
pNewDC->m_oWindow.Copy(m_oWindow);
pNewDC->m_oViewport.Copy(m_oViewport);
pNewDC->m_oTextColor = m_oTextColor;
pNewDC->m_oTextBgColor = m_oTextBgColor;
pNewDC->m_oCurPos = m_oCurPos;
pNewDC->m_ushTextBgMode = m_ushTextBgMode;
pNewDC->m_ushLayout = m_ushLayout;
pNewDC->m_ushPolyFillMode = m_ushPolyFillMode;
pNewDC->m_ushRop2Mode = m_ushRop2Mode;
pNewDC->m_ushStretchBltMode = m_ushStretchBltMode;
pNewDC->m_ushTextAlign = m_ushTextAlign;
pNewDC->m_ushCharSpacing = m_ushCharSpacing;
pNewDC->m_oTransform.Init();
return pNewDC;
}
......@@ -300,6 +334,9 @@ namespace MetaFile
{
m_ushMapMode = ushMapMode;
UpdatePixelMetrics();
return;
switch (m_ushMapMode)
{
case MM_TEXT: // 1 unit = 1pt
......@@ -438,7 +475,7 @@ namespace MetaFile
SetPixelHeight(dPixel);
SetPixelWidth(dPixel);
}
else if (MM_ANISOTROPIC == ushMapMode)
else// if (MM_ANISOTROPIC == ushMapMode)
{
double dPixelX = (double)m_oViewport.w / (double)m_oWindow.w;
double dPixelY = (double)m_oViewport.h / (double)m_oWindow.h;
......@@ -534,4 +571,16 @@ namespace MetaFile
{
return m_ushCharSpacing;
}
TXForm* CWmfDC::GetTransform()
{
return &m_oTransform;
}
TXForm* CWmfDC::GetInverseTransform()
{
return &m_oTransform;
}
unsigned int CWmfDC::GetMiterLimit()
{
return 0;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
#include <map>
#include <vector>
#include "WmfObjects.h"
#include "../Common/MetaFileTypes.h"
namespace MetaFile
{
......@@ -93,6 +94,9 @@ namespace MetaFile
unsigned short GetTextAlign();
void SetCharSpacing(unsigned short ushCharSpacing);
unsigned short GetCharSpacing();
TXForm* GetTransform();
TXForm* GetInverseTransform();
unsigned int GetMiterLimit();
private:
......@@ -124,6 +128,7 @@ namespace MetaFile
unsigned short m_ushStretchBltMode;
unsigned short m_ushTextAlign;
unsigned short m_ushCharSpacing;
TXForm m_oTransform;
};
//class CEmfDC
......
......@@ -780,6 +780,10 @@ enum EWmfBitCount
#define BI_JPEG 4L
#define BI_PNG 5L
#define LAYOUT_LTR 0x0000
#define LAYOUT_RTL 0x0001
#define LAYOUT_BITMAPORIENTATIONPRESERVED 0x0008
/* Metafile Functions */
#define META_SETBKCOLOR 0x0201
#define META_SETBKMODE 0x0102
......@@ -890,12 +894,12 @@ namespace MetaFile
a = 0;
}
void Copy(TWmfColor* pOther)
void Copy(TWmfColor& oOther)
{
r = pOther->r;
g = pOther->g;
b = pOther->b;
a = pOther->a;
r = oOther.r;
g = oOther.g;
b = oOther.b;
a = oOther.a;
}
TWmfColor& operator=(TWmfColor& oColor)
......@@ -918,6 +922,12 @@ namespace MetaFile
{
short x;
short y;
void Set(short _x, short _y)
{
x = _x;
y = _y;
}
};
struct TWmfRect
{
......@@ -969,8 +979,8 @@ namespace MetaFile
{
x = 0;
y = 0;
w = 1024;
h = 1024;
w = 1;
h = 1;
}
void Copy(TWmfWindow& oOther)
......
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