aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/FontFacade.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade/FontFacade.cpp')
-rw-r--r--src/crepe/facade/FontFacade.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp
index d447b6d..0a8ba5f 100644
--- a/src/crepe/facade/FontFacade.cpp
+++ b/src/crepe/facade/FontFacade.cpp
@@ -1,4 +1,5 @@
#include <fontconfig/fontconfig.h>
+#include <iostream>
#include <stdexcept>
#include "FontFacade.h"
@@ -6,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 == NULL) {
@@ -32,7 +39,6 @@ Asset FontFacade::get_font_asset(const string& font_family) {
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
@@ -44,6 +50,5 @@ Asset FontFacade::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);
}