// WizFontsEnumerator.cpp: implementation of the CWizFontsEnumerator class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "WizFontsEnumerator.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
namespace
{
UCHAR TTDefaults[] = { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
const int TTDefaultsSize = sizeof(TTDefaults)/sizeof(TTDefaults[0]);
}
//////////////////////////////////////////////////////////////////////
CWizFontsEnumerator::Font::Font(const LOGFONT& lf, DWORD fontType, LPCTSTR Script)
: m_Name(lf.lfFaceName) , m_bItalics(false), m_bBold(false),
m_bUnderline(false), m_bRegular(false),
m_dwFontType(fontType), m_bInited(false)
{
if (Script && *Script)
AddScript(Script);
}
void CWizFontsEnumerator::Font::operator=(const Font& f)
{
m_Name = f.m_Name ;
m_bItalics = f.m_bItalics ;
m_bBold = f.m_bBold ;
m_bUnderline= f.m_bUnderline;
m_bRegular = f.m_bRegular;
m_dwFontType= f.m_dwFontType;
m_Script.RemoveAll();
for (int i = 0; i < f.m_Script.GetSize(); i++)
m_Script.Add(f.m_Script[i]);
m_sizes.SetSize(f.m_sizes.GetSize());
for (i = 0; i < f.m_sizes.GetSize(); i++)
m_sizes[i] = f.m_sizes[i];
m_bInited = f.m_bInited;
}
struct Font_EnumStep
{
Font_EnumStep(CWizFontsEnumerator::Font& f, CDC& dc)
: rTHIS(f) , r_dc(dc)
{
cyPixelsPerInch = dc.GetDeviceCaps(LOGPIXELSY);
}
CWizFontsEnumerator::Font& rTHIS;
CDC& r_dc;
int cyPixelsPerInch;
};
int CALLBACK DetailsEnumProc (const ENUMLOGFONTEX *lpelfe, const NEWTEXTMETRICEX *lpntme, unsigned long FontType, LPARAM lParam)
{
Font_EnumStep* p = reinterpret_cast<Font_EnumStep*>(lParam);
/*
CWizFontsEnumerator::Font* pTHIS = reinterpret_cast<CWizFontsEnumerator::Font*>(lParam);
return pTHIS->DoEnumStep (lpelfe, lpntme, FontType);
*/
return p->rTHIS.DoEnumStep (lpelfe, lpntme, FontType, *p);
}
int CWizFontsEnumerator::Font::DoEnumStep (const ENUMLOGFONTEX *lpelf, const NEWTEXTMETRICEX *lpntm, unsigned long FontType, Font_EnumStep& data)
{
ASSERT(&(data.rTHIS) == this);
if (FontType & TRUETYPE_FONTTYPE)
{
if (!(lpntm->ntmTm.ntmFlags & (NTM_BOLD | NTM_ITALIC)))
{
TRACE("\n\tFont %s add regular", lpelf->elfLogFont.lfFaceName);
m_bRegular = true;
}
if (lpntm->ntmTm.ntmFlags & NTM_ITALIC)
{
TRACE("\n\tFont %s add Italics", lpelf->elfLogFont.lfFaceName);
m_bItalics = true;
}
if (lpntm->ntmTm.ntmFlags & NTM_BOLD)
{
TRACE("\n\tFont %s add Bold", lpelf->elfLogFont.lfFaceName);
m_bBold = true;
}
}
else
{
if (FontType & RASTER_FONTTYPE)
{
int height = lpntm->ntmTm.tmHeight - lpntm->ntmTm.tmInternalLeading;
int size_pp = MulDiv(height, 72, data.cyPixelsPerInch); //, height);
TRACE("\n\tFont %s add size %d", lpelf->elfLogFont.lfFaceName, size_pp);
AddSize(size_pp, height);
}
if (lpelf->elfLogFont.lfWeight >= FW_BOLD && lpelf->elfLogFont.lfItalic)
{
TRACE("\n\tFont %s add bold & italics", lpelf->elfLogFont.lfFaceName);
m_bItalics = true;
m_bBold = true;
}
else if (lpelf->elfLogFont.lfWeight >= FW_BOLD)
{
TRACE("\n\tFont %s add bold", lpelf->elfLogFont.lfFaceName);
m_bBold = true;
}
else if (lpelf->elfLogFont.lfItalic)
{
TRACE("\n\tFont %s add italics", lpelf->elfLogFont.lfFaceName);
m_bItalics = true;
}
else
{
TRACE("\n\tFont %s add regular", lpelf->elfLogFont.lfFaceName);
m_bRegular = true;
}
}
return 1;
}
void CWizFontsEnumerator::Font::DoInit()
{
// Init flags
m_bRegular = m_bItalics = m_bBold = m_bUnderline = false;
// Init for enumeration
CClientDC dc(NULL);
LOGFONT lf;
memset (&lf, 0, sizeof(lf));
lf.lfCharSet = DEFAULT_CHARSET;
strcpy(lf.lfFaceName, m_Name);
Font_EnumStep temp(const_cast<Font&>(*this), dc);
// Enumeration procedure
EnumFontFamiliesEx (dc.m_hAttribDC, &lf, (FONTENUMPROC)::DetailsEnumProc, reinterpret_cast<LPARAM>(&temp), 0);
// Finish init:
m_bUnderline = true; // Always availible so far
// Allow for "synthesized" italic && bold variants
if (m_bRegular)
m_bItalics = m_bBold = true;
}
void CWizFontsEnumerator::Font::Initialize() const
{
if (m_bInited)
return;
const_cast<Font*>(this)->DoInit();
m_bInited = true;
}
void CWizFontsEnumerator::Font::FillSizes(CWordArray& sizes) const
{
sizes.SetSize(0);
if (m_dwFontType != RASTER_FONTTYPE)
{
sizes.SetSize(TTDefaultsSize);
for (int i = 0; i < TTDefaultsSize; i++)
sizes[i] = TTDefaults[i];
}
else
{
Initialize();
sizes.SetSize(m_sizes.GetSize());
for (int i = 0; i < m_sizes.GetSize(); i++)
sizes[i] = m_sizes[i];
}
}
bool CWizFontsEnumerator::Font::CanBeItalics () const
{
Initialize();
return m_bItalics;
}
bool CWizFontsEnumerator::Font::CanBeBold () const
{
Initialize();
return m_bBold;
}
bool CWizFontsEnumerator::Font::CanBeUnderline () const
{
Initialize();
return m_bUnderline;
}
bool CWizFontsEnumerator::Font::CanBeRegular () const
{
Initialize();
return m_bRegular;
}
bool CWizFontsEnumerator::Font::MustBeRegular () const
{
Initialize();
return (m_bRegular && !(m_bItalics || m_bUnderline || m_bBold));
}
bool CWizFontsEnumerator::Font::MustBeItalics () const
{
Initialize();
return (m_bItalics && !(m_bRegular /*|| m_bUnderline || m_bBold*/));
}
bool CWizFontsEnumerator::Font::MustBeBold () const
{
Initialize();
return (m_bBold && !(m_bRegular /*|| m_bItalics || m_bUnderline*/));
}
bool CWizFontsEnumerator::Font::MustBeUnderline () const
{
Initialize();
return false;// (m_bUnderline && !(m_bRegular || m_bItalics || m_bBold));
}
void CWizFontsEnumerator::Font::AddSize(int pp_size, int lf_height)
{
m_sizes.Add(WORD(pp_size));
}
void CWizFontsEnumerator::Font::AddScript(LPCTSTR Script)
{
m_Script.Add(Script);
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWizFontsEnumerator::CWizFontsEnumerator()
{
}
CWizFontsEnumerator::~CWizFontsEnumerator()
{
}
int CWizFontsEnumerator::DoEnumStep (const ENUMLOGFONTEX *lpelfe, const NEWTEXTMETRICEX *lpntme, unsigned long FontType)
{
CString script = lpelfe->elfScript;
TRACE("\nFont %s", lpelfe->elfLogFont.lfFaceName);
// If font exists yet
int nFont = FindFont(lpelfe->elfLogFont.lfFaceName);
if (nFont >= 0)
{
m_aFonts.ElementAt(nFont).AddScript(script);
TRACE(" Add script %s", (LPCTSTR)script);
return 1;
}
// add font to list
Font f (lpelfe->elfLogFont, FontType, script);
int i = m_aFonts.Add(f);
if (i < 0)
{ ASSERT(0); AfxThrowMemoryException(); }
TRACE(" Script %s", (LPCTSTR)script);
return 1;
}
int CALLBACK EnumProc (const ENUMLOGFONTEX *lpelfe, const NEWTEXTMETRICEX *lpntme, unsigned long FontType, LPARAM lParam)
{
CWizFontsEnumerator* pTHIS = reinterpret_cast<CWizFontsEnumerator*>(lParam);
return pTHIS->DoEnumStep (lpelfe, lpntme, FontType);
}
void CWizFontsEnumerator::DoEnumerate (HDC hdc)
{
ASSERT(NULL != hdc);
m_aFonts.RemoveAll();
LOGFONT lf;
memset (&lf, 0, sizeof(lf));
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfFaceName[0]= 0;
EnumFontFamiliesEx (hdc, &lf, (FONTENUMPROC)::EnumProc, reinterpret_cast<LPARAM>(this), 0);
#ifdef _DEBUG
TRACE("\nFound %d fonts:", m_aFonts.GetSize());
for (int i = 0; i < m_aFonts.GetSize(); i++)
{
const Font* p = GetFont(i);
TRACE("\n %s", (LPCTSTR)(p->Name()));
for (int j = 0; j < p->GetScriptsCount(); j++)
TRACE("\n\t %s", (LPCTSTR)(p->GetScript(j)));
}
#endif
}
void CWizFontsEnumerator::InternalEnumerate (HDC hdc, bool bWayBack)
{
// If no valid DC supplied
if (NULL == hdc && bWayBack)
{
TRACE0("Warni
没有合适的资源?快使用搜索试试~ 我知道了~
get_font_info_.rar_font_font info
共31个文件
h:9个
cpp:8个
ico:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 35 浏览量
2022-09-22
16:38:36
上传
评论
收藏 48KB RAR 举报
温馨提示
获取系统所有字体信息 ,并反映在界面上,很有意思的一个小程序~!
资源推荐
资源详情
资源评论
收起资源包目录
get_font_info_.rar (31个子文件)
get_font_info_
WizFontSizesComboBox.h 1KB
res
fontsTest.rc2 407B
fontsTest.ico 1KB
fontsTest.clw 3KB
WizFontSizesComboBox.cpp 2KB
icon1.ico 766B
WizFontScriptsComboBox.h 1KB
fontsTest.h 1KB
WizFontExampleStatic.cpp 3KB
WizFontsEnumerator.h 4KB
fontsTestDlg.h 2KB
fontsTest.dsw 781B
fontsTest.mak 9KB
WizFontsEnumerator.cpp 9KB
fontsTest.001 5KB
StdAfx.cpp 207B
resource.h 1009B
fontsTest.rc 7KB
fontsTest.opt 63KB
WizFontScriptsComboBox.cpp 1KB
fontsTest.cpp 2KB
StdAfx.h 1010B
fontsTest.dsp 5KB
WizFontExampleStatic.h 1KB
fontsTest.ncb 73KB
fontsTestDlg.cpp 6KB
WizFontNamesComboBox.h 1KB
WizFontNamesComboBox.cpp 2KB
fontsTest.aps 36KB
fontsTest.plg 1KB
www.pudn.com.txt 218B
共 31 条
- 1
资源评论
邓凌佳
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功