diff --git a/src/font.cpp b/src/font.cpp index a508d1e..d6b8100 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -15,19 +15,24 @@ using namespace std; Font *Font::defaultFont() +{ + return new Font(TTF_FONT, TTF_FONT_SIZE); +} + +Font::Font(const std::string &path, unsigned int size) { if (!TTF_WasInit() && TTF_Init() < 0) { ERROR("Unable to init SDL_ttf library\n"); - return nullptr; + return; } - TTF_Font *font = TTF_OpenFont(TTF_FONT, TTF_FONT_SIZE); + font = TTF_OpenFont(path.c_str(), size); if (!font) { ERROR("Unable to open font\n"); - return nullptr; + return; } - return new Font(font); + fontheight = TTF_FontHeight(font); } Font::Font(TTF_Font *font) diff --git a/src/font.h b/src/font.h index 4f76962..e7e8dd3 100644 --- a/src/font.h +++ b/src/font.h @@ -19,6 +19,7 @@ public: * or nullptr if there was a problem creating it. */ static Font *defaultFont(); + Font(const std::string &path, unsigned int size); ~Font(); int getTextWidth(const char *text); diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 5118bdc..e34f42b 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -349,8 +349,16 @@ void GMenu2X::initBG() { } void GMenu2X::initFont() { - delete font; - font = Font::defaultFont(); + const string path = skinConfStr["font"]; + if (!path.empty()) { + unsigned int size = skinConfInt["fontsize"]; + if (!size) + size = 12; + font = new Font(path, size); + } else { + font = Font::defaultFont(); + } + if (!font) { ERROR("Cannot function without font; aborting...\n"); quit();