diff --git a/data/fonts/Makefile.am b/data/fonts/Makefile.am index 0a832e495..9188d5e07 100644 --- a/data/fonts/Makefile.am +++ b/data/fonts/Makefile.am @@ -21,6 +21,12 @@ if BOXMODEL_CST_HD2 install_DATA += UnDotum.ttf endif +if ! BOXMODEL_CST_HD1 +# icon font +install_DATA += \ + fa-solid-900.ttf +endif + install-data-hook: cd $(DESTDIR)$(FONTDIR); \ mv $(neutrino_ttf) neutrino.ttf; \ diff --git a/data/fonts/fa-solid-900.LICENSE b/data/fonts/fa-solid-900.LICENSE new file mode 100644 index 000000000..f31bef92b --- /dev/null +++ b/data/fonts/fa-solid-900.LICENSE @@ -0,0 +1,34 @@ +Font Awesome Free License +------------------------- + +Font Awesome Free is free, open source, and GPL friendly. You can use it for +commercial projects, open source projects, or really almost whatever you want. +Full Font Awesome Free license: https://fontawesome.com/license/free. + +# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/) +In the Font Awesome Free download, the CC BY 4.0 license applies to all icons +packaged as SVG and JS file types. + +# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL) +In the Font Awesome Free download, the SIL OFL license applies to all icons +packaged as web and desktop font files. + +# Code: MIT License (https://opensource.org/licenses/MIT) +In the Font Awesome Free download, the MIT license applies to all non-font and +non-icon files. + +# Attribution +Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font +Awesome Free files already contain embedded comments with sufficient +attribution, so you shouldn't need to do anything additional when using these +files normally. + +We've kept attribution comments terse, so we ask that you do not actively work +to remove them from files, especially code. They're a great way for folks to +learn about Font Awesome. + +# Brand Icons +All brand icons are trademarks of their respective owners. The use of these +trademarks does not indicate endorsement of the trademark holder by Font +Awesome, nor vice versa. **Please do not use brand logos for any purpose except +to represent the company, product, or service to which they refer.** diff --git a/data/fonts/fa-solid-900.ttf b/data/fonts/fa-solid-900.ttf new file mode 100644 index 000000000..35197cfa8 Binary files /dev/null and b/data/fonts/fa-solid-900.ttf differ diff --git a/src/driver/fontrenderer.cpp b/src/driver/fontrenderer.cpp index c194ce079..0a762e8aa 100644 --- a/src/driver/fontrenderer.cpp +++ b/src/driver/fontrenderer.cpp @@ -287,7 +287,18 @@ return 0; index=FT_Get_Char_Index(face, 'M'); // "M" gives us ascender getGlyphBitmap(index, &glyph); int tM=glyph->top; + fontwidth = glyph->width; + // walk through all chars to find fontwidth_widest + FT_UInt gindex = 0; + FT_ULong charcode = FT_Get_First_Char(face, &gindex); + while (gindex != 0) + { + getGlyphBitmap(gindex, &glyph); + fontwidth_widest = std::max(fontwidth, (int)glyph->width); + charcode = FT_Get_Next_Char(face, charcode, &gindex); + } + //printf("Font::setSize() %s: fontwidth=%d fontwidth_widest=%d\n", face->family_name, fontwidth, fontwidth_widest); index=FT_Get_Char_Index(face, 'g'); // "g" gives us descender getGlyphBitmap(index, &glyph); @@ -319,6 +330,11 @@ int Font::getWidth(void) return fontwidth; } +int Font::getWidestWidth(void) +{ + return fontwidth_widest; +} + int Font::getHeight(void) { return height; diff --git a/src/driver/fontrenderer.h b/src/driver/fontrenderer.h index 725ea8c47..c4068579a 100644 --- a/src/driver/fontrenderer.h +++ b/src/driver/fontrenderer.h @@ -54,6 +54,7 @@ class Font // these are HACKED values, because the font metrics were unusable. int height,DigitHeight,DigitOffset,ascender,descender,upper,lower; int fontwidth; + int fontwidth_widest; int maxdigitwidth; uint8_t fg_red, fg_green, fg_blue; fb_pixel_t colors[256]; @@ -86,6 +87,7 @@ class Font int getMaxDigitWidth(void); int getDigitOffset(void); int getWidth(void); + int getWidestWidth(void); int getSize(){return font.width;} int setSize(int isize); diff --git a/src/driver/neutrinofonts.cpp b/src/driver/neutrinofonts.cpp index 2e582cc78..ecfe67e09 100644 --- a/src/driver/neutrinofonts.cpp +++ b/src/driver/neutrinofonts.cpp @@ -63,6 +63,7 @@ font_sizes_struct fixed_font[SNeutrinoSettings::FONT_TYPE_FIXED_COUNT] = const font_sizes_struct signal_font = {NONEXISTANT_LOCALE, 14, CNeutrinoFonts::FONT_STYLE_REGULAR, 1}; const font_sizes_struct shell_font = {NONEXISTANT_LOCALE, 18, CNeutrinoFonts::FONT_STYLE_REGULAR, 1}; +const font_sizes_struct icon_font = {NONEXISTANT_LOCALE, 14, CNeutrinoFonts::FONT_STYLE_REGULAR, 1}; CNeutrinoFonts::CNeutrinoFonts() { @@ -82,6 +83,7 @@ CNeutrinoFonts::CNeutrinoFonts() g_SignalFont = NULL; g_ShellFont = NULL; + g_IconFont = NULL; InitDynFonts(); } @@ -260,6 +262,41 @@ void CNeutrinoFonts::SetupShellFont() dprintf(DEBUG_NORMAL, "[CNeutrinoFonts] [%s - %d] shell font family: %s (%s)\n", __func__, __LINE__, shell_font_name.c_str(), shell_ttf.c_str()); } +std::string CNeutrinoFonts::getIconTTF() +{ + const char *icon_ttf[2] = { FONTDIR_VAR "/fa-solid-900.ttf", FONTDIR "/fa-solid-900.ttf" }; + for (unsigned int i = 0; i < 2; i++) + { + if (access(icon_ttf[i], F_OK) == 0) + return (std::string)icon_ttf[i]; + } + return ""; +} + +void CNeutrinoFonts::SetupIconFont() +{ + if (g_IconFont) + { + delete g_IconFont; + g_IconFont = NULL; + } + + std::string icon_ttf = getIconTTF(); + if (access(icon_ttf.c_str(), F_OK) != 0) + return; + + if (g_iconFontRenderer != NULL) + delete g_iconFontRenderer; + g_iconFontRenderer = new FBFontRenderClass(); + g_iconFontRenderer->AddFont(icon_ttf.c_str()); + + std::string icon_font_name = g_iconFontRenderer->getFamily(icon_ttf.c_str()); + int icon_font_size = CFrameBuffer::getInstance()->scale2Res(icon_font.defaultsize)/* + icon_font.size_offset * fontDescr.size_offset*/; + g_IconFont = g_iconFontRenderer->getFont(icon_font_name.c_str(), fontStyle[icon_font.style].c_str(), icon_font_size); + if (g_IconFont) + dprintf(DEBUG_NORMAL, "[CNeutrinoFonts] [%s - %d] icon font family: %s (%s)\n", __func__, __LINE__, icon_font_name.c_str(), icon_ttf.c_str()); +} + void CNeutrinoFonts::refreshDynFonts() { if (!v_share_fonts.empty()) { diff --git a/src/driver/neutrinofonts.h b/src/driver/neutrinofonts.h index e3e9525d1..acc0e5646 100644 --- a/src/driver/neutrinofonts.h +++ b/src/driver/neutrinofonts.h @@ -132,6 +132,9 @@ class CNeutrinoFonts void SetupDynamicFonts(bool initRenderClass = true); void SetupShellFont(); std::string getShellTTF(); + void SetupIconFont(); + std::string getIconTTF(); + 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 62ca2b16c..51bc7b665 100644 --- a/src/global.h +++ b/src/global.h @@ -61,12 +61,14 @@ NEUTRINO_CPP FBFontRenderClass *g_fontRenderer; NEUTRINO_CPP FBFontRenderClass *g_fixedFontRenderer; NEUTRINO_CPP FBFontRenderClass *g_dynFontRenderer; NEUTRINO_CPP FBFontRenderClass *g_shellFontRenderer; +NEUTRINO_CPP FBFontRenderClass *g_iconFontRenderer; class Font; NEUTRINO_CPP Font *g_Font[SNeutrinoSettings::FONT_TYPE_COUNT]; NEUTRINO_CPP Font *g_FixedFont[SNeutrinoSettings::FONT_TYPE_FIXED_COUNT]; NEUTRINO_CPP Font *g_SignalFont; NEUTRINO_CPP Font *g_ShellFont; +NEUTRINO_CPP Font *g_IconFont; #ifdef HAVE_CONTROLD class CControldClient; diff --git a/src/gui/widget/iconfont.h b/src/gui/widget/iconfont.h new file mode 100644 index 000000000..69dd06ef4 --- /dev/null +++ b/src/gui/widget/iconfont.h @@ -0,0 +1,32 @@ +/* + Iconfont defines + Copyright (C) 2021, Sven Hoefer 'vanhofen' + + License: GPL + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __gui_widget_iconfont_h__ +#define __gui_widget_iconfont_h__ + +#define ICONFONT_FILE "\uf15b" +#define ICONFONT_FILM "\uf008" +#define ICONFONT_FOLDER "\uf07b" +#define ICONFONT_FOLDER_OPEN "\uf07c" +#define ICONFONT_IMAGE "\uf03e" +#define ICONFONT_LIST "\uf03a" +#define ICONFONT_MUSIC "\uf001" + +#endif /* __gui_widget_iconfont_h__ */ diff --git a/src/neutrino.cpp b/src/neutrino.cpp index 5927d89bf..1a5ca9f6a 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -2748,6 +2748,8 @@ void CNeutrinoApp::SetupFonts(int fmode) neutrinoFonts->refreshDynFonts(); } + neutrinoFonts->SetupIconFont(); + /* recalculate infobar position */ if (g_InfoViewer) g_InfoViewer->start(); @@ -5503,6 +5505,7 @@ int CNeutrinoApp::exec(CMenuTarget* parent, const std::string & actionKey) delete g_fixedFontRenderer; delete g_dynFontRenderer; delete g_shellFontRenderer; + delete g_iconFontRenderer; delete hint; @@ -6112,6 +6115,9 @@ void CNeutrinoApp::Cleanup() printf("cleanup g_shellFontRenderer\n"); fflush(stdout); delete g_shellFontRenderer; g_shellFontRenderer = NULL; + printf("cleanup g_iconFontRenderer\n"); fflush(stdout); + delete g_iconFontRenderer; g_iconFontRenderer = NULL; + printf("cleanup g_PicViewer\n"); fflush(stdout); delete g_PicViewer; g_PicViewer = NULL; @@ -6198,6 +6204,9 @@ void CNeutrinoApp::Cleanup() printf("cleanup g_ShellFont\n"); fflush(stdout); delete g_ShellFont; g_ShellFont = NULL; + printf("cleanup g_IconFont\n"); fflush(stdout); + delete g_IconFont; g_IconFont = NULL; + printf("cleanup g_settings.usermenu[]\n"); fflush(stdout); for (unsigned int i = 0; i < g_settings.usermenu.size(); ++i) {