diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-16 19:08:22 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-16 19:08:22 +0100 |
commit | 55f4aaf179cf723c5b703b0c4d848bf059ae190a (patch) | |
tree | 56b7034d665783384415abc1a0e9282c194ae1c3 /src/crepe/facade | |
parent | 7f7f1237532b4318361e69349cc38f34fe981803 (diff) |
font family implemented in the text component
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/crepe/facade/FontFacade.cpp (renamed from src/crepe/facade/SDLFontContext.cpp) | 11 | ||||
-rw-r--r-- | src/crepe/facade/FontFacade.h | 28 | ||||
-rw-r--r-- | src/crepe/facade/SDLFontContext.h | 29 |
4 files changed, 33 insertions, 39 deletions
diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt index e61b680..243ae46 100644 --- a/src/crepe/facade/CMakeLists.txt +++ b/src/crepe/facade/CMakeLists.txt @@ -4,7 +4,7 @@ target_sources(crepe PUBLIC SoundContext.cpp SDLContext.cpp DB.cpp - SDLFontContext.cpp + FontFacade.cpp Font.cpp ) @@ -14,7 +14,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES SoundContext.h SDLContext.h DB.h - SDLFontContext.h + FontFacade.h Font.h ) diff --git a/src/crepe/facade/SDLFontContext.cpp b/src/crepe/facade/FontFacade.cpp index 45d70cb..12e10ed 100644 --- a/src/crepe/facade/SDLFontContext.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -2,21 +2,15 @@ #include <SDL2/SDL_ttf.h> #include <fontconfig/fontconfig.h> -#include "SDLFontContext.h" +#include "FontFacade.h" using namespace crepe; using namespace std; -SDLFontContext::SDLFontContext() { +Asset FontFacade::get_font_asset(const string font_family) { if (!FcInit()) { throw runtime_error("Failed to initialize Fontconfig."); } -} - -SDLFontContext::~SDLFontContext() { FcFini(); } - -Asset SDLFontContext::get_font_asset(const string font_family) { - // Create a pattern to search for the font family FcPattern * pattern = FcNameParse(reinterpret_cast<const FcChar8 *>(font_family.c_str())); if (pattern == NULL) { @@ -51,5 +45,6 @@ Asset SDLFontContext::get_font_asset(const string font_family) { // Convert the file path to a string string font_file_path(reinterpret_cast<const char *>(file_path)); FcPatternDestroy(matched_pattern); + FcFini(); return Asset(font_file_path); } diff --git a/src/crepe/facade/FontFacade.h b/src/crepe/facade/FontFacade.h new file mode 100644 index 0000000..1b835d4 --- /dev/null +++ b/src/crepe/facade/FontFacade.h @@ -0,0 +1,28 @@ +#pragma once + +#include <memory> + +#include "../api/Asset.h" + +namespace crepe { + +/** + * + * \brief Font facade class for converting font family names to absolute file paths + * + */ +class FontFacade { +public: + /** + * + * \brief Facade function to convert a font_family into an asset. + * + * This function uses the FontConfig library to convert a font family name (Arial, Inter, Helvetica) and converts it to the font source path. + * This function is static so the member function can be used without create a FontFacade object. This way it can be used in a constructor as FontFacade::get_font_asset(). + * \param font_family Name of the font family name. + * \return Asset with filepath to the font. + */ + static Asset get_font_asset(const std::string font_family); +}; + +} // namespace crepe diff --git a/src/crepe/facade/SDLFontContext.h b/src/crepe/facade/SDLFontContext.h deleted file mode 100644 index d15e1a3..0000000 --- a/src/crepe/facade/SDLFontContext.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - - -#include <memory> - -#include "../api/Asset.h" - -namespace crepe { -class SDLFontContext { -public: - SDLFontContext(); - ~SDLFontContext(); - SDLFontContext(const SDLFontContext &) = delete; - SDLFontContext(SDLFontContext &&) = delete; - SDLFontContext & operator=(const SDLFontContext &) = delete; - SDLFontContext & operator=(SDLFontContext &&) = delete; - /** - * - * \brief Facade function to convert a font_family into an asset. - * - * This function uses the FontConfig library to convert a font family name (Arial, Inter, Helvetica) and converts it to the font source path. - * - * \param font_family Name of the font family name. - */ - Asset get_font_asset(const std::string font_family); - -}; - -} // namespace crepe |