#include "StdAfx.h" #include "FontLaipu.h" #include "FontTypeMgr.h" CFontLaipu::CFontLaipu(void) { } CFontLaipu::~CFontLaipu(void) { } void CFontLaipu::Initialize() { //先获得FONT 文件夹的目录-------------------------------------------------------- CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024); //读取程序当前目录 sPath.ReleaseBuffer(); int nPos; nPos = sPath.ReverseFind('\\'); sPath = sPath.Left(nPos); CString str = sPath + "\\font"; //在font 文件夹查找sl 后缀的文件------------------------------------------------- int idx = 0; CFileFind finder; BOOL bWorking = finder.FindFile(str + "/*.*");//m_path为指定的文件夹 while (bWorking)//遍历文件夹 { bWorking = finder.FindNextFile(); CString name = finder.GetFileName(); CString extend = name.Right(name.GetLength() - name.ReverseFind('.') - 1);//取得扩展名 if(!finder.IsDots()) { if(extend == "SL" || extend == "sl") { AddTypeName(name); } } } } void CFontLaipu::CreatCharVec(char *pChar,vector &PonitVec) { CreatCharVecExt(*pChar,PonitVec); } //在莱普的字库中提取AsciiCode 对应的数据(Offset是连续两个字符之间的间隔) void CFontLaipu::CreatCharVecExt(unsigned char AsciiCode,vector &PonitVec) { CFontTypeMgr &pFontTypeMgr = CFontTypeMgr::Instance(); //获取当前字体文件路径 CString str = pFontTypeMgr.GetFontPath(GetCurFontName()); char filepath[1024]; strcpy(filepath,(LPSTR)(LPCTSTR)str); //打开字库文件 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();//指针移到文件头 file.Read(pBuf, FileLen*sizeof(char));//读取到内存中 //找到存储地址的开始位置 unsigned long AddrOffset = AsciiCode*3; unsigned long AddrStart = 0;//数据的起始位置 unsigned char ch; ch = pBuf[AddrOffset]; AddrStart = ch; ch = pBuf[AddrOffset+1]; AddrStart += ch*256; ch = pBuf[AddrOffset+2]; AddrStart += ((long)ch*256*256); //下标从0 开始 AddrStart --; BOOL flg = TRUE; BOOL bUpOrDown = FALSE;//抬笔还是落笔 //方向系数 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; //出发点 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://单次偏移 { 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://连续偏移 { 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://小范围偏移 { int Low4Bit,High4Bit; High4Bit = (unsigned char)ch/16;//方向 Low4Bit = (unsigned char)ch - High4Bit*16;//步长 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++; } //释放文件缓冲区 delete []pBuf; file.Close(); } }