diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-14 14:37:55 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-14 14:37:55 +0100 |
commit | aa1f1f9460fa713e00fd1830b08be743395110ce (patch) | |
tree | bdb8178c283c27cd9b261675822aa6d784dfe23f /src/crepe/facade/Font.cpp | |
parent | 86e3dcbc1e5b2fe07d89d6cde21f4b9e687962fa (diff) |
sdl_ttf to submodules + feedback changes
Diffstat (limited to 'src/crepe/facade/Font.cpp')
-rw-r--r-- | src/crepe/facade/Font.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index a39af75..f111af9 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -8,17 +8,12 @@ using namespace crepe; Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator), font(nullptr, TTF_CloseFont) { - // Get the font file path from the Asset - const std::string font_path = src.get_path(); - - // Attempt to load the font - this->font.reset(TTF_OpenFont(font_path.c_str(), Config::get_instance().font.size)); - - // Check if font loading failed - if (!this->font) { - throw runtime_error(format("Failed to load font from path: {}. SDL_ttf error: {}", - font_path, TTF_GetError())); - } + Config & config = Config::get_instance(); + const std::string FONT_PATH = src.get_path(); + TTF_Font * font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size); + if (font == NULL) + throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH)); + this->font = { font, [] (TTF_Font * font) { TTF_CloseFont(font); } }; } TTF_Font * Font::get_font() const { return this->font.get(); } |