mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
CNeutrinoFonts: Fix segfault, when fontfile changed
- use std::string for font and style names
This commit is contained in:
@@ -52,7 +52,14 @@ const font_sizes_struct signal_font = {LOCALE_FONTSIZE_INFOBAR_SMALL, 14, CNeutr
|
|||||||
CNeutrinoFonts::CNeutrinoFonts()
|
CNeutrinoFonts::CNeutrinoFonts()
|
||||||
{
|
{
|
||||||
useDigitOffset = false;
|
useDigitOffset = false;
|
||||||
memset(&fontDescr, 0, sizeof(neutrino_font_descr_struct));
|
|
||||||
|
fontDescr.name = "";
|
||||||
|
fontDescr.filename = "";
|
||||||
|
fontDescr.size_offset = 0;
|
||||||
|
old_fontDescr.name = "";
|
||||||
|
old_fontDescr.filename = "";
|
||||||
|
old_fontDescr.size_offset = 0;
|
||||||
|
|
||||||
InitDynFonts();
|
InitDynFonts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,36 +107,37 @@ void CNeutrinoFonts::SetupNeutrinoFonts()
|
|||||||
delete g_fontRenderer;
|
delete g_fontRenderer;
|
||||||
g_fontRenderer = new FBFontRenderClass(72 * g_settings.screen_xres / 100, 72 * g_settings.screen_yres / 100);
|
g_fontRenderer = new FBFontRenderClass(72 * g_settings.screen_xres / 100, 72 * g_settings.screen_yres / 100);
|
||||||
|
|
||||||
if (fontDescr.filename != NULL)
|
old_fontDescr.size_offset = fontDescr.size_offset;
|
||||||
free((void *)fontDescr.filename);
|
old_fontDescr.filename = fontDescr.filename;
|
||||||
|
fontDescr.filename = "";
|
||||||
printf("[neutrino] settings font file %s\n", g_settings.font_file);
|
printf("[neutrino] settings font file %s\n", g_settings.font_file);
|
||||||
if (access(g_settings.font_file, F_OK)) {
|
if (access(g_settings.font_file, F_OK)) {
|
||||||
if (!access(FONTDIR"/neutrino.ttf", F_OK)) {
|
if (!access(FONTDIR"/neutrino.ttf", F_OK)) {
|
||||||
fontDescr.filename = strdup(FONTDIR"/neutrino.ttf");
|
fontDescr.filename = FONTDIR"/neutrino.ttf";
|
||||||
strcpy(g_settings.font_file, fontDescr.filename);
|
strcpy(g_settings.font_file, fontDescr.filename.c_str());
|
||||||
} else {
|
} else {
|
||||||
fprintf( stderr,"[neutrino] font file [%s] not found\n neutrino exit\n",FONTDIR"/neutrino.ttf");
|
fprintf( stderr,"[neutrino] font file [%s] not found\n neutrino exit\n",FONTDIR"/neutrino.ttf");
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
fontDescr.filename = strdup(g_settings.font_file);
|
fontDescr.filename = g_settings.font_file;
|
||||||
fontStyle[0] = g_fontRenderer->AddFont(fontDescr.filename);
|
fontStyle[0] = g_fontRenderer->AddFont(fontDescr.filename.c_str());
|
||||||
|
|
||||||
if (fontDescr.name != NULL)
|
old_fontDescr.name = fontDescr.name;
|
||||||
free((void *)fontDescr.name);
|
fontDescr.name = "";
|
||||||
fontDescr.name = strdup(g_fontRenderer->getFamily(fontDescr.filename).c_str());
|
fontDescr.name = g_fontRenderer->getFamily(fontDescr.filename.c_str());
|
||||||
printf("[neutrino] font family %s\n", fontDescr.name);
|
printf("[neutrino] font family %s\n", fontDescr.name.c_str());
|
||||||
fontStyle[1] = "Bold Regular";
|
fontStyle[1] = "Bold Regular";
|
||||||
|
|
||||||
g_fontRenderer->AddFont(fontDescr.filename, true); // make italics
|
g_fontRenderer->AddFont(fontDescr.filename.c_str(), true); // make italics
|
||||||
fontStyle[2] = "Italic";
|
fontStyle[2] = "Italic";
|
||||||
|
|
||||||
for (int i = 0; i < SNeutrinoSettings::FONT_TYPE_COUNT; i++) {
|
for (int i = 0; i < SNeutrinoSettings::FONT_TYPE_COUNT; i++) {
|
||||||
if (g_Font[i]) delete g_Font[i];
|
if (g_Font[i]) delete g_Font[i];
|
||||||
g_Font[i] = g_fontRenderer->getFont(fontDescr.name, fontStyle[neutrino_font[i].style], CNeutrinoApp::getInstance()->getConfigFile()->getInt32(locale_real_names[neutrino_font[i].name], neutrino_font[i].defaultsize) + neutrino_font[i].size_offset * fontDescr.size_offset);
|
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);
|
||||||
}
|
}
|
||||||
g_SignalFont = g_fontRenderer->getFont(fontDescr.name, fontStyle[signal_font.style], signal_font.defaultsize + signal_font.size_offset * fontDescr.size_offset);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CNeutrinoFonts::refreshDynFonts()
|
void CNeutrinoFonts::refreshDynFonts()
|
||||||
@@ -160,12 +168,16 @@ void CNeutrinoFonts::refreshDynFont(int dx, int dy, std::string text, int style,
|
|||||||
useDigitOffset = dyn_font->useDigitOffset;
|
useDigitOffset = dyn_font->useDigitOffset;
|
||||||
int dynSize = getDynFontSize(dx, dy, text, style);
|
int dynSize = getDynFontSize(dx, dy, text, style);
|
||||||
useDigitOffset = tmp;
|
useDigitOffset = tmp;
|
||||||
if (dyn_font->size == dynSize)
|
if ((dyn_font->size == dynSize) && (old_fontDescr.name == fontDescr.name) && (old_fontDescr.filename == fontDescr.filename))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
old_fontDescr.filename = fontDescr.filename;
|
||||||
|
old_fontDescr.name = fontDescr.name;
|
||||||
|
old_fontDescr.size_offset = fontDescr.size_offset;
|
||||||
|
|
||||||
if (dyn_font->font != NULL)
|
if (dyn_font->font != NULL)
|
||||||
delete dyn_font->font;
|
delete dyn_font->font;
|
||||||
Font *dynFont = g_fontRenderer->getFont(fontDescr.name, fontStyle[style], dynSize);
|
Font *dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize);
|
||||||
dyn_font->font = dynFont;
|
dyn_font->font = dynFont;
|
||||||
dyn_font->size = dynSize;
|
dyn_font->size = dynSize;
|
||||||
printf("##### [%s] change %s_font size old %d to new %d, index: %u\n", __FUNCTION__, (isShare)?"share":"dyn", oldSize, dyn_font->size, index);
|
printf("##### [%s] change %s_font size old %d to new %d, index: %u\n", __FUNCTION__, (isShare)?"share":"dyn", oldSize, dyn_font->size, index);
|
||||||
@@ -191,7 +203,7 @@ int CNeutrinoFonts::getDynFontSize(int dx, int dy, std::string text, int style)
|
|||||||
while (1) {
|
while (1) {
|
||||||
if (dynFont != NULL)
|
if (dynFont != NULL)
|
||||||
delete dynFont;
|
delete dynFont;
|
||||||
dynFont = g_fontRenderer->getFont(fontDescr.name, fontStyle[style], dynSize);
|
dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize);
|
||||||
// calculate height & width
|
// calculate height & width
|
||||||
_height = getFontHeight(dynFont);
|
_height = getFontHeight(dynFont);
|
||||||
std::string tmpText = text;
|
std::string tmpText = text;
|
||||||
@@ -258,7 +270,7 @@ Font **CNeutrinoFonts::getDynFontWithID(int &dx, int &dy, std::string text, int
|
|||||||
{
|
{
|
||||||
if ((dx <= 0) && (dy <= 0))
|
if ((dx <= 0) && (dy <= 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((fontDescr.name == NULL) || (fontDescr.filename == NULL) || (g_fontRenderer == NULL))
|
if ((fontDescr.name == "") || (fontDescr.filename == "") || (g_fontRenderer == NULL))
|
||||||
SetupNeutrinoFonts();
|
SetupNeutrinoFonts();
|
||||||
|
|
||||||
int dynSize = getDynFontSize(dx, dy, text, style);
|
int dynSize = getDynFontSize(dx, dy, text, style);
|
||||||
@@ -273,7 +285,7 @@ Font **CNeutrinoFonts::getDynFontWithID(int &dx, int &dy, std::string text, int
|
|||||||
return &(v_dyn_fonts[f_id].font);
|
return &(v_dyn_fonts[f_id].font);
|
||||||
}
|
}
|
||||||
|
|
||||||
dynFont = g_fontRenderer->getFont(fontDescr.name, fontStyle[style], dynSize);
|
dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize);
|
||||||
if (v_dyn_fonts[f_id].font != NULL)
|
if (v_dyn_fonts[f_id].font != NULL)
|
||||||
delete v_dyn_fonts[f_id].font;
|
delete v_dyn_fonts[f_id].font;
|
||||||
v_dyn_fonts[f_id].dx = dx;
|
v_dyn_fonts[f_id].dx = dx;
|
||||||
@@ -299,7 +311,7 @@ Font **CNeutrinoFonts::getDynFontShare(int &dx, int &dy, std::string text, int s
|
|||||||
{
|
{
|
||||||
if ((dx <= 0) && (dy <= 0))
|
if ((dx <= 0) && (dy <= 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((fontDescr.name == NULL) || (fontDescr.filename == NULL) || (g_fontRenderer == NULL))
|
if ((fontDescr.name == "") || (fontDescr.filename == "") || (g_fontRenderer == NULL))
|
||||||
SetupNeutrinoFonts();
|
SetupNeutrinoFonts();
|
||||||
|
|
||||||
int dynSize = getDynFontSize(dx, dy, text, style);
|
int dynSize = getDynFontSize(dx, dy, text, style);
|
||||||
@@ -327,7 +339,7 @@ Font **CNeutrinoFonts::getDynFontShare(int &dx, int &dy, std::string text, int s
|
|||||||
ret = &(v_share_fonts[i].font);
|
ret = &(v_share_fonts[i].font);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dynFont = g_fontRenderer->getFont(fontDescr.name, fontStyle[style], dynSize);
|
dynFont = g_fontRenderer->getFont(fontDescr.name.c_str(), fontStyle[style].c_str(), dynSize);
|
||||||
dyn_font_t dyn_font;
|
dyn_font_t dyn_font;
|
||||||
dyn_font.dx = dx;
|
dyn_font.dx = dx;
|
||||||
dyn_font.dy = dy;
|
dyn_font.dy = dy;
|
||||||
|
@@ -28,8 +28,8 @@
|
|||||||
#define __neutrinofonts__
|
#define __neutrinofonts__
|
||||||
|
|
||||||
typedef struct neutrino_font_descr {
|
typedef struct neutrino_font_descr {
|
||||||
const char *name;
|
std::string name;
|
||||||
const char *filename;
|
std::string filename;
|
||||||
int size_offset;
|
int size_offset;
|
||||||
} neutrino_font_descr_struct;
|
} neutrino_font_descr_struct;
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ typedef struct font_sizes_groups {
|
|||||||
class CNeutrinoFonts
|
class CNeutrinoFonts
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const char * fontStyle[3];
|
std::string fontStyle[3];
|
||||||
|
|
||||||
typedef struct dyn_font_t
|
typedef struct dyn_font_t
|
||||||
{
|
{
|
||||||
@@ -97,6 +97,7 @@ class CNeutrinoFonts
|
|||||||
static CNeutrinoFonts* getInstance();
|
static CNeutrinoFonts* getInstance();
|
||||||
|
|
||||||
neutrino_font_descr_struct fontDescr;
|
neutrino_font_descr_struct fontDescr;
|
||||||
|
neutrino_font_descr_struct old_fontDescr;
|
||||||
|
|
||||||
void SetupNeutrinoFonts();
|
void SetupNeutrinoFonts();
|
||||||
void refreshDynFonts();
|
void refreshDynFonts();
|
||||||
|
@@ -1742,7 +1742,7 @@ TIMER_START();
|
|||||||
CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_NEUTRINO_STARTING));
|
CHintBox * hintBox = new CHintBox(LOCALE_MESSAGEBOX_INFO, g_Locale->getText(LOCALE_NEUTRINO_STARTING));
|
||||||
hintBox->paint();
|
hintBox->paint();
|
||||||
|
|
||||||
CVFD::getInstance()->init(neutrinoFonts->fontDescr.filename, neutrinoFonts->fontDescr.name);
|
CVFD::getInstance()->init(neutrinoFonts->fontDescr.filename.c_str(), neutrinoFonts->fontDescr.name.c_str());
|
||||||
CVFD::getInstance()->Clear();
|
CVFD::getInstance()->Clear();
|
||||||
CVFD::getInstance()->ShowText(g_Locale->getText(LOCALE_NEUTRINO_STARTING));
|
CVFD::getInstance()->ShowText(g_Locale->getText(LOCALE_NEUTRINO_STARTING));
|
||||||
CVFD::getInstance()->setBacklight(g_settings.backlight_tv);
|
CVFD::getInstance()->setBacklight(g_settings.backlight_tv);
|
||||||
|
Reference in New Issue
Block a user