diff options
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); } |