📄 scemftxtutils.cpp
字号:
/*
* This file is part of the EMFexplorer projet.
* Copyright (C) 2004 Smith Charles.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* Extension: for commercial use, apply the Equity Public License, which
* adds to the normal terms of the GLPL a condition of donation to the author.
* If you are interested in support for this source code,
* contact Smith Charles <smith.charles@free.fr> for more information.
*/
#include "stdafx.h"
#include "SCEMFTxtUtils.h"
#include "SCEMFDefs.h"
#include "SCGenInclude.h"
#include SC_INC_WINLIB(SCGDIUtils.h)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////
// Record names
//
#define SC_UNKNOWN_RECNAME _T("EMR_UNKNOWN")
LPTSTR s_SCEMFRecNames[] =
{
_T("error"),
_T("EMR_HEADER"),
_T("EMR_POLYBEZIER"),
_T("EMR_POLYGON"),
_T("EMR_POLYLINE"),
_T("EMR_POLYBEZIERTO"),
_T("EMR_POLYLINETO"),
_T("EMR_POLYPOLYLINE"),
_T("EMR_POLYPOLYGON"),
_T("EMR_SETWINDOWEXTEX"),
_T("EMR_SETWINDOWORGEX"),
_T("EMR_SETVIEWPORTEXTEX"),
_T("EMR_SETVIEWPORTORGEX"),
_T("EMR_SETBRUSHORGEX"),
_T("EMR_EOF"),
_T("EMR_SETPIXELV"),
_T("EMR_SETMAPPERFLAGS"),
_T("EMR_SETMAPMODE"),
_T("EMR_SETBKMODE"),
_T("EMR_SETPOLYFILLMODE"),
_T("EMR_SETROP2"),
_T("EMR_SETSTRETCHBLTMODE"),
_T("EMR_SETTEXTALIGN"),
_T("EMR_SETCOLORADJUSTMENT"),
_T("EMR_SETTEXTCOLOR"),
_T("EMR_SETBKCOLOR"),
_T("EMR_OFFSETCLIPRGN"),
_T("EMR_MOVETOEX"),
_T("EMR_SETMETARGN"),
_T("EMR_EXCLUDECLIPRECT"),
_T("EMR_INTERSECTCLIPRECT"),
_T("EMR_SCALEVIEWPORTEXTEX"),
_T("EMR_SCALEWINDOWEXTEX"),
_T("EMR_SAVEDC"),
_T("EMR_RESTOREDC"),
_T("EMR_SETWORLDTRANSFORM"),
_T("EMR_MODIFYWORLDTRANSFORM"),
_T("EMR_SELECTOBJECT"),
_T("EMR_CREATEPEN"),
_T("EMR_CREATEBRUSHINDIRECT"),
_T("EMR_DELETEOBJECT"),
_T("EMR_ANGLEARC"),
_T("EMR_ELLIPSE"),
_T("EMR_RECTANGLE"),
_T("EMR_ROUNDRECT"),
_T("EMR_ARC"),
_T("EMR_CHORD"),
_T("EMR_PIE"),
_T("EMR_SELECTPALETTE"),
_T("EMR_CREATEPALETTE"),
_T("EMR_SETPALETTEENTRIES"),
_T("EMR_RESIZEPALETTE"),
_T("EMR_REALIZEPALETTE"),
_T("EMR_EXTFLOODFILL"),
_T("EMR_LINETO"),
_T("EMR_ARCTO"),
_T("EMR_POLYDRAW"),
_T("EMR_SETARCDIRECTION"),
_T("EMR_SETMITERLIMIT"),
_T("EMR_BEGINPATH"),
_T("EMR_ENDPATH"),
_T("EMR_CLOSEFIGURE"),
_T("EMR_FILLPATH"),
_T("EMR_STROKEANDFILLPATH"),
_T("EMR_STROKEPATH"),
_T("EMR_FLATTENPATH"),
_T("EMR_WIDENPATH"),
_T("EMR_SELECTCLIPPATH"),
_T("EMR_ABORTPATH"),
_T("error"),
_T("EMR_GDICOMMENT"),
_T("EMR_FILLRGN"),
_T("EMR_FRAMERGN"),
_T("EMR_INVERTRGN"),
_T("EMR_PAINTRGN"),
_T("EMR_EXTSELECTCLIPRGN"),
_T("EMR_BITBLT"),
_T("EMR_STRETCHBLT"),
_T("EMR_MASKBLT"),
_T("EMR_PLGBLT"),
_T("EMR_SETDIBITSTODEVICE"),
_T("EMR_STRETCHDIBITS"),
_T("EMR_EXTCREATEFONTINDIRECTW"),
_T("EMR_EXTTEXTOUTA"),
_T("EMR_EXTTEXTOUTW"),
_T("EMR_POLYBEZIER16"),
_T("EMR_POLYGON16"),
_T("EMR_POLYLINE16"),
_T("EMR_POLYBEZIERTO16"),
_T("EMR_POLYLINETO16"),
_T("EMR_POLYPOLYLINE16"),
_T("EMR_POLYPOLYGON16"),
_T("EMR_POLYDRAW16"),
_T("EMR_CREATEMONOBRUSH"),
_T("EMR_CREATEDIBPATTERNBRUSHPT"),
_T("EMR_EXTCREATEPEN"),
_T("EMR_POLYTEXTOUTA"),
_T("EMR_POLYTEXTOUTW"),
//WINVER >= 0x0400
_T("EMR_SETICMMODE"),
_T("EMR_CREATECOLORSPACE"),
_T("EMR_SETCOLORSPACE"),
_T("EMR_DELETECOLORSPACE"),
_T("EMR_GLSRECORD"),
_T("EMR_GLSBOUNDEDRECORD"),
_T("EMR_PIXELFORMAT"),
//WINVER >= 0x0500
#if 1
_T("EMR_DRAWESCAPE"),
_T("EMR_EXTESCAPE"),
_T("EMR_STARTDOC"),
_T("EMR_SMALLTEXTOUT"),
_T("EMR_FORCEUFIMAPPING"),
_T("EMR_NAMEDESCAPE"),
_T("EMR_COLORCORRECTPALETTE"),
_T("EMR_SETICMPROFILEA"),
_T("EMR_SETICMPROFILEW"),
_T("EMR_ALPHABLEND"),
_T("EMR_SETLAYOUT"), /*EMR_ALPHADIBBLEND*/
_T("EMR_TRANSPARENTBLT"),
_T("EMR_TRANSPARENTDIB"),
_T("EMR_GRADIENTFILL"),
_T("EMR_SETLINKEDUFIS"),
_T("EMR_SETTEXTJUSTIFICATION"),
_T("EMR_COLORMATCHTOTARGETW"),
_T("EMR_CREATECOLORSPACEW"),
#else
_T("EMR_RESERVED_105"),
_T("EMR_RESERVED_106"),
_T("EMR_RESERVED_107"),
_T("EMR_RESERVED_108"),
_T("EMR_RESERVED_109"),
_T("EMR_RESERVED_110"),
_T("EMR_COLORCORRECTPALETTE"),
_T("EMR_SETICMPROFILEA"),
_T("EMR_SETICMPROFILEW"),
_T("EMR_ALPHABLEND"),
_T("EMR_SETLAYOUT"),
_T("EMR_TRANSPARENTBLT"),
_T("EMR_RESERVED_117"),
_T("EMR_GRADIENTFILL"),
_T("EMR_RESERVED_119"),
_T("EMR_RESERVED_120"),
_T("EMR_COLORMATCHTOTARGETW"),
_T("EMR_CREATECOLORSPACEW")
#endif
};
LPTSTR SCGetRecordName(int iCode)
{
if (iCode>=sizeof(s_SCEMFRecNames)/sizeof(s_SCEMFRecNames[0]))
return SC_UNKNOWN_RECNAME;
return s_SCEMFRecNames[iCode];
}
////////////////////////////////////////////////////////////////////////
// Texts
CString SCFormatTextOptions(UINT uiOptions)
{
#if (_WIN32_WINNT >= 0x0500)
#define SC_ETO_PDY ETO_PDY
#else
#define SC_ETO_PDY 0x2000
#endif // (_WIN32_WINNT >= 0x0500)
CString strOpt = _T("");
if (uiOptions & ETO_OPAQUE)
strOpt += _T("|ETO_OPAQUE");
if (uiOptions & ETO_CLIPPED)
strOpt += _T("|ETO_CLIPPED");
if (uiOptions & ETO_GLYPH_INDEX)
strOpt += _T("|ETO_GLYPH_INDEX");
if (uiOptions & ETO_NUMERICSLATIN)
strOpt += _T("|ETO_NUMERICSLATIN");
if (uiOptions & ETO_NUMERICSLOCAL)
strOpt += _T("|ETO_NUMERICSLOCAL");
if (uiOptions & SC_ETO_PDY)
strOpt += _T("|ETO_PDY");
if (uiOptions & ETO_RTLREADING)
strOpt += _T("|ETO_RTLREADING");
if (!strOpt.IsEmpty())
strOpt.Right(strOpt.GetLength()-1);
return strOpt;
}
CString STFormatEmrTextA(EMRTEXT &emrtext, EMREXTTEXTOUTA *pRec)
{
int nbChars = pRec->emrtext.nChars;
TCHAR *pszText = new TCHAR[nbChars+1];
#ifdef _UNICODE
MultiByteToWideChar(CP_ACP, 0, (char*)pRec + pRec->emrtext.offString, nbChars, pszText, nbChars);
#else
strncpy(pszText, (char*)pRec + pRec->emrtext.offString, nbChars);
#endif
pszText[nbChars] = 0;
CString strOpt = SCFormatTextOptions(pRec->emrtext.fOptions);
CString strText;
strText.Format(_T(" TXT=[%s] [exScale(%f) eyScale(%f) iGraphicsMode(%d), Bounds(%d,%d,%d,%d)] TxOPT[fOptions(%d%s), nChars(%d), offDx(%d), ptlRef(%d,%d), rcl(%d,%d,%d,%d)]"),
pszText,
pRec->exScale, pRec->eyScale, pRec->iGraphicsMode, SC_PARAM_RCLBOUNDS(pRec->rclBounds),
pRec->emrtext.fOptions, strOpt, pRec->emrtext.nChars, pRec->emrtext.offDx, SC_PARAM_POINT(pRec->emrtext.ptlReference), SC_PARAM_RECT(pRec->emrtext.rcl));
delete [] pszText;
// characters spacing
if (pRec->emrtext.offDx)
{
long* pSpace = (long*)((BYTE*)pRec + pRec->emrtext.offDx);
CString strSpace = _T(" Spacing[");
CString strCur;
long nTotal = 0;
for (int i=0; (i<nbChars-1); i++)
{
nTotal += *pSpace;
strCur.Format(_T("%ld,"), *pSpace++);
strSpace += strCur;
}
nTotal += *pSpace;
strCur.Format(_T("%ld => Total(%ld) =>xPtRefRight(%ld)]"), *pSpace, nTotal, pRec->emrtext.ptlReference.x+nTotal-1);
strText += strSpace + strCur;
}
return strText;
}
CString STFormatEmrTextW(EMRTEXT &emrtext, EMREXTTEXTOUTW *pRec)
{
int nbChars = pRec->emrtext.nChars;
LPWSTR lpw = (LPWSTR)((char*)pRec + pRec->emrtext.offString);
TCHAR *pszText = new TCHAR[nbChars+1];
#ifdef _UNICODE
wcsncpy(pszText, lpw, nbChars);
#else
WideCharToMultiByte(CP_ACP, 0, lpw, nbChars, pszText, (nbChars+1)*sizeof(TCHAR), NULL, NULL);
#endif
pszText[nbChars]=0;
CString strOpt = SCFormatTextOptions(pRec->emrtext.fOptions);
CString strText;
strText.Format(_T(" TXT=[%s] [exScale(%f) eyScale(%f) iGraphicsMode(%d), Bounds(%d,%d,%d,%d)] TxOPT[fOptions(%d%s), nChars(%d), offDx(%d), ptlRef(%d,%d), rcl(%d,%d,%d,%d)]"),
pszText,
pRec->exScale, pRec->eyScale, pRec->iGraphicsMode, SC_PARAM_RCLBOUNDS(pRec->rclBounds),
pRec->emrtext.fOptions, strOpt, nbChars, pRec->emrtext.offDx, SC_PARAM_POINT(pRec->emrtext.ptlReference), SC_PARAM_RECT(pRec->emrtext.rcl));
delete [] pszText;
// characters spacing
if (pRec->emrtext.offDx)
{
long* pSpace = (long*)((BYTE*)pRec + pRec->emrtext.offDx);
CString strSpace = _T(" Spacing[");
CString strCur;
long nTotal = 0;
if (nbChars>1)
{
for (int i=0; (i<nbChars-1); i++)
{
nTotal += *pSpace;
strCur.Format(_T("%ld,"), *pSpace++);
strSpace += strCur;
}
}
nTotal += *pSpace;
strCur.Format(_T("%ld => Total(%ld) =>xPtRefRight(%ld)]"), *pSpace, nTotal, pRec->emrtext.ptlReference.x+nTotal-1);
strText += strSpace + strCur;
}
return strText;
}
////////////////////////////////////////////////////////////////////////
// Rops
LPCTSTR const s_strGDIRops2[]=
{
_T(""),
_T("R2_BLACK"),
_T("R2_NOTMERGEPEN"),
_T("R2_MASKNOTPEN"),
_T("R2_NOTCOPYPEN"),
_T("R2_MASKPENNOT"),
_T("R2_NOT"),
_T("R2_XORPEN"),
_T("R2_NOTMASKPEN"),
_T("R2_MASKPEN"),
_T("R2_NOTXORPEN"),
_T("R2_NOP"),
_T("R2_MERGENOTPEN"),
_T("R2_COPYPEN"),
_T("R2_MERGEPENNOT"),
_T("R2_MERGEPEN"),
_T("R2_WHITE")
};
CString SCRop2Text(INT iRop2)
{
if (iRop2>=sizeof(s_strGDIRops2)/sizeof(s_strGDIRops2[0]))
return _T("");
return s_strGDIRops2[iRop2];
}
////////////////////////////////////////////////////////////////////////
// Pens
CString SCPenStyleText(UINT uiPenStyle)
{
CString strResult = _T("");
switch (uiPenStyle & PS_STYLE_MASK)
{
case PS_SOLID: strResult = _T("PS_SOLID"); break;
case PS_DASH: strResult = _T("PS_DASH"); break;
case PS_DOT: strResult = _T("PS_DOT"); break;
case PS_DASHDOT: strResult = _T("PS_DASHDOT"); break;
case PS_DASHDOTDOT: strResult = _T("PS_DASHDOTDOT"); break;
case PS_NULL: strResult = _T("PS_NULL"); break;
case PS_INSIDEFRAME: strResult = _T("PS_INSIDEFRAME"); break;
case PS_USERSTYLE: strResult = _T("PS_USERSTYLE"); break;
case PS_ALTERNATE: strResult = _T("PS_ALTERNATE"); break;
}
if ((uiPenStyle & PS_STYLE_MASK) != PS_NULL)
{
switch (uiPenStyle & PS_TYPE_MASK)
{
case PS_GEOMETRIC: strResult += _T(" | GEOMETRIC"); break;
case PS_COSMETIC: strResult += _T(" | COSMETIC"); break;
}
switch (uiPenStyle & PS_JOIN_MASK)
{
case PS_JOIN_ROUND: /*strResult += _T(" | JOIN_ROUND");*/ break;
case PS_JOIN_MITER: strResult += _T(" | JOIN_MITER"); break;
case PS_JOIN_BEVEL: strResult += _T(" | JOIN_BEVEL"); break;
}
switch (uiPenStyle & PS_ENDCAP_MASK)
{
case PS_ENDCAP_ROUND: /*strResult += _T(" | ENDCAP_ROUND");*/ break;
case PS_ENDCAP_FLAT: strResult += _T(" | ENDCAP_FLAT"); break;
case PS_ENDCAP_SQUARE: strResult += _T(" | ENDCAP_SQUARE"); break;
}
}
return strResult;
}
////////////////////////////////////////////////////////////////////////
// Brushes
CString SCHatchStyleText(UINT uiHatchStyle)
{
switch (uiHatchStyle)
{
case HS_BDIAGONAL: return _T("HS_BDIAGONAL");
case HS_CROSS: return _T("HS_CROSS");
case HS_DIAGCROSS: return _T("HS_DIAGCROSS");
case HS_FDIAGONAL: return _T("HS_FDIAGONAL");
case HS_HORIZONTAL: return _T("HS_HORIZONTAL");
case HS_VERTICAL: return _T("HS_VERTICAL");
}
return _T("HS_??");
}
CString SCBrushStyleText(UINT uiStyle)
{
switch (uiStyle)
{
case BS_SOLID: return _T("BS_SOLID");
case BS_HATCHED: return _T("BS_HATCHED");
case BS_PATTERN: return _T("BS_PATTERN");
case BS_PATTERN8X8: return _T("BS_PATTERN8X8");
case BS_DIBPATTERNPT: return _T("BS_DIBPATTERNPT");
case BS_DIBPATTERN: return _T("BS_DIBPATTERN");
case BS_DIBPATTERN8X8: return _T("BS_DIBPATTERN8X8");
case BS_INDEXED: return _T("BS_INDEXED");
case BS_MONOPATTERN: return _T("BS_MONOPATTERN");
case BS_NULL: return _T("BS_NULL");
}
return _T("BS_??");
}
CString SCLogBrushStyleText(LOGBRUSH32& rLb)
{
CString strBrushStyle;
strBrushStyle.Format(_T("style(%d=%s"),
rLb.lbStyle,
SCBrushStyleText(rLb.lbStyle));
CString strAdd;
switch (rLb.lbStyle)
{
case BS_SOLID:
// elpColor specifies the color in which the pen is to be drawn.
// elpHatch is ignored.
strAdd.Format(_T("color:0x%08X"), rLb.lbColor);
break;
case BS_HATCHED:
// elpColor specifies the color in which the pen is to be drawn
// elpHatch describes the hatches
strAdd.Format(_T("lbHatch:%d=%s, color:0x%08X"),
rLb.lbHatch, SCHatchStyleText(rLb.lbHatch), rLb.lbColor);
break;
case BS_DIBPATTERN:
// lbColor is equal to DIB_PAL_COLORS or DIB_RGB_COLORS.
// lbHatch is a handle to the packed DIB.
strAdd.Format(_T("handle:0x%08x, color_format:%s"),
rLb.lbHatch, SCDIBColorUsageText(LOWORD(rLb.lbColor)));
break;
case BS_DIBPATTERNPT:
// lbColor is equal to DIB_PAL_COLORS or DIB_RGB_COLORS.
// lbHatch member is a pointer to the packed DIB.
strAdd.Format(_T("pointer:0x%08x, color_format:%s"),
rLb.lbHatch, SCDIBColorUsageText(LOWORD(rLb.lbColor)));
break;
case BS_PATTERN:
// lbColor is ignored.
// lbHatch is a handle to the bitmap that defines the pattern.
strAdd.Format(_T("handle:0x%08x"), rLb.lbHatch);
break;
case BS_HOLLOW:
// lbColor is ignored
// lbHatch is ignored
break;
}
if (!strAdd.IsEmpty())
strBrushStyle += _T(", ") + strAdd + _T(")");
else
strBrushStyle += _T(")");
return strBrushStyle;
}
CString SCExtLogpenBrushStyleText(EMREXTCREATEPEN *pRec)
{
ASSERT(pRec);
EXTLOGPEN& rLp = pRec->elp;
CString strBrushStyle;
strBrushStyle.Format(_T("brush(%d=%s"),
rLp.elpBrushStyle, SCBrushStyleText(rLp.elpBrushStyle));
CString strAdd;
switch (rLp.elpBrushStyle)
{
case BS_SOLID:
// elpColor specifies the color in which the pen is to be drawn.
// elpHatch is ignored.
strAdd.Format(_T("elpColor:0x%08X"), rLp.elpColor);
break;
case BS_HATCHED:
// elpColor specifies the color in which the pen is to be drawn
// elpHatch describes the hatches
strAdd.Format(_T("elpHatch:%d=%s, elpColor:0x%08X"),
rLp.elpHatch, SCHatchStyleText(rLp.elpHatch), rLp.elpColor);
break;
case BS_DIBPATTERN:
// elpColor is equal to DIB_PAL_COLORS or DIB_RGB_COLORS.
// elpHatch is a handle to the packed DIB.
strAdd.Format(_T("handle:0x%08x, color_format:%s, BMP[offBmi:%d, Bmi:%d, offBits:%d, Bits:%d]"),
rLp.elpHatch, SCDIBColorUsageText(rLp.elpColor),
pRec->offBmi, pRec->cbBmi, pRec->offBits, pRec->cbBits);
break;
case BS_DIBPATTERNPT:
// elpColor is equal to DIB_PAL_COLORS or DIB_RGB_COLORS.
// elpHatch member is a pointer to the packed DIB.
strAdd.Format(_T("pointer:0x%08x, color_format:%s, BMP[offBmi:%d, Bmi:%d, offBits:%d, Bits:%d]"),
rLp.elpHatch, SCDIBColorUsageText(rLp.elpColor),
pRec->offBmi, pRec->cbBmi, pRec->offBits, pRec->cbBits);
break;
case BS_PATTERN:
// elpColor is ignored.
// elpHatch is a handle to the bitmap that defines the pattern.
strAdd.Format(_T("handle:0x%08x, BMP[offBmi:%d, Bmi:%d, offBits:%d, Bits:%d]"),
rLp.elpHatch,
pRec->offBmi, pRec->cbBmi, pRec->offBits, pRec->cbBits);
break;
case BS_HOLLOW:
// elpColor is ignored
// elpHatch is ignored
break;
}
if (!strAdd.IsEmpty())
strBrushStyle += _T(", ") + strAdd + _T(")");
else
strBrushStyle += _T(")");
return strBrushStyle;
}
////////////////////////////////////////////////////////////////////////
// Bitmaps
CString SCDIBColorUsageText(UINT uiUsage)
{
#ifndef DIB_PAL_INDICES
#define DIB_PAL_INDICES 2
#endif
switch (uiUsage)
{
case DIB_RGB_COLORS: return _T("DIB_RGB_COLORS");
case DIB_PAL_COLORS: return _T("DIB_PAL_COLORS");
case DIB_PAL_INDICES: return _T("DIB_PAL_INDICES");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -