summaryrefslogtreecommitdiff
path: root/FontInfo.h
blob: 7385c331a614815ffba4769eb330722abaf37125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// FontInfo.h : Declaration of the CFontInfo

#ifndef __FONTINFO_H_
#define __FONTINFO_H_

#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// CFontInfo
class ATL_NO_VTABLE CFontInfo : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CFontInfo, &CLSID_FontInfo>,
	public ISupportErrorInfo,
	public IDispatchImpl<ITrueTypeFontInfo, &IID_ITrueTypeFontInfo, &LIBID_TtfInfoLib>
{
public:
	CFontInfo()
	{
		OSVERSIONINFO info = {0};
		info.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
		GetVersionEx( &info );

		if ( VER_PLATFORM_WIN32_NT == info.dwPlatformId )
			m_strFontsKey = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts");
		else
			m_strFontsKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts");

		Initialize();
	}

DECLARE_REGISTRY_RESOURCEID(IDR_FONTINFO)

BEGIN_COM_MAP(CFontInfo)
	COM_INTERFACE_ENTRY(ITrueTypeFontInfo)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

// Attributes
protected:
	_bstr_t m_bstrFileName;
	_bstr_t m_bstrCopyright;
	_bstr_t m_bstrFamily;
	_bstr_t m_bstrID;
	_bstr_t m_bstrName;
	_bstr_t m_bstrPostscriptName;
	_bstr_t m_bstrSubfamily;
	_bstr_t m_bstrTrademark;
	_bstr_t m_bstrVersion;
	static LPCTSTR m_strFontsKey;

// Inline helpers
public:
	inline void Initialize();
	inline _bstr_t GetRegistryFontName() const;
	inline static LONG OpenFontsKey( CRegKey& reg, REGSAM samDesired = KEY_ALL_ACCESS );


// ISupportsErrorInfo
public:
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// ITrueTypeFontInfo
public:
	STDMETHOD(Uninstall)(/*[in, optional]*/ VARIANT_BOOL bPermanent);
	STDMETHOD(Install)(/*[in, optional]*/ VARIANT_BOOL bPermanent);
	STDMETHOD(GetFontsDirectory)(/*[out, retval]*/ BSTR* pVal);
	STDMETHOD(get_RegisteredFileName)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_Version)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_Trademark)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_Subfamily)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_PostscriptName)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_Name)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_ID)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_Family)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_Copyright)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(get_FileName)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_FileName)(/*[in]*/ BSTR newVal);
	STDMETHOD(get__FileName)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put__FileName)(/*[in]*/ BSTR newVal);
};

///////////////////////////////////////////////////////////////////////////////////
//		Inline Helpers
///////////////////////////////////////////////////////////////////////////////////

inline void CFontInfo::Initialize()
{
	m_bstrFileName = "";
	m_bstrCopyright = "";
	m_bstrFamily = "";
	m_bstrID = "";
	m_bstrName = "";
	m_bstrPostscriptName = "";
	m_bstrSubfamily = "";
	m_bstrTrademark = "";
	m_bstrVersion = "";
}

inline _bstr_t CFontInfo::GetRegistryFontName() const
{
	return m_bstrName + _T(" (TrueType)");
}

inline LONG CFontInfo::OpenFontsKey( CRegKey& reg, REGSAM samDesired /* = KEY_ALL_ACCESS */ )
{
	return reg.Open( HKEY_LOCAL_MACHINE, m_strFontsKey, samDesired );		
}


#endif //__FONTINFO_H_