diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-12 21:26:03 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-12 21:26:03 +0100 |
commit | 5ef7c56e44a864e580810952450c43c0f9a7b6e0 (patch) | |
tree | 2a0faeaef514558b991832fbae63500f9f6e0228 /src/crepe/facade/SDLFontContext.cpp | |
parent | f9f06f54dd1a66350afd42f6eec761565a4d3d77 (diff) |
make format
Diffstat (limited to 'src/crepe/facade/SDLFontContext.cpp')
-rw-r--r-- | src/crepe/facade/SDLFontContext.cpp | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/src/crepe/facade/SDLFontContext.cpp b/src/crepe/facade/SDLFontContext.cpp index 851016b..2bccac4 100644 --- a/src/crepe/facade/SDLFontContext.cpp +++ b/src/crepe/facade/SDLFontContext.cpp @@ -2,54 +2,52 @@ #include "SDLFontContext.h" - using namespace crepe; using namespace std; -SDLFontContext::SDLFontContext(){ +SDLFontContext::SDLFontContext() { if (!FcInit()) { - throw runtime_error("Failed to initialize Fontconfig."); - } + throw runtime_error("Failed to initialize Fontconfig."); + } } -SDLFontContext::~SDLFontContext(){ - FcFini(); -} +SDLFontContext::~SDLFontContext() { FcFini(); } unique_ptr<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) { - throw runtime_error("Failed to create font pattern."); - } - - // Default configuration - FcConfig* config = FcConfigGetCurrent(); - if (!config) { - FcPatternDestroy(pattern); - throw runtime_error("Failed to get current Fontconfig configuration."); - } - - // Match the font pattern - FcResult result; - FcPattern* matched_pattern = FcFontMatch(config, pattern, &result); - FcPatternDestroy(pattern); - - if (!matched_pattern) { + + // Create a pattern to search for the font family + FcPattern * pattern = FcNameParse(reinterpret_cast<const FcChar8 *>(font_family.c_str())); + if (!pattern) { + throw runtime_error("Failed to create font pattern."); + } + + // Default configuration + FcConfig * config = FcConfigGetCurrent(); + if (!config) { + FcPatternDestroy(pattern); + throw runtime_error("Failed to get current Fontconfig configuration."); + } + + // Match the font pattern + FcResult result; + FcPattern * matched_pattern = FcFontMatch(config, pattern, &result); + FcPatternDestroy(pattern); + + if (!matched_pattern) { FcPatternDestroy(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); - 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); - return move(make_unique<Asset>(font_file_path)); + 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); + 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); + return move(make_unique<Asset>(font_file_path)); } |