📄 fontex.cpp
字号:
// FontEx.cpp: implementation of the CFontEx class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "FontEx.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL( CFontEx, CFont, 100 )
CFontEx::CFontEx()
{
}
CFontEx::~CFontEx()
{
}
void CFontEx::Serialize(CArchive& ar)
{
LOGFONT logFont;
if (ar.IsStoring())
{// storing code
if( GetSafeHandle() == NULL )
{
InitDefault();
}
GetLogFont( &logFont );
ar.Write( &logFont, sizeof(LOGFONT) );
}
else
{// loading code
ar.Read( &logFont, sizeof(LOGFONT) );
if( GetSafeHandle() != NULL )
{
DeleteObject();
}
CreateFontIndirect( &logFont );
}
}
void CFontEx::InitDefault()
{
/*
CreateFont( int nHeight, int nWidth, int nEscapement,
int nOrientation, int nWeight, BYTE bItalic,
BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet,
BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality,
BYTE nPitchAndFamily, LPCTSTR lpszFacename );
*/
if( GetSafeHandle() != NULL )
{
DeleteObject();
}
CreateFont( 20, 0, 0,
0, 0, 0,
0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH, NULL );
}
const CFont & CFontEx::operator=(CFont & font)
{
LOGFONT logFont;
if( GetSafeHandle() != NULL )
{
DeleteObject();
}
if( font.GetSafeHandle() == NULL )
{
return font;
}
font.GetLogFont( &logFont );
CreateFontIndirect( &logFont );
return font;
}
const CFont & CFontEx::operator = (LOGFONT & logFont)
{
if( GetSafeHandle() != NULL )
{
DeleteObject();
}
CreateFontIndirect( &logFont );
return *this;
}
void CFontEx::SafeCreate(int height, const char * fontName/*=NULL*/)
{
if( GetSafeHandle() != NULL )
{
DeleteObject();
}
CreateFont( height, 0, 0,
0, 0, 0,
0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH, fontName );
}
BOOL CFontEx::MakePrinterFont(CPrinterInfoEx & info, CFont & reFont)
{
if( GetSafeHandle() == NULL )
{
return FALSE;
}
if( reFont.GetSafeHandle() != NULL )
{
reFont.DeleteObject();
}
LOGFONT logFont;
GetLogFont( &logFont );
double height = logFont.lfHeight;
//注:此转换系数是经测试而得的,并非来自技术文档资料
height = height / 3764.7639 * info.m_yResolution;
logFont.lfWidth = 0;
logFont.lfHeight = long(height);
reFont.CreateFontIndirect( &logFont );
return TRUE;
}
BOOL CFontEx::SetBold(BOOL bold)
{
if( GetSafeHandle() == NULL )
{
return FALSE;
}
LOGFONT logFont;
GetLogFont( &logFont );
if( bold )
{
logFont.lfWeight = 700;
}
else
{
logFont.lfWeight = 400;
}
DeleteObject();
CreateFontIndirect( &logFont );
return TRUE;
}
BOOL CFontEx::SetItalic(BOOL italic)
{
if( GetSafeHandle() == NULL )
{
return FALSE;
}
LOGFONT logFont;
GetLogFont( &logFont );
logFont.lfItalic = italic;
DeleteObject();
CreateFontIndirect( &logFont );
return TRUE;
}
BOOL CFontEx::SetUnderline(BOOL ul)
{
if( GetSafeHandle() == NULL )
{
return FALSE;
}
LOGFONT logFont;
GetLogFont( &logFont );
logFont.lfUnderline = ul;
DeleteObject();
CreateFontIndirect( &logFont );
return TRUE;
}
BOOL CFontEx::Zoom( double ratio )
{
if( GetSafeHandle() == NULL )
{
return FALSE;
}
LOGFONT logFont;
GetLogFont( &logFont );
logFont.lfWidth = 0;
logFont.lfHeight = long(logFont.lfHeight*ratio);
DeleteObject();
CreateFontIndirect( &logFont );
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -