From dbf342df3c401cfc4cd4d5df28c98c175ba252bc Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Tue, 7 Jan 2014 12:42:37 +0100 Subject: [PATCH] cFont::CreateFont() now returns a dummy font in case there are no fonts installed --- HISTORY | 2 ++ font.c | 23 ++++++++++++----------- font.h | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/HISTORY b/HISTORY index 4fb96307..45ba1c47 100644 --- a/HISTORY +++ b/HISTORY @@ -8135,3 +8135,5 @@ Video Disk Recorder Revision History 2014-01-07: Version 2.1.4 - 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. diff --git a/font.c b/font.c index dee26c21..cd2c494b 100644 --- a/font.c +++ b/font.c @@ -6,7 +6,7 @@ * * BiDi support by Osama Alrawab @2008 Tripoli-Libya. * - * $Id: font.c 3.1 2013/04/07 14:42:13 kls Exp $ + * $Id: font.c 3.2 2014/01/07 12:19:45 kls Exp $ */ #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: class cDummyFont : public cFont { +private: + int height; public: - virtual int Width(uint c) const { return 10; } - virtual int Width(const char *s) const { return 50; } - virtual int Height(void) const { return 20; } + cDummyFont(int CharHeight) { height = CharHeight; } + virtual int Width(uint c) const { return height; } + 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(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) { - cFont *f = CreateFont(Name, constrain(CharHeight, MINFONTSIZE, MAXFONTSIZE)); - if (!f || !f->Height()) - f = new cDummyFont; delete fonts[Font]; - fonts[Font] = f; + fonts[Font] = CreateFont(Name, constrain(CharHeight, MINFONTSIZE, MAXFONTSIZE)); } 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) { cString fn = GetFontFileName(Name); - if (*fn) - return new cFreetypeFont(fn, CharHeight, CharWidth); - return NULL; + cFont *f = *fn ? new cFreetypeFont(fn, CharHeight, CharWidth) : NULL; + if (!f || !f->Height()) + f = new cDummyFont(CharHeight); + return f; } bool cFont::GetAvailableFontNames(cStringList *FontNames, bool Monospaced) diff --git a/font.h b/font.h index 86bd8b33..cd62b4a9 100644 --- a/font.h +++ b/font.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: font.h 2.7 2013/02/17 13:17:42 kls Exp $ + * $Id: font.h 3.1 2014/01/07 12:11:55 kls Exp $ */ #ifndef __FONT_H @@ -75,7 +75,7 @@ public: ///< default width. Name is of the form "Family:Style", for instance ///< "Verdana:Bold Italic" or "Times New Roman". See GetAvailableFontNames() ///< 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. static bool GetAvailableFontNames(cStringList *FontNames, bool Monospaced = false); ///< Queries the font configuration for a list of available font names,