⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngautofont.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
字号:
//CNGAutoFont class implementation
#include "stdafx.h"
#include "NGAutoFont.h"

CNGAutoFont::CNGAutoFont()
{
	lf.lfHeight=-12;
	lf.lfWidth=0;
	lf.lfEscapement=0;
	lf.lfOrientation=0;
	lf.lfWeight=FW_NORMAL;
	lf.lfItalic=0;
	lf.lfUnderline=0;
	lf.lfStrikeOut=0;
	lf.lfCharSet=ANSI_CHARSET;
	lf.lfOutPrecision=OUT_DEFAULT_PRECIS;
	lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	lf.lfQuality=PROOF_QUALITY;
	lf.lfPitchAndFamily=VARIABLE_PITCH | FF_ROMAN;
	strcpy(lf.lfFaceName, "Times New Roman");

	CreateFontIndirect(&lf);

	fontColor=0;
	hDC=NULL;
}

CNGAutoFont::CNGAutoFont(CString facename)
{
	lf.lfHeight=-12;
	lf.lfWidth=0;
	lf.lfEscapement=0;
	lf.lfOrientation=0;
	lf.lfWeight=FW_NORMAL;
	lf.lfItalic=0;
	lf.lfUnderline=0;
	lf.lfStrikeOut=0;
	lf.lfCharSet=ANSI_CHARSET;
	lf.lfOutPrecision=OUT_DEFAULT_PRECIS;
	lf.lfClipPrecision=CLIP_DEFAULT_PRECIS;
	lf.lfQuality=PROOF_QUALITY;
	lf.lfPitchAndFamily=VARIABLE_PITCH | FF_ROMAN;
	strcpy(lf.lfFaceName, (LPCTSTR)facename);

	CreateFontIndirect(&lf);

	fontColor=0;
	hDC=NULL;
}

CNGAutoFont::CNGAutoFont(LOGFONT& logfont)
{
	lf=logfont;
	CreateFontIndirect(&lf);

	fontColor=0;
	hDC=NULL;
}

CNGAutoFont::CNGAutoFont(CFont* pFont)
{
	HFONT hFont=(HFONT)*pFont;
	Attach((HFONT)hFont);

	GetLogFont(&lf);

	fontColor=0;
	hDC=NULL;
}


CNGAutoFont::CNGAutoFont(HFONT hFont)
{
	Attach((HFONT)hFont);

	GetLogFont(&lf);

	fontColor=0;
	hDC=NULL;
}

CNGAutoFont::~CNGAutoFont()
{
}

BOOL CNGAutoFont::CreateStockObject(int nIndex)
{
	//Thanks to Magnus Sigurdsson for this fix.
	ASSERT (nIndex >= OEM_FIXED_FONT && nIndex <=DEFAULT_GUI_FONT);

	BOOL bResult;
	bResult=CFont::CreateStockObject(nIndex);
	if (bResult)
	{
		GetLogFont(&lf);
		DeleteObject();
		CreateFontIndirect(&lf);
	}
	return bResult;
}

LONG CNGAutoFont::SetHeight(LONG height)
{
	LONG l=lf.lfHeight;

	DeleteObject();
	lf.lfHeight=height;
	CreateFontIndirect(&lf);

	return l;
}

LONG CNGAutoFont::SetHeightA(LONG height)
{
	LONG l=lf.lfHeight;

	DeleteObject();
	if (height>0)
		height=0-height;
	lf.lfHeight=height * 4;
	lf.lfHeight=(int)lf.lfHeight/3;
	CreateFontIndirect(&lf);

	return l;
}

LONG CNGAutoFont::SetWidth(LONG width)
{
	LONG l=lf.lfWidth;

	DeleteObject();
	lf.lfWidth=width;
	CreateFontIndirect(&lf);

	return l;
}

LONG CNGAutoFont::SetEscapement(LONG esc)
{
	LONG l=lf.lfEscapement;

	DeleteObject();
	lf.lfEscapement=esc;
	CreateFontIndirect(&lf);

	return l;
}

LONG CNGAutoFont::SetOrientation(LONG or)
{
	LONG l=lf.lfOrientation;

	DeleteObject();
	lf.lfOrientation=or;
	CreateFontIndirect(&lf);

	return l;
}

LONG CNGAutoFont::SetWeight(LONG weight)
{
	LONG l=lf.lfWeight;

	DeleteObject();
	lf.lfWeight=weight;
	CreateFontIndirect(&lf);

	return l;
}

BYTE CNGAutoFont::SetCharset(BYTE charset)
{
	BYTE b=lf.lfCharSet;

	DeleteObject();
	lf.lfCharSet=charset;
	CreateFontIndirect(&lf);

	return b;
}

BYTE CNGAutoFont::SetOutPrecision(BYTE op)
{
	BYTE b=lf.lfOutPrecision;

	DeleteObject();
	lf.lfOutPrecision=op;
	CreateFontIndirect(&lf);

	return b;
}

BYTE CNGAutoFont::SetClipPrecision(BYTE cp)
{
	BYTE b=lf.lfClipPrecision;

	DeleteObject();
	lf.lfClipPrecision=cp;
	CreateFontIndirect(&lf);

	return b;
}

BYTE CNGAutoFont::SetQuality(BYTE qual)
{
	BYTE b=lf.lfQuality;

	DeleteObject();
	lf.lfQuality=qual;
	CreateFontIndirect(&lf);

	return b;
}

BYTE CNGAutoFont::SetPitchAndFamily(BYTE paf)
{
	BYTE b=lf.lfPitchAndFamily;

	DeleteObject();
	lf.lfPitchAndFamily=paf;
	CreateFontIndirect(&lf);

	return b;
}

CString CNGAutoFont::SetFaceName(CString facename)
{
	CString str=lf.lfFaceName;

	DeleteObject();
	strcpy(lf.lfFaceName, (LPCTSTR)facename);
	CreateFontIndirect(&lf);

	return str;
}

LPCTSTR CNGAutoFont::SetFaceName(LPCTSTR facename)
{
	LPCTSTR str=lf.lfFaceName;

	DeleteObject();
	strcpy(lf.lfFaceName, facename);
	CreateFontIndirect(&lf);

	return str;
}

BOOL CNGAutoFont::SetBold(BOOL B)
{
	BOOL b;

	if (B)
		b=SetWeight(FW_BOLD);
	else
		b=SetWeight(FW_NORMAL);

	if (b >= FW_MEDIUM)
		return TRUE;
	else
		return FALSE;
}

BOOL CNGAutoFont::SetItalic(BOOL i)
{
	BOOL b=(BOOL)lf.lfItalic;

	DeleteObject();
	lf.lfItalic=(TCHAR)i;
	CreateFontIndirect(&lf);

	return b;
}

BOOL CNGAutoFont::SetUnderline(BOOL u)
{
	BOOL b=(BOOL)lf.lfUnderline;

	DeleteObject();
	lf.lfUnderline=(TCHAR)u;
	CreateFontIndirect(&lf);

	return b;
}

BOOL CNGAutoFont::SetStrikeOut(BOOL s)
{
	BOOL b=(BOOL)lf.lfStrikeOut;

	DeleteObject();
	lf.lfStrikeOut=(TCHAR)s;
	CreateFontIndirect(&lf);

	return b;
}

void CNGAutoFont::SetLogFont(LOGFONT& logfont)
{
	lf=logfont;
	DeleteObject();
	CreateFontIndirect(&lf);
}

LONG CNGAutoFont::GetHeight()
{
	return lf.lfHeight;
}

LONG CNGAutoFont::GetWidth()
{
	return lf.lfWidth;
}

LONG CNGAutoFont::GetEscapement()
{
	return lf.lfEscapement;
}

LONG CNGAutoFont::GetOrientation()
{
	return lf.lfEscapement;
}

LONG CNGAutoFont::GetWeight()
{
	return lf.lfWeight;
}

BYTE CNGAutoFont::GetCharset()
{
	return lf.lfCharSet;
}

BYTE CNGAutoFont::GetOutPrecision()
{
	return lf.lfOutPrecision;
}

BYTE CNGAutoFont::GetClipPrecision()
{
	return lf.lfClipPrecision;
}

BYTE CNGAutoFont::GetQuality()
{
	return lf.lfQuality;
}

BYTE CNGAutoFont::GetPitchAndFamily()
{
	return lf.lfPitchAndFamily;
}

LPCTSTR CNGAutoFont::GetFaceName()
{
	return lf.lfFaceName;
}

BOOL CNGAutoFont::GetBold()
{
	return lf.lfWeight >= FW_MEDIUM ? TRUE : FALSE;
}

BOOL CNGAutoFont::GetItalic()
{
	return (BOOL)lf.lfItalic;
}

BOOL CNGAutoFont::GetUnderline()
{
	return (BOOL)lf.lfUnderline;
}

BOOL CNGAutoFont::GetStrikeOut()
{
	return (BOOL)lf.lfStrikeOut;
}

CString CNGAutoFont::ContractFont()
{
	CString str, color;

	str.Format("%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%s",
		lf.lfHeight,
		lf.lfWidth,
		lf.lfEscapement,
		lf.lfOrientation,
		lf.lfWeight,
		lf.lfItalic,
		lf.lfUnderline,
		lf.lfStrikeOut,
		lf.lfCharSet,
		lf.lfOutPrecision,
		lf.lfClipPrecision,
		lf.lfQuality,
		lf.lfPitchAndFamily,
		lf.lfFaceName);
	color.Format("%u", fontColor);
	str+=",";
	str+=color;

	return str;
}

void CNGAutoFont::ExtractFont(CString& str)
{
	lf.lfHeight=atol((LPCTSTR)GetToken(str, ","));
	lf.lfWidth=atol((LPCTSTR)GetToken(str, ","));
	lf.lfEscapement=atol((LPCTSTR)GetToken(str, ","));
	lf.lfOrientation=atol((LPCTSTR)GetToken(str, ","));
	lf.lfWeight=atol((LPCTSTR)GetToken(str, ","));
	lf.lfItalic=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfUnderline=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfStrikeOut=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfCharSet=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfOutPrecision=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfClipPrecision=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfQuality=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	lf.lfPitchAndFamily=(TCHAR)atoi((LPCTSTR)GetToken(str, ","));
	strcpy(lf.lfFaceName, (LPCTSTR)GetToken(str, ","));

	DeleteObject();
	CreateFontIndirect(&lf);

	fontColor=atol((LPCTSTR)str);
}

CString CNGAutoFont::GetToken(CString& str, LPCTSTR c)
{
	int pos;
	CString token;

	pos=str.Find(c);
	token=str.Left(pos);
	str=str.Mid(pos+1);

	return token;
}

void CNGAutoFont::GetFontFromDialog(CFont *f, DWORD *color,
				CDC *pPrinterDC, CWnd *pParentWnd)
{
	LOGFONT tlf;
	if (f==NULL)
		tlf=lf;
	else
		f->GetLogFont(&tlf);

	CFontDialog dlg(&tlf, CF_EFFECTS | CF_SCREENFONTS,
		pPrinterDC, pParentWnd);
	dlg.m_cf.rgbColors=fontColor;
	
	if (dlg.DoModal()==IDOK)
	{
		dlg.GetCurrentFont(&lf);
		DeleteObject();
		CreateFontIndirect(&lf);
		f=(CFont *)this;
		color=&dlg.m_cf.rgbColors;
		SetFontColor(dlg.m_cf.rgbColors);
	}
}

void CNGAutoFont::SetFontColor(COLORREF color)
{
	fontColor=color;
	if (hDC!=NULL)
		::SetTextColor(hDC, color);
}

COLORREF CNGAutoFont::GetFontColor()
{
	return fontColor;
}

void CNGAutoFont::SetDC(HDC dc)
{
	hDC=dc;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -