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.

153 lines
5.1 KiB
C++

#include "StdAfx.h"
#include "FontLaipu.h"
#include "FontTypeMgr.h"
CFontLaipu::CFontLaipu(void)
{
}
CFontLaipu::~CFontLaipu(void)
{
}
void CFontLaipu::Initialize()
{
//<2F>Ȼ<EFBFBD><C8BB><EFBFBD>FONT <20>ļ<EFBFBD><C4BC>е<EFBFBD>Ŀ¼--------------------------------------------------------
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰĿ¼
sPath.ReleaseBuffer();
int nPos;
nPos = sPath.ReverseFind('\\');
sPath = sPath.Left(nPos);
CString str = sPath + "\\font";
//<2F><>font <20>ļ<EFBFBD><C4BC>в<EFBFBD><D0B2><EFBFBD>sl <20><>׺<EFBFBD><D7BA><EFBFBD>ļ<EFBFBD>-------------------------------------------------
int idx = 0;
CFileFind finder;
BOOL bWorking = finder.FindFile(str + "/*.*");//m_pathΪָ<CEAA><D6B8><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
while (bWorking)//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
{
bWorking = finder.FindNextFile();
CString name = finder.GetFileName();
CString extend = name.Right(name.GetLength() - name.ReverseFind('.') - 1);//ȡ<><C8A1><EFBFBD><EFBFBD>չ<EFBFBD><D5B9>
if(!finder.IsDots())
{
if(extend == "SL" || extend == "sl")
{
AddTypeName(name);
}
}
}
}
void CFontLaipu::CreatCharVec(char *pChar,vector<PointType> &PonitVec)
{
CreatCharVecExt(*pChar,PonitVec);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD><EFBFBD>ȡAsciiCode <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Offset<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>֮<EFBFBD><D6AE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>)
void CFontLaipu::CreatCharVecExt(unsigned char AsciiCode,vector<PointType> &PonitVec)
{
CFontTypeMgr &pFontTypeMgr = CFontTypeMgr::Instance();
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
CString str = pFontTypeMgr.GetFontPath(GetCurFontName());
char filepath[1024];
strcpy(filepath,(LPSTR)(LPCTSTR)str);
//<2F><><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF>ļ<EFBFBD>
CFile file;
if(file.Open(filepath,CFile::modeRead|CFile::typeBinary))
{
int FileLen = file.GetLength()+1;
char *pBuf=new char[FileLen];
memset(pBuf,0,FileLen*sizeof(char));
file.SeekToBegin();//ָ<><D6B8><EFBFBD>Ƶ<EFBFBD><C6B5>ļ<EFBFBD>ͷ
file.Read(pBuf, FileLen*sizeof(char));//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><E6B4A2>ַ<EFBFBD>Ŀ<EFBFBD>ʼλ<CABC><CEBB>
unsigned long AddrOffset = AsciiCode*3;
unsigned long AddrStart = 0;//<2F><><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>ʼλ<CABC><CEBB>
unsigned char ch;
ch = pBuf[AddrOffset];
AddrStart = ch;
ch = pBuf[AddrOffset+1];
AddrStart += ch*256;
ch = pBuf[AddrOffset+2];
AddrStart += ((long)ch*256*256);
//<2F>±<EFBFBD><C2B1><EFBFBD>0 <20><>ʼ
AddrStart --;
BOOL flg = TRUE;
BOOL bUpOrDown = FALSE;//̧<>ʻ<EFBFBD><CABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
double DirStepX[16] = {1, 1, 1, 0.5, 0, -0.5, -1, -1, -1, -1, -1, -0.5, 0, 0.5, 1, 1};
double DirStepY[16] = {0, 0.5, 1, 1, 1, 1, 1, 0.5, 0, -0.5, -1, -1, -1, -1, -1, -0.5};
int idx = 0;
PointType PointData;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
PointData.first.x = 0;
PointData.first.y = 0;
while(flg)
{
ch = pBuf[AddrStart+idx];
switch(ch)
{
case 0:
flg = FALSE;
break;
case 1://pen down
bUpOrDown = FALSE;
break;
case 2://pen up
bUpOrDown = TRUE;
break;
case 8://<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
{
idx++;
int XOffset = pBuf[AddrStart+idx];
idx++;
int YOffset = pBuf[AddrStart+idx];
PointData.first.x += XOffset;
PointData.first.y += YOffset;
PointData.second = bUpOrDown;
PonitVec.push_back(PointData);
}
break;
case 9://<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
{
idx++;
int XOffset = pBuf[AddrStart+idx];
idx++;
int YOffset = pBuf[AddrStart+idx];
while(XOffset != 0 || YOffset != 0)
{
PointData.first.x += XOffset;
PointData.first.y += YOffset;
PointData.second = bUpOrDown;
PonitVec.push_back(PointData);
idx++;
XOffset = pBuf[AddrStart+idx];
idx++;
YOffset = pBuf[AddrStart+idx];
}
}
break;
default://С<><D0A1>Χƫ<CEA7><C6AB>
{
int Low4Bit,High4Bit;
High4Bit = (unsigned char)ch/16;//<2F><><EFBFBD><EFBFBD>
Low4Bit = (unsigned char)ch - High4Bit*16;//<2F><><EFBFBD><EFBFBD>
int XOffset = DirStepX[Low4Bit]*High4Bit;
int YOffset = DirStepY[Low4Bit]*High4Bit;
PointData.first.x += XOffset;
PointData.first.y += YOffset;
PointData.second = bUpOrDown;
PonitVec.push_back(PointData);
}
break;
}
idx++;
}
//<2F>ͷ<EFBFBD><CDB7>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delete []pBuf;
file.Close();
}
}