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.

154 lines
3.7 KiB
C++

#include "StdAfx.h"
#include "FontTypeMgr.h"
#include "LogMgr.h"
#include "FontLaipu.h"
#include "FontTrueType.h"
#include "FontBarcode.h"
CFontTypeMgr CFontTypeMgr::m_Instance;
CFontTypeMgr::CFontTypeMgr(void)
{
}
CFontTypeMgr::~CFontTypeMgr(void)
{
}
CFontTypeMgr &CFontTypeMgr::Instance()
{
return m_Instance;
}
//初始化
void CFontTypeMgr::Initialize()
{
//windows TrueType 字库
CFontType *p1 = new CFontTrueType;
p1->Initialize();
AddFontType(p1);
//莱普的字库
CFontType *p2 = new CFontLaipu;
p2->Initialize();
AddFontType(p2);
//条码字库
CFontType *p3 = new CFontBarcode;
p3->Initialize();
AddFontType(p3);
m_CurFontTypeIdx = 0;//当前选择的字库类型
}
bool CFontTypeMgr::CheckIdx(int idx)
{
int size = m_FontTypeVec.size();
if(idx>=0 && idx<size)
return true;
return false;
}
//添加字体
void CFontTypeMgr::AddFontType(CFontType *p)
{
//保存到智能指针
Sptr<CFontType> sPtr(p);
m_FontTypeVec.push_back(sPtr);
}
//字库类型名字插入到comb
void CFontTypeMgr::FontTypeNameInsertToComb(CComboBox &Comb)
{
//先清空
Comb.ResetContent();
vector<Sptr<CFontType>>::iterator iter = m_FontTypeVec.begin();
vector<Sptr<CFontType>>::iterator iter_end = m_FontTypeVec.end();
for(int i=0;iter!=iter_end;iter++,i++)
{
Comb.InsertString(i,(*iter)->GetFontType());
}
Comb.SetCurSel(m_CurFontTypeIdx);
}
//刷新字体名字下拉列表CComboBox
void CFontTypeMgr::UpdateFontNameComb(CComboBox &Comb)
{
//先清空
Comb.ResetContent();
if(CheckIdx(m_CurFontTypeIdx))
{
m_FontTypeVec[m_CurFontTypeIdx]->UpdateFontNameComb(Comb);
}
}
//获取当前选择的字体路径
CString CFontTypeMgr::GetFontPath(CString FontName)
{
//先获得FONT 文件夹的目录--------------------------------------------------------
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(1023),1024); //读取程序当前目录
sPath.ReleaseBuffer();
int nPos;
nPos = sPath.ReverseFind('\\');
sPath = sPath.Left(nPos);
sPath = sPath + "\\font\\";
return sPath+FontName;
}
//设置当前选择的字体
void CFontTypeMgr::SetCurFontType(int idx)
{
m_CurFontTypeIdx = idx;
}
void CFontTypeMgr::GetCurFontName(int idx)
{
if(CheckIdx(m_CurFontTypeIdx))
{
m_FontTypeVec[m_CurFontTypeIdx]->SetCurFontNameIdx(idx);
}
}
//获取当前选择的索引值
int CFontTypeMgr::GetCurFontTypeIdx()
{
if(CheckIdx(m_CurFontTypeIdx))
return m_FontTypeVec[m_CurFontTypeIdx]->GetCurFontNameIdx();
else
return -1;
}
//用当前字体来创建字符数据
void CFontTypeMgr::CreatCharVec(char *pChar,vector<PointType> &m_PonitVec)
{
if(CheckIdx(m_CurFontTypeIdx))
{
m_FontTypeVec[m_CurFontTypeIdx]->CreatCharVec(pChar,m_PonitVec);
}
}
CString CFontTypeMgr::GetCurFontTypeName()
{
CString str;
if(CheckIdx(m_CurFontTypeIdx))
{
str = m_FontTypeVec[m_CurFontTypeIdx]->GetFontType();
}
return str;
}
CString CFontTypeMgr::GetCurFontName()
{
CString str;
if(CheckIdx(m_CurFontTypeIdx))
{
str = m_FontTypeVec[m_CurFontTypeIdx]->GetCurFontName();
}
return str;
}
//通过字体的名字来改变当前选择的字体
void CFontTypeMgr::SetCurFontByName(CString FontTypeName,CString FontName)
{
vector<Sptr<CFontType>>::iterator iter = m_FontTypeVec.begin();
vector<Sptr<CFontType>>::iterator iter_end = m_FontTypeVec.end();
for(int i=0;iter!=iter_end;iter++,i++)
{
if((*iter)->GetFontType() == FontTypeName)//查找匹配的字体类型
{
if((*iter)->SetCurFontByName(FontName))//同时需要具体字体名字匹配成功
{
m_CurFontTypeIdx = i;
break;
}
}
}
}