You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
TwoLaserHead-PushJig/LaiPuLaser/FontTrueType.cpp

126 lines
3.3 KiB
C++

#include "StdAfx.h"
#include "FontTrueType.h"
#include "LogMgr.h"
vector<CString> TrueTypeVec;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/*<2A>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>ϵͳ<CFB5>Ѿ<EFBFBD><D1BE><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
BOOL CALLBACK EnumWinFontCallBackEx(ENUMLOGFONTEX* pelf, NEWTEXTMETRICEX* lpntm, int FontType, LPVOID pThis)
{
if(FontType&RASTER_FONTTYPE)
{
return TRUE;
}
CString str;
if (FontType&TRUETYPE_FONTTYPE)
{
str=((pelf)->elfLogFont.lfFaceName);
}
TrueTypeVec.push_back(str);
return TRUE;
}
CFontTrueType::CFontTrueType(void)
{
}
CFontTrueType::~CFontTrueType(void)
{
}
void CFontTrueType::Initialize()
{
HDC hDC;
hDC=::GetWindowDC(NULL);
LOGFONT lf;
memset(&lf,0,sizeof(LOGFONT));
lf.lfCharSet=GB2312_CHARSET;
::EnumFontFamiliesEx(hDC, &lf,(FONTENUMPROC)EnumWinFontCallBackEx,(LPARAM)this,(DWORD) 0);
::ReleaseDC(NULL,hDC);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
int size = TrueTypeVec.size();
for(int i=0;i<size;i++)
{
CString str = TrueTypeVec[i].Left(1);
if(str!=_T("@"))//ɾ<><C9BE>@ <20><>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
AddTypeName(TrueTypeVec[i]);
}
}
}
void CFontTrueType::CreatCharVec(char *pChar,vector<PointType> &PonitVec)
{
CClientDC dc(NULL);
CDC *pDC = &dc;
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = 1000;//<2F>ߴ<EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD>
lf.lfWeight = FW_NORMAL;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
lf.lfCharSet = GB2312_CHARSET;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
_tcscpy(lf.lfFaceName, _T(GetCurFontName()));
// create and select it
CFont newFont;
if (!newFont.CreateFontIndirect(&lf))
return;
CFont* pOldFont = pDC->SelectObject(&newFont);
pDC->SetBkMode(TRANSPARENT);//<2F><><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>
//<2F><>ʼһ<CABC><D2BB>·<EFBFBD><C2B7>
pDC->BeginPath();
pDC->TextOut(0, 0, pChar);
pDC->EndPath();//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>߶<EFBFBD><DFB6><EFBFBD><EFBFBD><EFBFBD>
pDC->FlattenPath();//<2F><>һ<EFBFBD><D2BB>·<EFBFBD><C2B7><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
int Count=pDC->GetPath(NULL,NULL,0);//<2F><>ȡ·<C8A1><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CPoint* pPoin=new CPoint[Count];
BYTE* pByte=new BYTE[Count];
CPoint endpoint;
pDC->GetPath(pPoin,pByte,Count);
PointType PointData;
for(int i=0;i<Count;i++)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch(pByte[i])
{
case PT_MOVETO:
PointData.first.x = pPoin[i].x;
PointData.first.y = pPoin[i].y;
PointData.second = true;
PonitVec.push_back(PointData);
endpoint=pPoin[i];
break;
case PT_LINETO:
PointData.first.x = pPoin[i].x;
PointData.first.y = pPoin[i].y;
PointData.second = false;
PonitVec.push_back(PointData);
break;
case PT_LINETO|PT_CLOSEFIGURE://<2F>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD>
PointData.first.x = endpoint.x;
PointData.first.y = endpoint.y;
PointData.second = false;
PonitVec.push_back(PointData);
break;
}
}
delete[] pPoin;
delete[] pByte;
pDC->SelectObject(pOldFont);
//<2F><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Mirror(PonitVec);
}
//<2F><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CFontTrueType::Mirror(vector<PointType> &PonitVec)
{
int size = PonitVec.size();
for(int i=0;i<size;i++)
{
PonitVec[i].first.y = PonitVec[i].first.y+(0-PonitVec[i].first.y)*2;
}
}