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

Удален старый вариант WMF. Немного изменена структура файлов.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@62375 954022d7-b5bf-4e40-9824-e11837661b57
parent b241feff
#ifndef _METAFILE_COMMON_IOUTPUTDEVICE_H
#define _METAFILE_COMMON_IOUTPUTDEVICE_H
#include "../Wmf/WmfTypes.h"
#include <string>
#include "MetaFileTypes.h"
namespace MetaFile
{
......@@ -20,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(std::wstring& wsText, unsigned int unCharsCount, int nX, int nY, int nTextW, bool bWithOutLast) = 0;
virtual void DrawString(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;
......
......@@ -2,6 +2,7 @@
#define _METAFILE_COMMON_METAFILE_H
#include "MetaFileTypes.h"
#include "MetaFileUtils.h"
#include "MetaFileObjects.h"
#include "MetaFileClip.h"
#include "../../fontengine/FontManager.h"
......
#ifndef _METAFILE_COMMON_METAFILEOBJECTS_H
#define _METAFILE_COMMON_METAFILEOBJECTS_H
#include <string>
namespace MetaFile
{
class IFont
......
#ifndef _METAFILE_COMMON_METAFILERENDERER_H
#define _METAFILE_COMMON_METAFILERENDERER_H
#include "../../../graphics/IRenderer.h"
#include "../../../graphics/structures.h"
#include "../../../graphics/Image.h"
......@@ -13,13 +12,11 @@
#include "MetaFile.h"
#include "MetaFileTypes.h"
#include "MetaFileObjects.h"
#include "../Common.h"
namespace MetaFile
{
class CMetaFileRenderer : public IOutputDevice
{
public:
CMetaFileRenderer(IMetaFileBase *pFile, IRenderer *pRenderer, double dX, double dY, double dWidth, double dHeight)
{
......@@ -60,18 +57,21 @@ namespace MetaFile
CheckEndPath();
}
void DrawBitmap(int lX, int lY, int lW, int lH, BYTE* pBuffer, unsigned int ulWidth, unsigned int ulHeight)
void DrawBitmap(int lX, int lY, int lW, int lH, BYTE* pBuffer, unsigned int unWidth, unsigned int unHeight)
{
if (!pBuffer || 0 == unWidth || 0 == unHeight)
return;
CheckEndPath();
UpdateTransform();
UpdateClip();
Aggplus::CImage oImage;
BYTE* pBufferPtr = new BYTE[4 * ulWidth * ulHeight];
oImage.Create(pBufferPtr, ulWidth, ulHeight, 4 * ulWidth);
BYTE* pBufferPtr = new BYTE[4 * unWidth * unHeight];
oImage.Create(pBufferPtr, unWidth, unHeight, 4 * unWidth);
for (int nIndex = 0, nSize = 4 * ulWidth * ulHeight; nIndex < nSize; nIndex += 4)
for (int nIndex = 0, nSize = 4 * unWidth * unHeight; nIndex < nSize; nIndex += 4)
{
pBufferPtr[0] = (unsigned char)pBuffer[nIndex + 0];
pBufferPtr[1] = (unsigned char)pBuffer[nIndex + 1];
......@@ -84,7 +84,7 @@ 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(std::wstring& wsText, unsigned int ulCharsCount, int lX, int lY, int nTextW, bool bWithOutLast)
void DrawString(std::wstring& wsText, unsigned int ulCharsCount, int lX, int lY, int nTextW, bool bWithOutLast)
{
CheckEndPath();
......
#ifndef _METAFILE_COMMON_METAFILETYPES_H
#define _METAFILE_COMMON_METAFILETYPES_H
#include <string>
#include "../../../common/String.h"
#ifndef BYTE
typedef unsigned char BYTE;
#endif
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#ifndef NULL
#define NULL 0
#endif
#if !defined (_WIN32) && !defined(_WIN64)
#define BLACKONWHITE 1
#define WHITEONBLACK 2
#define COLORONCOLOR 3
#define HALFTONE 4
#define MAXSTRETCHBLTMODE 4
#define BLACKONWHITE 1
#define WHITEONBLACK 2
#define COLORONCOLOR 3
#define HALFTONE 4
#define MAXSTRETCHBLTMODE 4
#define PT_CLOSEFIGURE 0x01
#define PT_LINETO 0x02
#define PT_BEZIERTO 0x04
#define PT_MOVETO 0x06
#ifndef _MAC
#define ENHMETA_SIGNATURE 0x464D4520
#else
#define ENHMETA_SIGNATURE 0x20454D46
#endif
#endif
#define MWT_IDENTITY 0x01
......@@ -15,9 +40,197 @@
#define MWT_RIGHTMULTIPLY 0x03
#define MWT_SET 0x04
//---------------------------------------------------------------------------------------------------
// Modes for CWmfFile.SetMapMode
//---------------------------------------------------------------------------------------------------
#define MM_TEXT 1
#define MM_LOMETRIC 2
#define MM_HIMETRIC 3
#define MM_LOENGLISH 4
#define MM_HIENGLISH 5
#define MM_TWIPS 6
#define MM_ISOTROPIC 7
#define MM_ANISOTROPIC 8
#define MM_DPI 9
#define RGN_AND 1
#define RGN_OR 2
#define RGN_XOR 3
#define RGN_DIFF 4
#define RGN_COPY 5
//--------------------------------------------------------------------------------------------------
// From wingdi.h
//--------------------------------------------------------------------------------------------------
/* PolyFill() Modes */
#define ALTERNATE 1
#define WINDING 2
#define POLYFILL_LAST 2
/* Background Modes */
#define TRANSPARENT 1
#define OPAQUE 2
#define BKMODE_LAST 2
/* Brush Styles */
#define BS_SOLID 0
#define BS_NULL 1
#define BS_HOLLOW BS_NULL
#define BS_HATCHED 2
#define BS_PATTERN 3
#define BS_INDEXED 4
#define BS_DIBPATTERN 5
#define BS_DIBPATTERNPT 6
#define BS_PATTERN8X8 7
#define BS_DIBPATTERN8X8 8
#define BS_MONOPATTERN 9
/* Hatch Styles */
#define HS_HORIZONTAL 0 /* ----- */
#define HS_VERTICAL 1 /* ||||| */
#define HS_FDIAGONAL 2 /* \\\\\ */
#define HS_BDIAGONAL 3 /* ///// */
#define HS_CROSS 4 /* +++++ */
#define HS_DIAGCROSS 5 /* xxxxx */
/* Pen Styles */
#define PS_SOLID 0
#define PS_DASH 1 /* ------- */
#define PS_DOT 2 /* ....... */
#define PS_DASHDOT 3 /* _._._._ */
#define PS_DASHDOTDOT 4 /* _.._.._ */
#define PS_NULL 5
#define PS_INSIDEFRAME 6
#define PS_USERSTYLE 7
#define PS_ALTERNATE 8
#define PS_STYLE_MASK 0x0000000F
#define PS_ENDCAP_ROUND 0x00000000
#define PS_ENDCAP_SQUARE 0x00000100
#define PS_ENDCAP_FLAT 0x00000200
#define PS_ENDCAP_MASK 0x00000F00
#define PS_JOIN_ROUND 0x00000000
#define PS_JOIN_BEVEL 0x00001000
#define PS_JOIN_MITER 0x00002000
#define PS_JOIN_MASK 0x0000F000
#define PS_COSMETIC 0x00000000
#define PS_GEOMETRIC 0x00010000
#define PS_TYPE_MASK 0x000F0000
/* Text Alignment Options */
#define TA_NOUPDATECP 0
#define TA_UPDATECP 1
#define TA_LEFT 0
#define TA_RIGHT 2
#define TA_CENTER 6
#define TA_TOP 0
#define TA_BOTTOM 8
#define TA_BASELINE 24
/* Binary raster ops */
#define R2_BLACK 1 /* 0 */
#define R2_NOTMERGEPEN 2 /* DPon */
#define R2_MASKNOTPEN 3 /* DPna */
#define R2_NOTCOPYPEN 4 /* PN */
#define R2_MASKPENNOT 5 /* PDna */
#define R2_NOT 6 /* Dn */
#define R2_XORPEN 7 /* DPx */
#define R2_NOTMASKPEN 8 /* DPan */
#define R2_MASKPEN 9 /* DPa */
#define R2_NOTXORPEN 10 /* DPxn */
#define R2_NOP 11 /* D */
#define R2_MERGENOTPEN 12 /* DPno */
#define R2_COPYPEN 13 /* P */
#define R2_MERGEPENNOT 14 /* PDno */
#define R2_MERGEPEN 15 /* DPo */
#define R2_WHITE 16 /* 1 */
#define R2_LAST 16
/* Ternary raster operations */
#define SRCCOPY (DWORD)0x00CC0020 /* dest = source */
#define SRCPAINT (DWORD)0x00EE0086 /* dest = source OR dest */
#define SRCAND (DWORD)0x008800C6 /* dest = source AND dest */
#define SRCINVERT (DWORD)0x00660046 /* dest = source XOR dest */
#define SRCERASE (DWORD)0x00440328 /* dest = source AND (NOT dest ) */
#define NOTSRCCOPY (DWORD)0x00330008 /* dest = (NOT source) */
#define NOTSRCERASE (DWORD)0x001100A6 /* dest = (NOT src) AND (NOT dest) */
#define MERGECOPY (DWORD)0x00C000CA /* dest = (source AND pattern) */
#define MERGEPAINT (DWORD)0x00BB0226 /* dest = (NOT source) OR dest */
#define PATCOPY (DWORD)0x00F00021 /* dest = pattern */
#define PATPAINT (DWORD)0x00FB0A09 /* dest = DPSnoo */
#define PATINVERT (DWORD)0x005A0049 /* dest = pattern XOR dest */
#define DSTINVERT (DWORD)0x00550009 /* dest = (NOT dest) */
#define BLACKNESS (DWORD)0x00000042 /* dest = BLACK */
#define WHITENESS (DWORD)0x00FF0062 /* dest = WHITE */
/* Object Definitions for EnumObjects() */
#define OBJ_PEN 1
#define OBJ_BRUSH 2
#define OBJ_DC 3
#define OBJ_METADC 4
#define OBJ_PAL 5
#define OBJ_FONT 6
#define OBJ_BITMAP 7
#define OBJ_REGION 8
#define OBJ_METAFILE 9
#define OBJ_MEMDC 10
#define OBJ_EXTPEN 11
#define OBJ_ENHMETADC 12
#define OBJ_ENHMETAFILE 13
#define OBJ_COLORSPACE 14
#define ANSI_CHARSET 0
#define DEFAULT_CHARSET 1
#define SYMBOL_CHARSET 2
#define SHIFTJIS_CHARSET 128
#define HANGEUL_CHARSET 129
#define HANGUL_CHARSET 129
#define GB2312_CHARSET 134
#define CHINESEBIG5_CHARSET 136
#define OEM_CHARSET 255
#define JOHAB_CHARSET 130
#define HEBREW_CHARSET 177
#define ARABIC_CHARSET 178
#define GREEK_CHARSET 161
#define TURKISH_CHARSET 162
#define VIETNAMESE_CHARSET 163
#define THAI_CHARSET 222
#define EASTEUROPE_CHARSET 238
#define RUSSIAN_CHARSET 204
#define MAC_CHARSET 77
#define BALTIC_CHARSET 186
/* constants for the biCompression field */
#define BI_RGB 0L
#define BI_RLE8 1L
#define BI_RLE4 2L
#define BI_BITFIELDS 3L
#define BI_JPEG 4L
#define BI_PNG 5L
#define LAYOUT_LTR 0x0000
#define LAYOUT_RTL 0x0001
#define LAYOUT_BITMAPORIENTATIONPRESERVED 0x0008
namespace MetaFile
{
enum EMetaFileBitCount
{
BI_BITCOUNT_0 = 0x0000,
BI_BITCOUNT_1 = 0x0001,
BI_BITCOUNT_2 = 0x0004,
BI_BITCOUNT_3 = 0x0008,
BI_BITCOUNT_4 = 0x0010,
BI_BITCOUNT_5 = 0x0018,
BI_BITCOUNT_6 = 0x0020
};
struct TEmfPointL;
struct TWmfPointS;
struct TWmfRect;
......
#include "Common.h"
#include "MetaFileUtils.h"
#include "../../raster/ImageFileFormatChecker.h"
#include "../../raster/BgraFrame.h"
#include <time.h>
#define U_TO_UTF8(val) NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(val.c_str(), val.length())
namespace MetaFile
{
{
unsigned char GetLowestBit(unsigned int ulValue)
{
if (0 == ulValue)
......@@ -100,7 +104,7 @@ namespace MetaFile
std::wstring wsTempFileName;
FILE* pTempFile = NULL;
if (!WmfOpenTempFile(&wsTempFileName, &pTempFile, L"wb", L".wmf0", NULL))
if (!OpenTempFile(&wsTempFileName, &pTempFile, L"wb", L".wmf0", NULL))
return false;
::fwrite(pBuffer, 1, unImageSize, pTempFile);
......@@ -110,18 +114,20 @@ namespace MetaFile
oFrame.OpenFile(wsTempFileName);
// TODO: .
NSFile::CFileBinary::Remove(wsTempFileName);
NSFile::CFileBinary::Remove(wsTempFileName);
return false;
}
else if (BI_BITCOUNT_1 == ushBitCount)
{
// , 2-
TRgbQuad oColor1, oColor2;
oHeaderStream >> oColor1 >> oColor2;
if (oHeaderStream.CanRead() >= 8)
oHeaderStream >> oColor1 >> oColor2;
//
int lCalcLen = (((nWidth * ushPlanes * ushBitCount + 31) & ~31) / 8) * abs(nHeight);
if (lCalcLen > lBufLen)
if (lCalcLen > lBufLen)
return false;
pBgraBuffer = new BYTE[nWidth * abs(nHeight) * 4 * sizeof(BYTE)];
......@@ -151,8 +157,13 @@ namespace MetaFile
{
int nByte = *pBuffer; pBuffer++; lBufLen--;
int nBitCount = 128;
int nAlpha = 255;
if (nX == nWidthBytes - 1)
{
// ,
nBitCount = nLastBitCount;
nAlpha = 0;
}
for (int nBitIndex = nBitCount; nBitIndex > 0; nBitIndex /= 2)
{
......@@ -161,7 +172,7 @@ namespace MetaFile
pBgraBuffer[nIndex + 0] = pColor->b;
pBgraBuffer[nIndex + 1] = pColor->g;
pBgraBuffer[nIndex + 2] = pColor->r;
pBgraBuffer[nIndex + 3] = 255;
pBgraBuffer[nIndex + 3] = nAlpha;
nIndex += 4;
}
}
......@@ -180,17 +191,22 @@ namespace MetaFile
{
int nByte = *pBuffer; pBuffer++; lBufLen--;
int nBitCount = 128;
int nAlpha = 255;
if (nX == nWidthBytes - 1)
{
// ,
nBitCount = nLastBitCount;
nAlpha = 0;
}
for (int nBitIndex = nBitCount; nBitIndex > 0; nBitIndex /= 2)
{
int nBit = (nByte & nBitIndex);
TRgbQuad* pColor = (nBit ? &oColor2 : &oColor1);
pBgraBuffer[nIndex + 0] = pColor->b;
pBgraBuffer[nIndex + 1] = pColor->g;
pBgraBuffer[nIndex + 2] = pColor->r;
pBgraBuffer[nIndex + 3] = 255;
pBgraBuffer[nIndex + 0] = pColor->b;
pBgraBuffer[nIndex + 1] = pColor->g;
pBgraBuffer[nIndex + 2] = pColor->r;
pBgraBuffer[nIndex + 3] = nAlpha;
nIndex += 4;
}
}
......@@ -386,10 +402,10 @@ namespace MetaFile
BYTE nByte = *pBuffer; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 0] = oColorTable[nByte].b;
pBgraBuffer[nIndex + 0] = oColorTable[nByte].b;
pBgraBuffer[nIndex + 1] = oColorTable[nByte].g;
pBgraBuffer[nIndex + 2] = oColorTable[nByte].r;
pBgraBuffer[nIndex + 3] = 255;
pBgraBuffer[nIndex + 2] = oColorTable[nByte].r;
pBgraBuffer[nIndex + 3] = 255;
}
pBuffer += nAdd; lBufLen -= nAdd;
}
......@@ -578,7 +594,7 @@ namespace MetaFile
// ,
}
else if (BI_BITFIELDS == unCompression)
{
{
if (oHeaderStream.CanRead() < 12)
return false;
......@@ -644,9 +660,9 @@ namespace MetaFile
}
else
{
pBgraBuffer[nIndex + 0] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 1] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 2] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 0] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 1] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 2] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 3] = 255; pBuffer++; lBufLen--; // ,
}
}
......@@ -683,9 +699,9 @@ namespace MetaFile
}
else
{
pBgraBuffer[nIndex + 0] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 1] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 2] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 0] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 1] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 2] = pBuffer[0]; pBuffer++; lBufLen--;
pBgraBuffer[nIndex + 3] = 255; pBuffer++; lBufLen--; // ,
}
}
......@@ -711,7 +727,7 @@ namespace MetaFile
}
return false;
}
}
void ReadImage(BYTE* pHeaderBuffer, unsigned int ulHeaderBufferLen, BYTE* pImageBuffer, unsigned int ulImageBufferLen, BYTE** ppDstBuffer, unsigned int* pulWidth, unsigned int* pulHeight)
{
if (ulHeaderBufferLen <= 0 || NULL == pHeaderBuffer || NULL == pImageBuffer || ulImageBufferLen < 0)
......@@ -751,18 +767,40 @@ namespace MetaFile
ReadImageCoreHeader(pImageBuffer + 4, unHeaderSize - 4, pImageBuffer + unHeaderSize, unBufferLen - unHeaderSize, ppDstBuffer, punWidth, punHeight);
else // BitmapInfoHeader
{
int nWidth;
int nHeight;
unsigned short ushPlanes;
unsigned short ushBitCount;
unsigned int unCompression;
unsigned int unImageSize;
unsigned int unXPelsPerMeter;
unsigned int unYPelsPerMeter;
unsigned int unColorUsed;
oHeaderStream.Skip(10);
unsigned int unColorImportant;
oHeaderStream >> nWidth;
oHeaderStream >> nHeight;
oHeaderStream >> ushPlanes;
oHeaderStream >> ushBitCount;
oHeaderStream.Skip(16);
oHeaderStream >> unCompression;
oHeaderStream >> unImageSize;
oHeaderStream >> unXPelsPerMeter;
oHeaderStream >> unYPelsPerMeter;
oHeaderStream >> unColorUsed;
oHeaderStream >> unColorImportant;
if (DIB_RGB_COLORS == unColorUsage)
{
if (0 == unColorUsed && BI_BITCOUNT_1 == ushBitCount)
int lCalcLen = (((nWidth * ushPlanes * ushBitCount + 31) & ~31) / 8) * abs(nHeight);
int nAvailableLen = (unBufferLen - unHeaderSize) - lCalcLen - unColorUsed * 4;
if (nAvailableLen < 0)
return;
if (0 == unColorUsed && BI_BITCOUNT_1 == ushBitCount && nAvailableLen >= 8)
unColorUsed = 2;
else if (0 == unColorUsed && BI_BITCOUNT_3 == ushBitCount)
else if (0 == unColorUsed && BI_BITCOUNT_3 == ushBitCount && nAvailableLen >= 1024)
unColorUsed = 256;
unHeaderSize += 4 * unColorUsed; // RGBQuad
......@@ -799,7 +837,7 @@ namespace MetaFile
double dDist = sqrt((double)(nX - dX0) * (nX - dX0) + (nY - dY0) * (nY - dY0));
double dRadAngle = asin(abs(nY - dY0) / dDist);
double dAngle = dRadAngle * 180 / 3.1415926;
double dAngle = dRadAngle * 180 / 3.14159265358979323846;
switch (nQuarter)
{
case 1: dAngle = 180 - dAngle; break;
......@@ -842,4 +880,96 @@ 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;
}
bool OpenTempFile(std::wstring *pwsName, FILE **ppFile, wchar_t *wsMode, wchar_t *wsExt, wchar_t *wsFolder)
{
std::wstring wsTemp, wsFileName;
FILE *pTempFile = NULL;
#if defined(_WIN32) || defined (_WIN64)
wchar_t *wsTempDir;
if ((wsTempDir = _wgetenv(L"TEMP")) && (wsFolder == NULL))
{
wsTemp = std::wstring(wsTempDir);
#else
char *wsTempDirA;
if ((wsTempDirA = getenv("TEMP")) && (wsFolder == NULL))
{
std::wstring wsTempDir = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)wsTempDirA, strlen(wsTempDirA));
wsTemp = wsTempDir.c_str();
#endif
wsTemp.append(L"/");
}
else if (wsFolder != NULL)
{
wsTemp = std::wstring(wsFolder);
wsTemp.append(L"/");
}
else
{
wsTemp = L"";
}
wsTemp.append(L"x");
int nTime = (int)time(NULL);
for (int nIndex = 0; nIndex < 1000; ++nIndex)
{
wsFileName = wsTemp;
#if defined(_WIN32) || defined (_WIN64)
wchar_t buff[32] ={};
_itow(nTime + nIndex, buff, 10);
wsFileName.append(buff, wcslen(buff));
#else
wsFileName.append(std::to_wstring(nTime + nIndex));
#endif
if (wsExt)
{
wsFileName.append(wsExt);
}
#if defined (_WIN32) || defined (_WIN64)
if (!(pTempFile = _wfopen(wsFileName.c_str(), L"r")))
{
if (!(pTempFile = _wfopen(wsFileName.c_str(), wsMode)))
#else
std::string sFileName = U_TO_UTF8(wsFileName);
if (!(pTempFile = fopen(sFileName.c_str(), "r")))
{
std::wstring strMode(wsMode);
std::string sMode = U_TO_UTF8(strMode);
if (!(pTempFile = fopen(sFileName.c_str(), sMode.c_str())))
#endif
{
return FALSE;
}
*pwsName = wsFileName;
*ppFile = pTempFile;
return TRUE;
}
fclose(pTempFile);
}
return FALSE;
}
}
#ifndef _METAFILE_WMF_EMF_COMMON_H
#define _METAFILE_WMF_EMF_COMMON_H
#ifndef _METAFILE_COMMON_METAFILEUTILS_H
#define _METAFILE_COMMON_METAFILEUTILS_H
#ifndef BYTE
typedef unsigned char BYTE;
#endif
#include "MetaFileTypes.h"
#ifndef NULL
#define NULL 0
#endif
#include "../Emf/EmfTypes.h"
#include "../Wmf/WmfTypes.h"
#include "../Emf/EmfObjects.h"
#include "../Wmf/WmfObjects.h"
#include <algorithm>
#include "Emf/EmfTypes.h"
#include "Wmf/WmfTypes.h"
#include "Wmf/WmfUtils.h"
#include "Emf/EmfObjects.h"
#include "Wmf/WmfObjects.h"
namespace MetaFile
{
#define METAFILE_RGBA(r, g, b) ((DWORD)( ( (BYTE)(r) )| ( ( (BYTE)(g) ) << 8 ) | ( ( (BYTE)(b) ) << 16 ) | ( (BYTE)(0) << 24 ) ) )
#define METAFILE_RGBA(r, g, b) ((DWORD)( ( (BYTE)(r) )| ( ( (BYTE)(g) ) << 8 ) | ( ( (BYTE)(b) ) << 16 ) | ( (BYTE)(0) << 24 ) ) )
struct TRgbQuad
struct TRgbQuad
{
unsigned char r;
unsigned char g;
unsigned char b;
TRgbQuad()
{
r = 0;
g = 0;
b = 0;
}
};
class CDataStream
......@@ -224,10 +223,10 @@ namespace MetaFile
}
CDataStream& operator>>(TEmfColor& oColor)
{
*this >> oColor.r;
*this >> oColor.g;
*this >> oColor.b;
*this >> oColor.a;
*this >> oColor.r;
*this >> oColor.g;
*this >> oColor.b;
*this >> oColor.a;
return *this;
}
......@@ -416,7 +415,7 @@ namespace MetaFile
*this >> oBitmap.cbBmi;
*this >> oBitmap.offBits;
*this >> oBitmap.cbBits;
return *this;
}
CDataStream& operator>>(TEmfLogPaletteEntry& oEntry)
......@@ -456,10 +455,10 @@ namespace MetaFile
}
CDataStream& operator>>(TRgbQuad& oRGB)
{
*this >> oRGB.b;
*this >> oRGB.g;
*this >> oRGB.r;
Skip(1); // reserved
*this >> oRGB.b;
*this >> oRGB.g;
*this >> oRGB.r;
Skip(1); // reserved
return *this;
}
......@@ -571,7 +570,7 @@ namespace MetaFile
}
oText.TextString = pUnicode;
}
return *this;
}
CDataStream& operator>>(TEmfAlphaBlend& oBitmap)
......@@ -738,7 +737,7 @@ namespace MetaFile
else
{
oScan.ScanLines = NULL;
}
}
*this >> oScan.Count2;
return *this;
......@@ -941,6 +940,6 @@ namespace MetaFile
void ReadImage(BYTE* pImageBuffer, unsigned int unBufferLen, unsigned int unColorUsage, BYTE** ppDstBuffer, unsigned int* punWidth, unsigned int* punHeight);
double GetEllipseAngle(int nL, int nT, int nR, int nB, int nX, int nY);
void ProcessRasterOperation(unsigned int unRasterOperation, BYTE** ppBgra, unsigned int unWidth, unsigned int unHeight);
bool OpenTempFile(std::wstring *pwsName, FILE **ppFile, wchar_t *wsMode, wchar_t *wsExt, wchar_t *wsFolder);
};
#endif //_METAFILE_WMF_EMF_COMMON_H
#endif // _METAFILE_COMMON_METAFILEUTILS_H
\ No newline at end of file
#ifndef _METAFILE_EMF_EMFFILE_H
#define _METAFILE_EMF_EMFFILE_H
#include "../Wmf/WmfUtils.h"
#include "../Wmf/WmfTypes.h"
#include "../../../common/String.h"
#include "../../../fontengine/FontManager.h"
#include "../Common.h"
#include "../Common/MetaFile.h"
#include "EmfTypes.h"
#include "EmfPlayer.h"
#include "EmfPath.h"
#include "../../../fontengine/FontManager.h"
#include <iostream>
#include "../Common/MetaFile.h"
#include "../../../common/String.h"
#include "../../../common/File.h"
namespace MetaFile
{
class CEmfFile : virtual public IMetaFileBase
......@@ -33,11 +27,10 @@ namespace MetaFile
ClearFile();
};
TEmfRectL* GetBounds()
TEmfRectL* GetBounds()
{
return &m_oHeader.oFrame;
}
}
void PlayMetaFile()
{
if (!m_oStream.IsValid())
......@@ -188,7 +181,6 @@ namespace MetaFile
//-----------------------------------------------------------
default:
{
std::cout << ulType << " ";
Read_EMR_UNKNOWN();
break;
}
......@@ -499,7 +491,7 @@ namespace MetaFile
if (m_pOutput)
{
m_pOutput->DrawText(wsString, unCharsCount, nX, nY, nTextW, bWithOutLast);
m_pOutput->DrawString(wsString, unCharsCount, nX, nY, nTextW, bWithOutLast);
}
}
void DrawTextA(TEmfEmrText& oText)
......
#include "EmfObjects.h"
#include "../../../raster/ImageFileFormatChecker.h"
#include "../../../graphics/Image.h"
#include "../Common.h"
#include "../Common/MetaFileUtils.h"
#include "EmfObjects.h"
namespace MetaFile
{
......@@ -51,7 +53,7 @@ namespace MetaFile
FILE *pTempFile = NULL;
std::wstring wsTempFileName;
if (!WmfOpenTempFile(&wsTempFileName, &pTempFile, L"wb", L".emf0", NULL))
if (!OpenTempFile(&wsTempFileName, &pTempFile, L"wb", L".emf0", NULL))
return;
::fclose(pTempFile);
......
......@@ -2,8 +2,6 @@
#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"
......
#ifndef _METAFILE_EMF_EMFPLAYER_H
#define _METAFILE_EMF_EMFPLAYER_H
#include <vector>
#include <map>
#include "EmfTypes.h"
#include "EmfObjects.h"
#include "EmfClip.h"
#include <vector>
#include <map>
namespace MetaFile
{
class CEmfFile;
......
......@@ -4,9 +4,6 @@
#include "../../raster/BgraFrame.h"
#include "Common/MetaFileRenderer.h"
#ifndef NEW_WMF
#include "Wmf/RendererOutput.h"
#endif
namespace MetaFile
{
......@@ -50,12 +47,7 @@ namespace MetaFile
// Wmf
m_oWmfFile.OpenFromFile(wsFilePath);
#ifdef NEW_WMF
m_oWmfFile.Scan();
#else
m_oWmfFile.Scan(&m_oWmfRect);
#endif
if (!m_oWmfFile.CheckError())
{
......@@ -89,52 +81,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);
pRenderer->get_DpiY(&dRendererDpiY);
CRendererOutput oWmfOut(&m_oWmfFile, pRenderer, dX, dY, dWidth, dHeight);
double fSrcWidth, fSrcHeight;
float fW, fH;
m_oWmfFile.GetSize(&fW, &fH);
m_oWmfFile.GetDisplaySize(&fSrcWidth, &fSrcHeight, dRendererDpix, dRendererDpiY);
//m_oWmfFile.GetDisplaySize( &fSrcWidth, &fSrcHeight, 25.4, 25.4 );
TWmfRectF oRectB = m_oWmfFile.GetBounds();
//double dW = m_oRect.oBR.fX - m_oRect.oTL.fX;
//double dH = m_oRect.oBR.fY - m_oRect.oTL.fY;
double dW = oRectB.oBR.fX - oRectB.oTL.fX;
double dH = oRectB.oBR.fY - oRectB.oTL.fY;
double dScaleX = dWidth / dW;//fSrcWidth;
double dScaleY = dHeight / dH;//fSrcHeight;
//double dScaleX = dWidth / fSrcWidth;
//double dScaleY = dHeight / fSrcHeight;
double dSrcDpiX, dSrcDpiY;
m_oWmfFile.GetDpi(&dSrcDpiX, &dSrcDpiY);
double dDpiKoefX = dRendererDpix / dSrcDpiX;
double dDpiKoefY = dRendererDpiY / dSrcDpiY;
double dDpi = dSrcDpiY * fSrcHeight / fH;
oWmfOut.SetDpi(dRendererDpix, dDpi);
oWmfOut.SetWmfRect(oRectB);
oWmfOut.SetScales(dScaleX, dScaleY);
m_oWmfFile.SetOutputDevice(&oWmfOut);
TWmfRectF oRect;
m_oWmfFile.Play(&oRect);
#endif
}
else if (c_lMetaEmf == m_lType)
{
......@@ -149,11 +98,11 @@ namespace MetaFile
void CMetaFile::Close()
{
m_oWmfFile.Close();
//m_oEmfFile.Close();
m_oEmfFile.Close();
m_lType = 0;
};
int CMetaFile::GetType()
int CMetaFile::GetType()
{
return m_lType;
}
......@@ -161,19 +110,11 @@ namespace MetaFile
{
if (c_lMetaWmf == m_lType)
{
#ifdef NEW_WMF
const 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)
{
......
......@@ -34,7 +34,6 @@ namespace MetaFile
CApplicationFonts* m_pAppFonts;
CFontManager* m_pFontManager;
CWmfFile m_oWmfFile;
TWmfRectF m_oWmfRect;
CEmfFile m_oEmfFile;
int m_lType;
};
......
......@@ -148,13 +148,13 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Common.h" />
<ClInclude Include="Common\MetaFileClip.h" />
<ClInclude Include="Common\MetaFileRenderer.h" />
<ClInclude Include="Common\IOutputDevice.h" />
<ClInclude Include="Common\MetaFile.h" />
<ClInclude Include="Common\MetaFileObjects.h" />
<ClInclude Include="Common\MetaFileTypes.h" />
<ClInclude Include="Common\MetaFileUtils.h" />
<ClInclude Include="Emf\EmfClip.h" />
<ClInclude Include="Emf\EmfFile.h" />
<ClInclude Include="Emf\EmfObjects.h" />
......@@ -163,26 +163,15 @@
<ClInclude Include="Emf\EmfTypes.h" />
<ClInclude Include="MetaFile.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="Wmf\RendererOutput.h" />
<ClInclude Include="Wmf\WmfCharsets.h" />
<ClInclude Include="Wmf\WmfCodePage1361.h" />
<ClInclude Include="Wmf\WmfCodePage932.h" />
<ClInclude Include="Wmf\WmfCodePage936.h" />
<ClInclude Include="Wmf\WmfCodePage949.h" />
<ClInclude Include="Wmf\WmfCodePage950.h" />
<ClInclude Include="Wmf\WmfColor.h" />
<ClInclude Include="Wmf\WmfClip.h" />
<ClInclude Include="Wmf\WmfFile.h" />
<ClInclude Include="Wmf\WmfMemory.h" />
<ClInclude Include="Wmf\WmfObjects.h" />
<ClInclude Include="Wmf\WmfOutputDevice.h" />
<ClInclude Include="Wmf\WmfPlayer.h" />
<ClInclude Include="Wmf\WmfRegion.h" />
<ClInclude Include="Wmf\WmfTypes.h" />
<ClInclude Include="Wmf\WmfUtils.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Common.cpp" />
<ClCompile Include="Common\MetaFileTypes.cpp" />
<ClCompile Include="Common\MetaFileUtils.cpp" />
<ClCompile Include="Emf\EmfClip.cpp" />
<ClCompile Include="Emf\EmfObjects.cpp" />
<ClCompile Include="Emf\EmfPath.cpp" />
......@@ -190,6 +179,7 @@
<ClCompile Include="MetaFile.cpp" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="TestMain.cpp" />
<ClCompile Include="Wmf\WmfClip.cpp" />
<ClCompile Include="Wmf\WmfObjects.cpp" />
<ClCompile Include="Wmf\WmfPlayer.cpp" />
</ItemGroup>
......
......@@ -24,48 +24,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Wmf\RendererOutput.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfCharsets.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfCodePage932.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfCodePage936.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfCodePage949.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfCodePage950.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfCodePage1361.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfColor.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfFile.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfMemory.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfOutputDevice.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfRegion.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfTypes.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfUtils.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="MetaFile.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -75,9 +39,6 @@
<ClInclude Include="Emf\EmfTypes.h">
<Filter>Emf</Filter>
</ClInclude>
<ClInclude Include="Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Emf\EmfPlayer.h">
<Filter>Emf</Filter>
</ClInclude>
......@@ -117,6 +78,12 @@
<ClInclude Include="Common\MetaFileClip.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="Wmf\WmfClip.h">
<Filter>Wmf</Filter>
</ClInclude>
<ClInclude Include="Common\MetaFileUtils.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="TestMain.cpp">
......@@ -128,9 +95,6 @@
<ClCompile Include="MetaFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Emf\EmfPlayer.cpp">
<Filter>Emf</Filter>
</ClCompile>
......@@ -152,5 +116,11 @@
<ClCompile Include="Common\MetaFileTypes.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="Wmf\WmfClip.cpp">
<Filter>Wmf</Filter>
</ClCompile>
<ClCompile Include="Common\MetaFileUtils.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
//#define _CRTDBG_LEAK_CHECK_DF
//#define _CRTDBG_LEAK_CHECK_DF
#include "stdafx.h"
#include <vector>
#include "../../fontengine/ApplicationFonts.h"
#include "MetaFile.h"
#include <Windows.h>
#include <vector>
using namespace MetaFile;
std::vector<std::wstring> GetAllFilesInFolder(std::wstring wsFolder, std::wstring wsExt)
......@@ -63,6 +62,7 @@ void ConvertFolder(CMetaFile &oMetaFile, std::wstring wsFolderPath)
}
}
#include "../../common/String.h"
void Test()
{
CApplicationFonts oFonts;
......@@ -70,7 +70,7 @@ void Test()
CMetaFile oMetaFile(&oFonts);
//ConvertFile(oMetaFile, L"D://Test Files//fulltest.wmf");
ConvertFolder(oMetaFile, L"D://Test Files//Bugs//");
ConvertFolder(oMetaFile, L"D://Test Files//Bugs//Bugs//");
}
void main()
......
This diff is collapsed.
This diff is collapsed.
#include "WmfClip.h"
namespace MetaFile
{
CWmfClip::CWmfClip()
{
}
CWmfClip::~CWmfClip()
{
Clear();
}
void CWmfClip::operator=(CWmfClip& oClip)
{
Clear();
for (unsigned int ulIndex = 0; ulIndex < oClip.m_vCommands.size(); ulIndex++)
{
CWmfClipCommandBase* pCommand = oClip.m_vCommands.at(ulIndex);
CWmfClipCommandBase* pNewCommand = NULL;
switch (pCommand->GetType())
{
case WMF_CLIPCOMMAND_INTERSECT:
{
CWmfClipCommandIntersect* pI = (CWmfClipCommandIntersect*)pCommand;
pNewCommand = new CWmfClipCommandIntersect(pI->m_shL, pI->m_shT, pI->m_shR, pI->m_shB);
break;
}
case WMF_CLIPCOMMAND_EXCLUDE:
{
CWmfClipCommandExclude* pE = (CWmfClipCommandExclude*)pCommand;
pNewCommand = new CWmfClipCommandExclude(pE->m_shL, pE->m_shT, pE->m_shR, pE->m_shB, pE->m_oBB);
break;
}
}
if (pNewCommand)
m_vCommands.push_back(pNewCommand);
}
}
void CWmfClip::Reset()
{
Clear();
}
bool CWmfClip::Intersect(short shL, short shT, short shR, short shB)
{
CWmfClipCommandBase* pCommand = new CWmfClipCommandIntersect(shL, shT, shR, shB);
if (!pCommand)
return false;
m_vCommands.push_back(pCommand);
return true;
}
bool CWmfClip::Exclude(short shL, short shT, short shR, short shB, TRect oBB)
{
CWmfClipCommandBase* pCommand = new CWmfClipCommandExclude(shL, shT, shR, shB, oBB);
if (!pCommand)
return false;
m_vCommands.push_back(pCommand);
return true;
}
void CWmfClip::Clear()
{
for (unsigned int ulIndex = 0; ulIndex < m_vCommands.size(); ulIndex++)
{
CWmfClipCommandBase* pCommand = m_vCommands.at(ulIndex);
delete pCommand;
}
m_vCommands.clear();
}
void CWmfClip::ClipOnRenderer(IOutputDevice* pOutput)
{
if (pOutput)
{
pOutput->ResetClip();
for (unsigned int ulIndex = 0; ulIndex < m_vCommands.size(); ulIndex++)
{
CWmfClipCommandBase* pCommand = m_vCommands.at(ulIndex);
switch (pCommand->GetType())
{
case WMF_CLIPCOMMAND_INTERSECT:
{
CWmfClipCommandIntersect* pIntersect = (CWmfClipCommandIntersect*)pCommand;
pOutput->StartClipPath(RGN_AND);
pOutput->MoveTo(pIntersect->m_shL, pIntersect->m_shT);
pOutput->LineTo(pIntersect->m_shR, pIntersect->m_shT);
pOutput->LineTo(pIntersect->m_shR, pIntersect->m_shB);
pOutput->LineTo(pIntersect->m_shL, pIntersect->m_shB);
pOutput->ClosePath();
pOutput->EndClipPath(RGN_AND);
break;
}
case WMF_CLIPCOMMAND_EXCLUDE:
{
CWmfClipCommandExclude* pExclude = (CWmfClipCommandExclude*)pCommand;
pOutput->StartClipPath(RGN_AND);
pOutput->MoveTo(pExclude->m_oBB.nLeft, pExclude->m_oBB.nTop);
pOutput->LineTo(pExclude->m_oBB.nRight, pExclude->m_oBB.nTop);
pOutput->LineTo(pExclude->m_oBB.nRight, pExclude->m_oBB.nBottom);
pOutput->LineTo(pExclude->m_oBB.nLeft, pExclude->m_oBB.nBottom);
pOutput->ClosePath();
pOutput->MoveTo(pExclude->m_shL, pExclude->m_shT);
pOutput->LineTo(pExclude->m_shR, pExclude->m_shT);
pOutput->LineTo(pExclude->m_shR, pExclude->m_shB);
pOutput->LineTo(pExclude->m_shL, pExclude->m_shB);
pOutput->ClosePath();
pOutput->EndClipPath(RGN_AND);
break;
}
}
}
}
}
}
\ No newline at end of file
#ifndef _METAFILE_WMF_WMFCLIP_H
#define _METAFILE_WMF_WMFCLIP_H
#include "../Common/MetaFileClip.h"
#include "../Common/IOutputDevice.h"
#include "../Common/MetaFileTypes.h"
#include <vector>
namespace MetaFile
{
typedef enum
{
WMF_CLIPCOMMAND_UNKNOWN = 0x00,
WMF_CLIPCOMMAND_INTERSECT = 0x01,
WMF_CLIPCOMMAND_EXCLUDE = 0x02
} EWmfClipCommandType;
class CWmfClipCommandBase
{
public:
CWmfClipCommandBase()
{
}
virtual ~CWmfClipCommandBase()
{
}
virtual EWmfClipCommandType GetType()
{
return WMF_CLIPCOMMAND_UNKNOWN;
}
};
class CWmfClipCommandIntersect : public CWmfClipCommandBase
{
public:
CWmfClipCommandIntersect(short shL, short shT, short shR, short shB)
{
m_shL = shL;
m_shT = shT;
m_shR = shR;
m_shB = shB;
}
~CWmfClipCommandIntersect()
{
}
EWmfClipCommandType GetType()
{
return WMF_CLIPCOMMAND_INTERSECT;
}
public:
short m_shL;
short m_shT;
short m_shR;
short m_shB;
};
class CWmfClipCommandExclude : public CWmfClipCommandBase
{
public:
CWmfClipCommandExclude(short shL, short shT, short shR, short shB, TRect oBB)
{
m_shL = shL;
m_shT = shT;
m_shR = shR;
m_shB = shB;
m_oBB = oBB;
}
~CWmfClipCommandExclude()
{
}
EWmfClipCommandType GetType()
{
return WMF_CLIPCOMMAND_EXCLUDE;
}
public:
TRect m_oBB;
short m_shL;
short m_shT;
short m_shR;
short m_shB;
};
class CWmfClip : public IClip
{
public:
CWmfClip();
~CWmfClip();
void operator=(CWmfClip& oClip);
void Reset();
bool Intersect(short shL, short shT, short shR, short shB);
bool Exclude(short shL, short shT, short shR, short shB, TRect oBB);
// IClip
void ClipOnRenderer(IOutputDevice* pOutput);
private:
void Clear();
private:
std::vector<CWmfClipCommandBase*> m_vCommands;
};
}
#endif // _METAFILE_WMF_WMFCLIP_H
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef _WMF_MEMORY_H
#define _WMF_MEMORY_H
#include <stdio.h>
#ifdef _DEBUG
//#define DebugCheckMemory
//#include <vector>
//#include <iterator>
#endif
class CWmfMemoryManager
{
public:
CWmfMemoryManager()
{
#ifdef DebugCheckMemory
m_arrDescription.clear();
m_arrMemoryList.clear();
#endif
}
~CWmfMemoryManager()
{
#ifdef DebugCheckMemory
m_arrDescription.clear();
m_arrMemoryList.clear();
#endif
}
void *Malloc(size_t unSize, std::wstring sDescription)
{
void *pAddress = malloc(unSize);
if (NULL == pAddress)
return NULL;
#ifdef DebugCheckMemory
Add(pAddress, sDescription);
#endif
return pAddress;
}
void *Realloc(void *pMemory, size_t unSize)
{
#ifdef DebugCheckMemory
std::wstring sDescription = Remove(pMemory);
#endif
void *pAddress = realloc(pMemory, unSize);
if (NULL == pAddress)
return NULL;
#ifdef DebugCheckMemory
Add(pAddress, sDescription);
#endif
return pAddress;
}
void Free(void *pMemory)
{
if (pMemory)
{
free(pMemory);
}
#ifdef DebugCheckMemory
Remove(pMemory);
#endif
}
private:
#ifdef DebugCheckMemory
void Add(void *pAddress, std::wstring sDescription)
{
m_arrDescription.push_back(sDescription);
m_arrMemoryList.push_back(pAddress);
}
std::wstring Remove(void *pAddress)
{
int nIndex = 0;
for (nIndex = 0; nIndex < m_arrMemoryList.size(); nIndex++)
{
if (pAddress == m_arrMemoryList.at(nIndex))
break;
}
if (nIndex >= m_arrMemoryList.size())
return L"";
m_arrMemoryList.erase(m_arrMemoryList.begin() + nIndex);
std::wstring sResult = m_arrDescription.at(nIndex);
m_arrDescription.erase(m_arrDescription.begin() + nIndex);
return sResult;
}
#endif
private:
#ifdef DebugCheckMemory
std::vector<void *> m_arrMemoryList;
std::vector<std::wstring> m_arrDescription;
#endif
};
#endif /* _WMF_MEMORY_H */
\ No newline at end of file
#include "WmfObjects.h"
#include "../../../raster/ImageFileFormatChecker.h"
#include "../../../graphics/Image.h"
#include "../Common.h"
#include "../Common/MetaFileUtils.h"
#include "WmfObjects.h"
namespace MetaFile
{
......@@ -60,7 +62,7 @@ namespace MetaFile
FILE *pTempFile = NULL;
std::wstring wsTempFileName;
if (!WmfOpenTempFile(&wsTempFileName, &pTempFile, L"wb", L".emf0", NULL))
if (!OpenTempFile(&wsTempFileName, &pTempFile, L"wb", L".emf0", NULL))
return;
::fclose(pTempFile);
......
#ifndef _WMF_OBJECTS_H
#define _WMF_OBJECTS_H
#ifndef _METAFILE_WMF_WMFOBJECTS_H
#define _METAFILE_WMF_WMFOBJECTS_H
#include "WmfTypes.h"
#include "WmfUtils.h"
#include "../Common/MetaFileTypes.h"
#include "../Common/MetaFileObjects.h"
#include "WmfTypes.h"
namespace MetaFile
{
typedef enum
......@@ -80,7 +81,7 @@ namespace MetaFile
}
std::wstring GetFaceName()
{
return NSFile::CUtf8Converter::GetUnicodeFromCharPtr((const char*)Facename, 32, FALSE);
return NSString::CConverter::GetUnicodeFromSingleByteString((const unsigned char*)Facename, 32);
}
int GetWeight()
{
......@@ -204,4 +205,4 @@ namespace MetaFile
};
}
#endif //_WMF_OBJECTS_H
\ No newline at end of file
#endif //_METAFILE_WMF_WMFOBJECTS_H
\ No newline at end of file
#ifndef _WMF_OUTPUT_DEVICE_H
#define _WMF_OUTPUT_DEVICE_H
#include "WmfTypes.h"
class CWmfOutputDevice
{
public:
CWmfOutputDevice() {}
virtual ~CWmfOutputDevice() {}
virtual bool IsSupportPolypolygon() { return false; }
//
virtual void Begin() = 0;
virtual void End () = 0;
virtual void Flood_Interior(TWmfFlood*) = 0;
virtual void Flood_Exterior(TWmfFlood*) = 0;
virtual void Draw_Pixel (TWmfDrawPixel*) = 0;
virtual void Draw_Pie (TWmfDrawArc*) = 0;
virtual void Draw_Chord (TWmfDrawArc*) = 0;
virtual void Draw_Arc (TWmfDrawArc*) = 0;
virtual void Draw_Ellipse (TWmfDrawArc*) = 0;
virtual void Draw_Line (TWmfDrawLine*) = 0;
virtual void Poly_Line (TWmfPolyLine*) = 0;
virtual void Draw_Polygon (TWmfPolyLine*) = 0;
virtual void Draw_Polypolygon(TWmfPolyPoly*) = 0;
virtual void Draw_Rectangle (TWmfDrawRectangle*) = 0;
virtual void Rop_Draw(TWmfROPDraw*) = 0;
virtual void Bmp_Draw(TWmfBMPDraw*) = 0;
virtual void Bmp_Read(TWmfBMPRead*) = 0;
virtual void Bmp_Free(TWmfBMP*) = 0;
virtual void Draw_Text(TWmfDrawText*) = 0;
virtual void Region_Frame(TWmfPolyRectangle*) = 0;
virtual void Region_Paint(TWmfPolyRectangle*) = 0;
virtual void Region_Clip (TWmfPolyRectangle*) = 0;
private:
};
#endif /* _WMF_OUTPUT_DEVICE_H */
\ No newline at end of file
......@@ -263,6 +263,7 @@ namespace MetaFile
pNewDC->m_ushTextAlign = m_ushTextAlign;
pNewDC->m_ushCharSpacing = m_ushCharSpacing;
pNewDC->m_oTransform.Init();
pNewDC->m_oClip = m_oClip;
return pNewDC;
}
......@@ -584,4 +585,8 @@ namespace MetaFile
{
return 0;
}
CWmfClip* CWmfDC::GetClip()
{
return &m_oClip;
}
}
\ No newline at end of file
#ifndef _WMF_PLAYER_H
#define _WMF_PLAYER_H
#ifndef _METAFILE_WMF_WMFPLAYER_H
#define _METAFILE_WMF_WMFPLAYER_H
#include "WmfObjects.h"
#include "WmfClip.h"
#include <map>
#include <vector>
#include "WmfObjects.h"
#include "../Common/MetaFileTypes.h"
namespace MetaFile
{
......@@ -97,6 +98,7 @@ namespace MetaFile
TXForm* GetTransform();
TXForm* GetInverseTransform();
unsigned int GetMiterLimit();
CWmfClip* GetClip();
private:
......@@ -129,31 +131,8 @@ namespace MetaFile
unsigned short m_ushTextAlign;
unsigned short m_ushCharSpacing;
TXForm m_oTransform;
CWmfClip m_oClip;
};
//class CEmfDC
//{
//public:
// CEmfDC();
// ~CEmfDC();
// CEmfDC* Copy();
// TEmfXForm* GetTransform();
// TEmfXForm* GetInverseTransform();
// void MultiplyTransform(TEmfXForm& oForm, unsigned int ulMode);
// void SetMiterLimit(unsigned int ulMiter);
// unsigned int GetMiterLimit();
// CEmfClip* GetClip();
// void ClipToPath(CEmfPath* pPath, unsigned int unMode);
//private:
// TEmfXForm m_oTransform;
// TEmfXForm m_oInverseTransform;
// unsigned int m_ulMiterLimit;
// CEmfClip m_oClip;
//};
}
#endif //_WMF_PLAYER_H
\ No newline at end of file
#endif //_METAFILE_WMF_WMFPLAYER_H
\ No newline at end of file
This diff is collapsed.
#ifndef _WMF_UTILS_H
#define _WMF_UTILS_H
#include "WmfTypes.h"
#include <stdio.h>
#include <time.h>
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#include "../../../common/File.h"
#define U_TO_UTF8(val) NSFile::CUtf8Converter::GetUtf8StringFromUnicode2(val.c_str(), val.length())
static 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;
}
static 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;
}
static char *WmfStrDup(const char *sString)
{
if ( NULL == sString )
return NULL;
char *sCopy = (char*)malloc( strlen(sString) + 1 );
if ( NULL == sCopy )
return NULL;
strcpy( sCopy, sString );
return sCopy;
}
static TWmfCoord WmfCoord(unsigned short ushX, unsigned short ushY)
{
TWmfCoord oPoint;
oPoint.unX = UShort_2_Long( ushX );
oPoint.unY = UShort_2_Long( ushY );
return oPoint;
}
static void PolyPoly_To_PolyLine(TWmfPolyPoly *pPolyPoly, TWmfPolyLine *pPolyLine, unsigned short ushPolyIndex)
{
unsigned short ushCount = pPolyPoly->pCount[ushPolyIndex];
if ( NULL == pPolyPoly->ppPoints )
return;
if ( ( NULL == pPolyPoly->ppPoints[ushPolyIndex] ) || ( pPolyPoly->pCount[ushPolyIndex] < 3 ) )
return;
// Избавляемся от лишних точек
while ( ( pPolyPoly->ppPoints[ushPolyIndex][0].fX == pPolyPoly->ppPoints[ushPolyIndex][ushCount - 1].fX ) && ( pPolyPoly->ppPoints[ushPolyIndex][0].fY == pPolyPoly->ppPoints[ushPolyIndex][ushCount - 1].fY ) )
{
ushCount--;
if ( ushCount < 3 )
break;
}
if ( ushCount < 3 )
return;
// Определяем последний ли полигон
bool bLast = false;
if ( ushPolyIndex < ( pPolyPoly->ushPolyCount - 1 ) )
{
if ( ( NULL == pPolyPoly->ppPoints[ushPolyIndex + 1] == 0 ) || ( pPolyPoly->pCount[ushPolyIndex + 1] < 3 ) )
{
bLast = 1;
}
}
else
{
bLast = 1;
}
if ( bLast )
{
for ( unsigned short ushPointIndex = 0; ushPointIndex < ushCount; ushPointIndex++ )
{
pPolyLine->pPoints[pPolyLine->ushCount].fX = pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fX;
pPolyLine->pPoints[pPolyLine->ushCount].fY = pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fY;
pPolyLine->ushCount++;
}
pPolyLine->pPoints[pPolyLine->ushCount].fX = pPolyPoly->ppPoints[ushPolyIndex][0].fX;
pPolyLine->pPoints[pPolyLine->ushCount].fY = pPolyPoly->ppPoints[ushPolyIndex][0].fY;
pPolyLine->ushCount++;
return;
}
// Ищем в данном полигоне точку ближающую к нулевой точке следующего полигона (т.к. этот полигон не последний, то все впорядке)
unsigned short ushMinIndex = 0;
double dMinR2;
for ( unsigned short ushPointIndex = 0; ushPointIndex < ushCount; ushPointIndex++ )
{
double dX2 = (double) pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fX - (double) pPolyPoly->ppPoints[ushPolyIndex+1][0].fX;
dX2 *= dX2;
double dY2 = (double) pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fY - (double) pPolyPoly->ppPoints[ushPolyIndex+1][0].fY;
dY2 *= dY2;
double dR2 = dX2 + dY2;
if ( 0 == ushPointIndex )
{
dMinR2 = dR2;
}
else if ( dR2 < dMinR2 )
{
dMinR2 = dR2;
ushMinIndex = ushPointIndex;
}
}
for ( unsigned short ushPointIndex = 0; ushPointIndex <= ushMinIndex; ushPointIndex++ )
{
pPolyLine->pPoints[pPolyLine->ushCount].fX = pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fX;
pPolyLine->pPoints[pPolyLine->ushCount].fY = pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fY;
pPolyLine->ushCount++;
}
PolyPoly_To_PolyLine( pPolyPoly, pPolyLine, (unsigned short)(ushPolyIndex + 1) );
for ( unsigned short ushPointIndex = ushMinIndex; ushPointIndex < ushCount; ushPointIndex++ )
{
pPolyLine->pPoints[pPolyLine->ushCount].fX = pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fX;
pPolyLine->pPoints[pPolyLine->ushCount].fY = pPolyPoly->ppPoints[ushPolyIndex][ushPointIndex].fY;
pPolyLine->ushCount++;
}
pPolyLine->pPoints[pPolyLine->ushCount].fX = pPolyPoly->ppPoints[ushPolyIndex][0].fX;
pPolyLine->pPoints[pPolyLine->ushCount].fY = pPolyPoly->ppPoints[ushPolyIndex][0].fY;
pPolyLine->ushCount++;
}
static bool WmfOpenTempFile(std::wstring *pwsName, FILE **ppFile, wchar_t *wsMode, wchar_t *wsExt, wchar_t *wsFolder)
{
std::wstring wsTemp, wsFileName;
FILE *pTempFile = NULL;
#if defined(_WIN32) || defined (_WIN64)
wchar_t *wsTempDir;
if ((wsTempDir = _wgetenv(L"TEMP")) && (wsFolder == NULL))
{
wsTemp = std::wstring(wsTempDir);
#else
char *wsTempDirA;
if ( ( wsTempDirA = getenv( "TEMP" ) ) && ( wsFolder == NULL ) )
{
std::wstring wsTempDir = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)wsTempDirA, strlen(wsTempDirA));
wsTemp = wsTempDir.c_str();
#endif
wsTemp.append(L"/");
}
else if (wsFolder != NULL)
{
wsTemp = std::wstring(wsFolder);
wsTemp.append(L"/");
}
else
{
wsTemp = L"";
}
wsTemp.append(L"x");
int nTime = (int)time(NULL);
for (int nIndex = 0; nIndex < 1000; ++nIndex)
{
wsFileName = wsTemp;
#if defined(_WIN32) || defined (_WIN64)
wchar_t buff[32] ={};
_itow(nTime + nIndex, buff, 10);
wsFileName.append(buff, wcslen(buff));
#else
wsFileName.append(std::to_wstring(nTime + nIndex));
#endif
if (wsExt)
{
wsFileName.append(wsExt);
}
#if defined (_WIN32) || defined (_WIN64)
if (!(pTempFile = _wfopen(wsFileName.c_str(), L"r")))
{
if (!(pTempFile = _wfopen(wsFileName.c_str(), wsMode)))
#else
std::string sFileName = U_TO_UTF8(wsFileName);
if ( !( pTempFile = fopen( sFileName.c_str(), "r" ) ) )
{
std::wstring strMode (wsMode);
std::string sMode = U_TO_UTF8(strMode);
if ( !( pTempFile = fopen( sFileName.c_str(), sMode.c_str() ) ) )
#endif
{
return FALSE;
}
*pwsName = wsFileName;
*ppFile = pTempFile;
return TRUE;
}
fclose(pTempFile);
}
return FALSE;
}
#endif /* _WMF_UTILS_H */
#pragma once
#include <stdio.h>
#pragma comment(lib, "../../Qt_build/graphics/project/debug/graphics.lib")
\ 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