diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-17 13:31:34 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-17 13:31:34 +0100 |
commit | 24578c9afb61ae65b300dd7fb645220e133089be (patch) | |
tree | c6451ea01a56f0bde33a803ea37169f59d0fc41d /src/crepe/facade/FontFacade.cpp | |
parent | bcaee968761c1d2e85c20925b237480c87da9747 (diff) | |
parent | 707db8c94b6bb3921105f40658aab13511d8df07 (diff) |
Merge branch 'wouter/text-component' into niels/UI
Diffstat (limited to 'src/crepe/facade/FontFacade.cpp')
-rw-r--r-- | src/crepe/facade/FontFacade.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp index a0464e0..9919032 100644 --- a/src/crepe/facade/FontFacade.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -7,10 +7,16 @@ using namespace crepe; using namespace std; -Asset FontFacade::get_font_asset(const string font_family) { +FontFacade::FontFacade(){ if (!FcInit()) { throw runtime_error("Failed to initialize Fontconfig."); } +} +FontFacade::~FontFacade(){ + FcFini(); +} +Asset FontFacade::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) { @@ -19,8 +25,8 @@ Asset FontFacade::get_font_asset(const string font_family) { // Default configuration FcConfig * config = FcConfigGetCurrent(); - if (!config) { - FcPatternDestroy(pattern); + if (config == NULL) { + // FcPatternDestroy(pattern); throw runtime_error("Failed to get current Fontconfig configuration."); } @@ -32,18 +38,16 @@ Asset FontFacade::get_font_asset(const string font_family) { if (!matched_pattern) { throw runtime_error("No matching font found."); } - // Extract the file path FcChar8 * file_path = nullptr; if (FcPatternGetString(matched_pattern, FC_FILE, 0, &file_path) != FcResultMatch - || !file_path) { - FcPatternDestroy(matched_pattern); + || file_path == NULL) { + // FcPatternDestroy(matched_pattern); throw runtime_error("Failed to get font file path."); } // Convert the file path to a string string font_file_path = reinterpret_cast<const char *>(file_path); FcPatternDestroy(matched_pattern); - cout << font_file_path << endl; return Asset(font_file_path); } |