aboutsummaryrefslogtreecommitdiff
path: root/source/30-game/FontManager.cpp
blob: 11a3a5ba23a2d207791e9af3544bde8d140f9f70 (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
#include "FontManager.hpp"

RcPtr<Font> FontManager::sans{ new Font() };
RcPtr<Font> FontManager::serif{ new Font() };
RcPtr<Font> FontManager::monospace{ new Font() };

const RcPtr<Font>& FontManager::GetDefaultFont() {
	return sans;
}

const Font* FontManager::ResolveFallback(const Font* font) {
	if (font == nullptr) {
		return FontManager::sans.Get();
	} else {
		return font;
	}
}

const RcPtr<Font>& FontManager::ResolveFallback(const RcPtr<Font>& font) {
	if (font == nullptr) {
		return FontManager::sans;
	} else {
		return font;
	}
}

void FontManager::Init() {
	Font::LoadingCandidate sansFiles[] = {
		{
			.ttfPath = "fonts/NotoSans-Regular.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Regular,
		},
		{
			.ttfPath = "fonts/NotoSans-Italic.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Italic,
		},
		{
			.ttfPath = "fonts/NotoSans-Bold.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Bold,
		},
		{
			.ttfPath = "fonts/NotoSans-BoldItalic.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::BoldItalic,
		},
		{
			.ttfPath = "fonts/NotoSansSC-Regular.otf",
			.glyphRange = Font::GetGlyphRangesChineseSimplifiedCommon(),
			.type = FontType::Regular,
		},
	};

	sans->Init(sansFiles, 18.0f);

	Font::LoadingCandidate serifFiles[] = {
		{
			.ttfPath = "fonts/NotoSerif-Regular.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Regular,
		},
		{
			.ttfPath = "fonts/NotoSerif-Italic.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Italic,
		},
		{
			.ttfPath = "fonts/NotoSerif-Bold.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Bold,
		},
		{
			.ttfPath = "fonts/NotoSerif-BoldItalic.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::BoldItalic,
		},
	};
	
	serif->Init(sansFiles, 18.0f);

	Font::LoadingCandidate monospacedFiles[] = {
		{
			.ttfPath = "fonts/NotoMono-Regular.ttf",
			.glyphRange = Font::GetGlyphRangesDefault(),
			.type = FontType::Regular,
		},
	};
	monospace->Init(monospacedFiles, 18.0f);
}

void FontManager::Shutdown() {
}