aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/Font.cpp
blob: 66835eed04c6c2101c82ec8bff94dfd4a55d3175 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "../api/Config.h"

#include "font.h"

using namespace std;
using namespace crepe;

void Font::load(unique_ptr<Asset> res){
	const char* font_path = res->get_path();
    this->font = std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)>(
        TTF_OpenFont(font_path, this->default_font_size), &TTF_CloseFont); 

    if (!font) {
        throw std::runtime_error("Failed to load font: " + std::string(TTF_GetError()));
    }
}

Font::Font(const char* src){
	this->load(make_unique<Asset>(src));
}

Font::Font(std::unique_ptr<Asset> res){
	this->load(std::move(res));
}

TTF_Font* Font::get_font() const{
	return this->font.get();
}