From c0b433c83d4162805e57e9757c3a695fd59ba435 Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Sun, 28 Jan 2018 23:54:39 +0100 Subject: [PATCH] - yaft: allow new shell.ttf in yaft-widget too Signed-off-by: Thilo Graf --- src/driver/neutrinofonts.cpp | 17 +++++++++++++---- src/driver/neutrinofonts.h | 1 + src/gui/widget/yaft/yaft_priv.cpp | 8 ++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/driver/neutrinofonts.cpp b/src/driver/neutrinofonts.cpp index 24d6f7d9b..e7639d2dd 100644 --- a/src/driver/neutrinofonts.cpp +++ b/src/driver/neutrinofonts.cpp @@ -193,6 +193,17 @@ void CNeutrinoFonts::SetupNeutrinoFonts(bool initRenderClass/*=true*/) g_SignalFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[signal_font.style].c_str(), fontSize); } +std::string CNeutrinoFonts::getShellTTF() +{ + const char *shell_ttf[2] = { FONTDIR_VAR "/shell.ttf", FONTDIR "/shell.ttf" }; + for (unsigned int i = 0; i < 2; i++) + { + if (access(shell_ttf[i], F_OK) == 0) + return (std::string)shell_ttf[i]; + } + return ""; +} + void CNeutrinoFonts::SetupShellFont() { if (g_ShellFont) @@ -201,10 +212,8 @@ void CNeutrinoFonts::SetupShellFont() g_ShellFont = NULL; } - std::string shell_ttf = FONTDIR_VAR "/shell.ttf"; - if (access(shell_ttf.c_str(), F_OK) != 0) - shell_ttf = FONTDIR "/shell.ttf"; - if (access(shell_ttf.c_str(), F_OK) != 0) + std::string shell_ttf = getShellTTF(); + if (shell_ttf.empty()) return; if (g_shellFontRenderer != NULL) diff --git a/src/driver/neutrinofonts.h b/src/driver/neutrinofonts.h index 5f3f8eb0f..e3e9525d1 100644 --- a/src/driver/neutrinofonts.h +++ b/src/driver/neutrinofonts.h @@ -131,6 +131,7 @@ class CNeutrinoFonts void SetupNeutrinoFonts(bool initRenderClass = true); void SetupDynamicFonts(bool initRenderClass = true); void SetupShellFont(); + std::string getShellTTF(); void refreshDynFonts(); Font **getDynFont(int &dx, int &dy, std::string text="", int style=FONT_STYLE_REGULAR, int share=FONT_ID_SHARE); void setFontUseDigitHeight(bool set=true) {useDigitOffset = set;} diff --git a/src/gui/widget/yaft/yaft_priv.cpp b/src/gui/widget/yaft/yaft_priv.cpp index 3f44eefb3..a23bb1315 100644 --- a/src/gui/widget/yaft/yaft_priv.cpp +++ b/src/gui/widget/yaft/yaft_priv.cpp @@ -26,6 +26,7 @@ #include "yaft_priv.h" #include +#include #include #include /* UTF8 conversion */ @@ -124,13 +125,16 @@ bool YaFT_p::init() * try to get a font size that fits about LINES x COLS into the terminal. * NOTE: this is not guaranteed to work! Terminal might be smaller or bigger */ + std::string shell_ttf = CNeutrinoFonts::getInstance()->getShellTTF(); + if (shell_ttf.empty()) + shell_ttf = ttx_font_file; if (paint) { for (int i = 0; i < 2; i++) { delete font; delete fr; fr = new FBFontRenderClass(scalex, scaley); - fontstyle = fr->AddFont(ttx_font_file.c_str()); - font = fr->getFont(fr->getFamily(ttx_font_file.c_str()).c_str(), fontstyle, height / LINES); + fontstyle = fr->AddFont(shell_ttf.c_str()); + font = fr->getFont(fr->getFamily(shell_ttf.c_str()).c_str(), fontstyle, height / LINES); /* getWidth() does not return good values, leading to "out of box" rendering later fw = font->getWidth(); ... so just let's get the width of a wide glyph (it's a monospace font after all */