diff --git a/src/driver/neutrinofonts.cpp b/src/driver/neutrinofonts.cpp index 0b429bb17..8773a96a9 100644 --- a/src/driver/neutrinofonts.cpp +++ b/src/driver/neutrinofonts.cpp @@ -60,6 +60,11 @@ CNeutrinoFonts::CNeutrinoFonts() old_fontDescr.filename = ""; old_fontDescr.size_offset = 0; + for (int i = 0; i < SNeutrinoSettings::FONT_TYPE_COUNT; i++) + g_Font[i] = NULL; + + g_SignalFont = NULL; + InitDynFonts(); } @@ -101,42 +106,65 @@ CNeutrinoFonts* CNeutrinoFonts::getInstance() return nf; } -void CNeutrinoFonts::SetupNeutrinoFonts() +void CNeutrinoFonts::SetupDynamicFonts(bool initRenderClass/*=true*/) { - if (g_fontRenderer != NULL) - delete g_fontRenderer; - g_fontRenderer = new FBFontRenderClass(72 * g_settings.screen_xres / 100, 72 * g_settings.screen_yres / 100); + if (initRenderClass) { + if (g_dynFontRenderer != NULL) + delete g_dynFontRenderer; + g_dynFontRenderer = new FBFontRenderClass(); - old_fontDescr.size_offset = fontDescr.size_offset; - old_fontDescr.filename = fontDescr.filename; - fontDescr.filename = ""; - printf("[neutrino] settings font file %s\n", g_settings.font_file); - if (access(g_settings.font_file, F_OK)) { - if (!access(FONTDIR"/neutrino.ttf", F_OK)) { - fontDescr.filename = FONTDIR"/neutrino.ttf"; - strcpy(g_settings.font_file, fontDescr.filename.c_str()); - } else { - fprintf( stderr,"[neutrino] font file [%s] not found\n neutrino exit\n",FONTDIR"/neutrino.ttf"); - _exit(0); + dynFontStyle[0] = g_dynFontRenderer->AddFont(fontDescr.filename.c_str()); + + fontDescr.name = g_dynFontRenderer->getFamily(fontDescr.filename.c_str()); + printf("[neutrino] font family %s\n", fontDescr.name.c_str()); + dynFontStyle[1] = "Bold Regular"; + + g_dynFontRenderer->AddFont(fontDescr.filename.c_str(), true); // make italics + dynFontStyle[2] = "Italic"; + } +} + +void CNeutrinoFonts::SetupNeutrinoFonts(bool initRenderClass/*=true*/) +{ + if (initRenderClass) { + if (g_fontRenderer != NULL) + delete g_fontRenderer; + g_fontRenderer = new FBFontRenderClass(72 * g_settings.screen_xres / 100, 72 * g_settings.screen_yres / 100); + + old_fontDescr.size_offset = fontDescr.size_offset; + old_fontDescr.filename = fontDescr.filename; + fontDescr.filename = ""; + printf("[neutrino] settings font file %s\n", g_settings.font_file); + if (access(g_settings.font_file, F_OK)) { + if (!access(FONTDIR"/neutrino.ttf", F_OK)) { + fontDescr.filename = FONTDIR"/neutrino.ttf"; + strcpy(g_settings.font_file, fontDescr.filename.c_str()); + } + else { + fprintf( stderr,"[neutrino] font file [%s] not found\n neutrino exit\n",FONTDIR"/neutrino.ttf"); + _exit(0); + } } + else + fontDescr.filename = g_settings.font_file; - } else - fontDescr.filename = g_settings.font_file; - fontStyle[0] = g_fontRenderer->AddFont(fontDescr.filename.c_str()); + fontStyle[0] = g_fontRenderer->AddFont(fontDescr.filename.c_str()); - old_fontDescr.name = fontDescr.name; - fontDescr.name = ""; - fontDescr.name = g_fontRenderer->getFamily(fontDescr.filename.c_str()); - printf("[neutrino] font family %s\n", fontDescr.name.c_str()); - fontStyle[1] = "Bold Regular"; + old_fontDescr.name = fontDescr.name; + fontDescr.name = ""; + fontDescr.name = g_fontRenderer->getFamily(fontDescr.filename.c_str()); + printf("[neutrino] font family %s\n", fontDescr.name.c_str()); + fontStyle[1] = "Bold Regular"; - g_fontRenderer->AddFont(fontDescr.filename.c_str(), true); // make italics - fontStyle[2] = "Italic"; + g_fontRenderer->AddFont(fontDescr.filename.c_str(), true); // make italics + fontStyle[2] = "Italic"; + } for (int i = 0; i < SNeutrinoSettings::FONT_TYPE_COUNT; i++) { if (g_Font[i]) delete g_Font[i]; g_Font[i] = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[neutrino_font[i].style].c_str(), CNeutrinoApp::getInstance()->getConfigFile()->getInt32(locale_real_names[neutrino_font[i].name], neutrino_font[i].defaultsize) + neutrino_font[i].size_offset * fontDescr.size_offset); } + if (g_SignalFont) delete g_SignalFont; g_SignalFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[signal_font.style].c_str(), signal_font.defaultsize + signal_font.size_offset * fontDescr.size_offset); } @@ -177,7 +205,7 @@ void CNeutrinoFonts::refreshDynFont(int dx, int dy, std::string text, int style, if (dyn_font->font != NULL) delete dyn_font->font; - Font *dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize); + Font *dynFont = g_dynFontRenderer->getFont(fontDescr.name.c_str(), dynFontStyle[style].c_str(), dynSize); dyn_font->font = dynFont; dyn_font->size = dynSize; if (dyn_font->size != dynSize) @@ -197,8 +225,6 @@ int CNeutrinoFonts::getFontHeight(Font* fnt) int CNeutrinoFonts::getDynFontSize(int dx, int dy, std::string text, int style) { Font *dynFont = NULL; - int _width = 0; - int _height = 0; int dynSize = 8; bool dynFlag = false; @@ -206,7 +232,9 @@ int CNeutrinoFonts::getDynFontSize(int dx, int dy, std::string text, int style) while (1) { if (dynFont != NULL) delete dynFont; - dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize); + dynFont = g_dynFontRenderer->getFont(fontDescr.name.c_str(), dynFontStyle[style].c_str(), dynSize); + int _width = 0; + int _height = 0; // calculate height & width _height = getFontHeight(dynFont); std::string tmpText = text; @@ -273,8 +301,10 @@ Font **CNeutrinoFonts::getDynFontWithID(int &dx, int &dy, std::string text, int { if ((dx <= 0) && (dy <= 0)) return NULL; - if ((fontDescr.name == "") || (fontDescr.filename == "") || (g_fontRenderer == NULL)) + if ((fontDescr.name == "") || (fontDescr.filename == "")) SetupNeutrinoFonts(); + if (g_dynFontRenderer == NULL) + SetupDynamicFonts(); int dynSize = getDynFontSize(dx, dy, text, style); Font *dynFont = NULL; @@ -288,7 +318,7 @@ Font **CNeutrinoFonts::getDynFontWithID(int &dx, int &dy, std::string text, int return &(v_dyn_fonts[f_id].font); } - dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize); + dynFont = g_dynFontRenderer->getFont(fontDescr.name.c_str(), dynFontStyle[style].c_str(), dynSize); if (v_dyn_fonts[f_id].font != NULL) delete v_dyn_fonts[f_id].font; v_dyn_fonts[f_id].dx = dx; @@ -314,7 +344,7 @@ Font **CNeutrinoFonts::getDynFontShare(int &dx, int &dy, std::string text, int s { if ((dx <= 0) && (dy <= 0)) return NULL; - if ((fontDescr.name == "") || (fontDescr.filename == "") || (g_fontRenderer == NULL)) + if ((fontDescr.name == "") || (fontDescr.filename == "") || (g_dynFontRenderer == NULL)) SetupNeutrinoFonts(); int dynSize = getDynFontSize(dx, dy, text, style); @@ -342,7 +372,7 @@ Font **CNeutrinoFonts::getDynFontShare(int &dx, int &dy, std::string text, int s ret = &(v_share_fonts[i].font); } else { - dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize); + dynFont = g_dynFontRenderer->getFont(fontDescr.name.c_str(), dynFontStyle[style].c_str(), dynSize); dyn_font_t dyn_font; dyn_font.dx = dx; dyn_font.dy = dy; diff --git a/src/driver/neutrinofonts.h b/src/driver/neutrinofonts.h index 959e7b9e5..d03edf779 100644 --- a/src/driver/neutrinofonts.h +++ b/src/driver/neutrinofonts.h @@ -52,6 +52,7 @@ class CNeutrinoFonts { private: std::string fontStyle[3]; + std::string dynFontStyle[3]; typedef struct dyn_font_t { @@ -91,6 +92,14 @@ class CNeutrinoFonts FONT_ID_MAX }; + enum { + FONTSETUP_NEUTRINO_FONT = 1, /* refresh neutrino fonts */ + FONTSETUP_NEUTRINO_FONT_INST = 2, /* delete & initialize font renderer class */ + FONTSETUP_DYN_FONT = 4, /* refresh dynamic fonts */ + FONTSETUP_DYN_FONT_INST = 8, /* delete & initialize font renderer class */ + + FONTSETUP_ALL = FONTSETUP_NEUTRINO_FONT | FONTSETUP_NEUTRINO_FONT_INST | FONTSETUP_DYN_FONT | FONTSETUP_DYN_FONT_INST + }; CNeutrinoFonts(); ~CNeutrinoFonts(); @@ -99,7 +108,8 @@ class CNeutrinoFonts neutrino_font_descr_struct fontDescr; neutrino_font_descr_struct old_fontDescr; - void SetupNeutrinoFonts(); + void SetupNeutrinoFonts(bool initRenderClass = true); + void SetupDynamicFonts(bool initRenderClass = true); 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/global.h b/src/global.h index 2870b54b2..73322e913 100644 --- a/src/global.h +++ b/src/global.h @@ -87,6 +87,7 @@ NEUTRINO_CPP CSectionsdClient *g_Sectionsd; NEUTRINO_CPP CTimerdClient *g_Timerd; NEUTRINO_CPP FBFontRenderClass *g_fontRenderer; +NEUTRINO_CPP FBFontRenderClass *g_dynFontRenderer; NEUTRINO_CPP Font * g_Font[SNeutrinoSettings::FONT_TYPE_COUNT]; NEUTRINO_CPP Font * g_SignalFont; diff --git a/src/gui/osd_setup.cpp b/src/gui/osd_setup.cpp index dcfd32b9d..6deb82a34 100644 --- a/src/gui/osd_setup.cpp +++ b/src/gui/osd_setup.cpp @@ -194,7 +194,7 @@ int COsdSetup::exec(CMenuTarget* parent, const std::string &actionKey) { strcpy(g_settings.font_file, fileBrowser.getSelectedFile()->Name.c_str()); printf("[neutrino] new font file %s\n", fileBrowser.getSelectedFile()->Name.c_str()); - CNeutrinoApp::getInstance()->SetupFonts(); + CNeutrinoApp::getInstance()->SetupFonts(CNeutrinoFonts::FONTSETUP_ALL); osdFontFile = "(" + getBaseName(fileBrowser.getSelectedFile()->Name) + ")"; mfFontFile->setOption(osdFontFile.c_str()); } @@ -211,7 +211,7 @@ int COsdSetup::exec(CMenuTarget* parent, const std::string &actionKey) strcpy(g_settings.ttx_font_file, fileBrowser.getSelectedFile()->Name.c_str()); ttx_font_file = fileBrowser.getSelectedFile()->Name; printf("[neutrino] ttx font file %s\n", fileBrowser.getSelectedFile()->Name.c_str()); - CNeutrinoApp::getInstance()->SetupFonts(); + CNeutrinoApp::getInstance()->SetupFonts(CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT | CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT_INST); osdTtxFontFile = "(" + getBaseName(fileBrowser.getSelectedFile()->Name) + ")"; mfTtxFontFile->setOption(osdTtxFontFile.c_str()); } @@ -253,7 +253,7 @@ int COsdSetup::exec(CMenuTarget* parent, const std::string &actionKey) printf("[neutrino] new font scale settings x: %d%% y: %d%%\n", xre, yre); g_settings.screen_xres = xre; g_settings.screen_yres = yre; - CNeutrinoApp::getInstance()->SetupFonts(); + CNeutrinoApp::getInstance()->SetupFonts(CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT | CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT_INST); } //return menu_return::RETURN_REPAINT; return res; diff --git a/src/neutrino.cpp b/src/neutrino.cpp index cdcdfed51..2250b2dd0 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -1522,12 +1522,18 @@ void CNeutrinoApp::SetupFrameBuffer() * CNeutrinoApp - setup fonts * **************************************************************************************/ -void CNeutrinoApp::SetupFonts() +void CNeutrinoApp::SetupFonts(int fmode) { if (neutrinoFonts == NULL) neutrinoFonts = CNeutrinoFonts::getInstance(); - neutrinoFonts->SetupNeutrinoFonts(); - neutrinoFonts->refreshDynFonts(); + + if ((fmode & CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT) == CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT) + neutrinoFonts->SetupNeutrinoFonts(((fmode & CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT_INST) == CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT_INST)); + + if ((fmode & CNeutrinoFonts::FONTSETUP_DYN_FONT) == CNeutrinoFonts::FONTSETUP_DYN_FONT) { + neutrinoFonts->SetupDynamicFonts(((fmode & CNeutrinoFonts::FONTSETUP_DYN_FONT_INST) == CNeutrinoFonts::FONTSETUP_DYN_FONT_INST)); + neutrinoFonts->refreshDynFonts(); + } /* recalculate infobar position */ if (g_InfoViewer) @@ -3462,6 +3468,7 @@ int CNeutrinoApp::exec(CMenuTarget* parent, const std::string & actionKey) delete g_Sectionsd; delete g_RemoteControl; delete g_fontRenderer; + delete g_dynFontRenderer; delete hintBox; @@ -3947,6 +3954,7 @@ void CNeutrinoApp::Cleanup() printf("cleanup 11\n");fflush(stdout); delete g_fontRenderer; g_fontRenderer = NULL; + delete g_dynFontRenderer; g_dynFontRenderer = NULL; printf("cleanup 12\n");fflush(stdout); delete g_PicViewer; g_PicViewer = NULL; printf("cleanup 13\n");fflush(stdout); diff --git a/src/neutrino.h b/src/neutrino.h index 133a29310..d93fd5d3e 100644 --- a/src/neutrino.h +++ b/src/neutrino.h @@ -37,6 +37,7 @@ #include #include "driver/framebuffer.h" +#include "driver/neutrinofonts.h" #include "system/setting_helpers.h" #include "system/configure_network.h" #include "daemonc/remotecontrol.h" /* st_rmsg */ @@ -153,7 +154,7 @@ public: void loadKeys(const char * fname = NULL); void saveKeys(const char * fname = NULL); void SetupTiming(); - void SetupFonts(); + void SetupFonts(int fmode = CNeutrinoFonts::FONTSETUP_ALL); void setupRecordingDevice(void); ~CNeutrinoApp(); diff --git a/src/system/setting_helpers.cpp b/src/system/setting_helpers.cpp index 99717e25f..b2ca12c00 100644 --- a/src/system/setting_helpers.cpp +++ b/src/system/setting_helpers.cpp @@ -316,7 +316,7 @@ bool CFontSizeNotifier::changeNotify(const neutrino_locale_t, void *) CHintBox hintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_FONTSIZE_HINT)); // UTF-8 hintBox.paint(); - CNeutrinoApp::getInstance()->SetupFonts(); + CNeutrinoApp::getInstance()->SetupFonts(CNeutrinoFonts::FONTSETUP_NEUTRINO_FONT); hintBox.hide(); /* recalculate infoclock/muteicon/volumebar */