diff options
author | rtk0c <[email protected]> | 2022-11-25 17:28:07 -0800 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-11-25 17:28:07 -0800 |
commit | f3269a49c474ffe4d382c3d60826ad1cfbb7cdc4 (patch) | |
tree | bf7854505e9dae60c84e64764589c240339c3a41 /source/30-game/FontManager.cpp | |
parent | a0ddfdbcbc6336685362343518770f7bdefd10fe (diff) |
Changeset: 93 Branch comment: [] Port font and UTF-8 string utilities from p6503master-ui-framework
Diffstat (limited to 'source/30-game/FontManager.cpp')
-rw-r--r-- | source/30-game/FontManager.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/source/30-game/FontManager.cpp b/source/30-game/FontManager.cpp new file mode 100644 index 0000000..11a3a5b --- /dev/null +++ b/source/30-game/FontManager.cpp @@ -0,0 +1,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() { +} |