-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cpp
67 lines (50 loc) · 1.6 KB
/
Utils.cpp
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
//---------------------------------------------------------------------------
#pragma hdrstop
#include <windows.h>
#include <memory>
#include "Utils.h"
using std::unique_ptr;
using std::make_unique;
//---------------------------------------------------------------------------
#pragma package(smart_init)
namespace AreaPrj {
unique_ptr<TStringList> RetrieveFontList()
{
auto SL = make_unique<TStringList>();
LOGFONT LFont {};
class DCMngr {
public:
DCMngr() : dc_( ::GetDC( {} ) ) { Win32Check( dc_ != HDC{} ); }
~DCMngr() { ::ReleaseDC( {}, dc_ ); }
HDC get() const { return dc_; }
private:
HDC dc_;
} DC;
LFont.lfCharSet = DEFAULT_CHARSET;
struct EnumFontFamExProc {
static int WINAPI Proc( LOGFONT const * Elfe, TEXTMETRIC const * Tme,
DWORD FontType, LPARAM LParam )
{
if ( FontType & TRUETYPE_FONTTYPE ) {
auto SL = reinterpret_cast<TStringList*>( LParam );
String const FontName{ Elfe->lfFaceName };
if ( !SL->Count ||
(
!SameText( FontName, SL->Strings[SL->Count-1] ) &&
!FontName.IsEmpty() && FontName[1] != _T( '@' )
)
) {
SL->Append( FontName );
}
}
return TRUE;
}
};
::EnumFontFamiliesEx(
DC.get(), &LFont, &EnumFontFamExProc::Proc,
reinterpret_cast<LONG_PTR>( SL.get() ), {}
);
SL->Sort();
return SL;
}
} // End of namespace AreaPrj