-
Notifications
You must be signed in to change notification settings - Fork 1
/
Font.hpp
111 lines (88 loc) · 2.63 KB
/
Font.hpp
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
#pragma once
//---------------------------------------------------------------------------//
//
// Font.hpp
// RAII class for Windows fonts
// Copyright (C) 2014-2018 tapetums
//
//---------------------------------------------------------------------------//
#include <windows.h>
//---------------------------------------------------------------------------//
// Forward Declarations
//---------------------------------------------------------------------------//
namespace tapetums
{
class Font;
}
//---------------------------------------------------------------------------//
// Classes
//---------------------------------------------------------------------------//
class tapetums::Font final
{
private: // members
HFONT m_font { nullptr };
public: // ctor / dtor
Font() = default;
~Font() { Free(); }
Font(const Font& lhs) = delete;
Font& operator =(const Font& lhs) = delete;
Font(Font&&) noexcept = default;
Font& operator =(Font&&) noexcept = default;
Font(INT32 size, LPCTSTR name, INT32 weight = FW_REGULAR)
{
Create(size, name, weight);
}
public: // accessors
HFONT handle() const noexcept { return m_font; }
public: // operators
operator HFONT() const noexcept { return m_font; }
public: // methods
HFONT Create(INT32 size, LPCSTR name, INT32 weight = FW_REGULAR);
HFONT Create(INT32 size, LPCWSTR name, INT32 weight = FW_REGULAR);
void Free();
};
//---------------------------------------------------------------------------//
// Font Methods
//---------------------------------------------------------------------------//
inline HFONT tapetums::Font::Create
(
INT32 size, LPCSTR name, INT32 weight
)
{
m_font = ::CreateFontA
(
size, 0, 0, 0,
weight, FALSE, FALSE, FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
name
);
return m_font;
}
//---------------------------------------------------------------------------//
inline HFONT tapetums::Font::Create
(
INT32 size, LPCWSTR name, INT32 weight
)
{
m_font = ::CreateFontW
(
size, 0, 0, 0,
weight, FALSE, FALSE, FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
name
);
return m_font;
}
//---------------------------------------------------------------------------//
inline void tapetums::Font::Free()
{
if ( m_font )
{
::DeleteObject(m_font);
m_font = nullptr;
}
}
//---------------------------------------------------------------------------//
// Font.hpp