forked from tapetums/include
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Font.hpp
78 lines (61 loc) · 1.81 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
#pragma once
//---------------------------------------------------------------------------//
//
// Font.hpp
// フォントの作成および破棄
// Copyright (C) 2014-2016 tapetums
//
//---------------------------------------------------------------------------//
#include <windows.h>
//---------------------------------------------------------------------------//
namespace tapetums
{
class Font;
}
//---------------------------------------------------------------------------//
class tapetums::Font
{
private:
INT32 size { 0 };
INT32 weight { 0 };
HFONT font { nullptr };
LPCTSTR name { nullptr };
public:
Font() noexcept = default;
~Font() { free(); }
Font(const Font& lhs) { create(lhs.size, lhs.name, lhs.weight); }
Font& operator =(const Font& lhs) { create(lhs.size, lhs.name, lhs.weight); return *this; }
Font(Font&&) noexcept = default;
Font& operator =(Font&&) noexcept = default;
Font(INT32 font_size, LPCTSTR font_name, INT32 cWeight = FW_REGULAR) { create(font_size, font_name, cWeight); }
public:
operator HFONT() { return font; }
public:
HFONT create
(
INT32 font_size, LPCTSTR font_name, INT32 cWeight = FW_REGULAR
)
{
font = ::CreateFont
(
font_size, 0, 0, 0,
cWeight, FALSE, FALSE, FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
font_name
);
if ( font )
{
size = font_size;
name = font_name;
weight = cWeight;
}
return font;
}
void free()
{
if ( font ) { ::DeleteObject(font); font = nullptr; }
}
};
//---------------------------------------------------------------------------//
// Font.hpp