1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

cFont::CreateFont() now returns a dummy font in case there are no fonts installed

This commit is contained in:
Klaus Schmidinger 2014-01-25 14:26:26 +01:00
parent c7316989f5
commit 6bd94489de
3 changed files with 17 additions and 14 deletions

View File

@ -7870,9 +7870,11 @@ Video Disk Recorder Revision History
and also to use the correct directory with --edit (the latter reported by Marko and also to use the correct directory with --edit (the latter reported by Marko
Mäkelä). Mäkelä).
2014-01-16: Version 2.0.6 2014-01-25: Version 2.0.6
- Updated 'sources.conf' (thanks to Antti Hartikainen). - Updated 'sources.conf' (thanks to Antti Hartikainen).
- cFont::CreateFont() now returns a dummy font in case there are no fonts installed.
This prevents a crash with the LCARS skin on a system that has no fonts.
- Increased MIN_TS_PACKETS_FOR_FRAME_DETECTOR to 10 in order to be able to record - Increased MIN_TS_PACKETS_FOR_FRAME_DETECTOR to 10 in order to be able to record
channels that need more than 5 TS packets for detecting frame borders (reported by channels that need more than 5 TS packets for detecting frame borders (reported by
Eike Sauer). Eike Sauer).

23
font.c
View File

@ -6,7 +6,7 @@
* *
* BiDi support by Osama Alrawab <alrawab@hotmail.com> @2008 Tripoli-Libya. * BiDi support by Osama Alrawab <alrawab@hotmail.com> @2008 Tripoli-Libya.
* *
* $Id: font.c 2.13.1.1 2013/04/07 14:54:15 kls Exp $ * $Id: font.c 2.13.1.2 2014/01/25 14:25:29 kls Exp $
*/ */
#include "font.h" #include "font.h"
@ -382,10 +382,13 @@ void cFreetypeFont::DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColo
// A dummy font, in case there are no fonts installed: // A dummy font, in case there are no fonts installed:
class cDummyFont : public cFont { class cDummyFont : public cFont {
private:
int height;
public: public:
virtual int Width(uint c) const { return 10; } cDummyFont(int CharHeight) { height = CharHeight; }
virtual int Width(const char *s) const { return 50; } virtual int Width(uint c) const { return height; }
virtual int Height(void) const { return 20; } virtual int Width(const char *s) const { return height; }
virtual int Height(void) const { return height; }
virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {} virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {}
virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {}; virtual void DrawText(cPixmap *Pixmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {};
}; };
@ -396,11 +399,8 @@ cFont *cFont::fonts[eDvbFontSize] = { NULL };
void cFont::SetFont(eDvbFont Font, const char *Name, int CharHeight) void cFont::SetFont(eDvbFont Font, const char *Name, int CharHeight)
{ {
cFont *f = CreateFont(Name, constrain(CharHeight, MINFONTSIZE, MAXFONTSIZE));
if (!f || !f->Height())
f = new cDummyFont;
delete fonts[Font]; delete fonts[Font];
fonts[Font] = f; fonts[Font] = CreateFont(Name, constrain(CharHeight, MINFONTSIZE, MAXFONTSIZE));
} }
const cFont *cFont::GetFont(eDvbFont Font) const cFont *cFont::GetFont(eDvbFont Font)
@ -423,9 +423,10 @@ const cFont *cFont::GetFont(eDvbFont Font)
cFont *cFont::CreateFont(const char *Name, int CharHeight, int CharWidth) cFont *cFont::CreateFont(const char *Name, int CharHeight, int CharWidth)
{ {
cString fn = GetFontFileName(Name); cString fn = GetFontFileName(Name);
if (*fn) cFont *f = *fn ? new cFreetypeFont(fn, CharHeight, CharWidth) : NULL;
return new cFreetypeFont(fn, CharHeight, CharWidth); if (!f || !f->Height())
return NULL; f = new cDummyFont(CharHeight);
return f;
} }
bool cFont::GetAvailableFontNames(cStringList *FontNames, bool Monospaced) bool cFont::GetAvailableFontNames(cStringList *FontNames, bool Monospaced)

4
font.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: font.h 2.7 2013/02/17 13:17:42 kls Exp $ * $Id: font.h 2.7.1.1 2014/01/25 14:24:51 kls Exp $
*/ */
#ifndef __FONT_H #ifndef __FONT_H
@ -75,7 +75,7 @@ public:
///< default width. Name is of the form "Family:Style", for instance ///< default width. Name is of the form "Family:Style", for instance
///< "Verdana:Bold Italic" or "Times New Roman". See GetAvailableFontNames() ///< "Verdana:Bold Italic" or "Times New Roman". See GetAvailableFontNames()
///< for how to get a list of all available font names. ///< for how to get a list of all available font names.
///< If the requested font can't be created, NULL is returned. ///< If the requested font can't be created, a dummy font is returned.
///< The caller must delete the font when it is no longer needed. ///< The caller must delete the font when it is no longer needed.
static bool GetAvailableFontNames(cStringList *FontNames, bool Monospaced = false); static bool GetAvailableFontNames(cStringList *FontNames, bool Monospaced = false);
///< Queries the font configuration for a list of available font names, ///< Queries the font configuration for a list of available font names,