introduce Font Awesome iconfont

Origin commit data
------------------
Branch: ni/coolstream
Commit: 7406f94ae8
Author: vanhofen <vanhofen@gmx.de>
Date: 2021-10-31 (Sun, 31 Oct 2021)

Origin message was:
------------------
- introduce Font Awesome iconfont

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2021-10-31 00:03:07 +02:00
parent 6004493a21
commit cb0b33a205
10 changed files with 141 additions and 0 deletions

View File

@@ -18,6 +18,12 @@ install_DATA += \
ubuntumono-b-webfont.ttf \
ubuntumono-r-webfont.ttf
if ! BOXMODEL_CST_HD1
# icon font
install_DATA += \
fa-solid-900.ttf
endif
install-data-hook:
cd $(DESTDIR)$(FONTDIR); \
mv $(neutrino_ttf) neutrino.ttf; \

View File

@@ -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.**

BIN
data/fonts/fa-solid-900.ttf Normal file

Binary file not shown.

View File

@@ -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;

View File

@@ -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);

View File

@@ -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()) {

View File

@@ -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;}

View File

@@ -57,12 +57,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;

32
src/gui/widget/iconfont.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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__ */

View File

@@ -2795,6 +2795,8 @@ void CNeutrinoApp::SetupFonts(int fmode)
neutrinoFonts->refreshDynFonts();
}
neutrinoFonts->SetupIconFont();
/* recalculate infobar position */
if (g_InfoViewer)
g_InfoViewer->start();
@@ -5620,6 +5622,7 @@ int CNeutrinoApp::exec(CMenuTarget* parent, const std::string & actionKey)
delete g_fixedFontRenderer;
delete g_dynFontRenderer;
delete g_shellFontRenderer;
delete g_iconFontRenderer;
delete hint;
@@ -6226,6 +6229,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;
@@ -6312,6 +6318,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)
{