aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/FontFacade.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 13:22:34 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 13:22:34 +0100
commitb99f5fc0f52fdd4ec96be844e643060503a8860b (patch)
treedbf0efa56ad98debbb2aa288866ec4a1fbf80d55 /src/crepe/facade/FontFacade.cpp
parent3b5b5258b0f46a3492a7fd777908dfb01e15417b (diff)
text now working with optional
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);
}