From afd72642e9d4d250f56cef081b031a140226a10a Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Thu, 18 Jun 2009 12:16:11 +0300 Subject: [PATCH] Fixed font handling to be thread-safe. --- HISTORY | 7 ++++++- femonosd.c | 21 ++++++++++++++------- femonosd.h | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/HISTORY b/HISTORY index 1a496ec..4571eff 100644 --- a/HISTORY +++ b/HISTORY @@ -339,6 +339,10 @@ VDR Plugin 'femon' Revision History - Backported from 1.7.1. +2009-06-18: Version 1.6.7 + +- Backported from 1.7.2. + =================================== VDR Plugin 'femon' Revision History =================================== @@ -356,6 +360,7 @@ VDR Plugin 'femon' Revision History - Fixed closing of frontend file handles (Thanks to Brendon Higgins for reporting this one). -2009-xx-xx: Version 1.7.2 +2009-06-18: Version 1.7.2 - Cleaned up compilation warnings. +- Fixed font handling to be thread-safe. diff --git a/femonosd.c b/femonosd.c index 4e0dcf4..9cc1306 100644 --- a/femonosd.c +++ b/femonosd.c @@ -116,6 +116,14 @@ #define OSDCLEARINFO() \ m_Osd->DrawRectangle(0, OSDINFOWIN_Y(0), OSDWIDTH, OSDINFOWIN_Y(OSDINFOHEIGHT) - 1, clrTransparent) +class cFemonDummyFont : public cFont { +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; } + virtual void DrawText(cBitmap *Bitmap, int x, int y, const char *s, tColor ColorFg, tColor ColorBg, int Width) const {} +}; + cFemonOsd *cFemonOsd::pInstance = NULL; cFemonOsd *cFemonOsd::Instance(bool create) @@ -150,14 +158,11 @@ cFemonOsd::cFemonOsd() { Dprintf("%s()\n", __PRETTY_FUNCTION__); m_SvdrpConnection.handle = -1; - if (Setup.UseSmallFont == 0) { - // Dirty hack to force the small fonts... - Setup.UseSmallFont = 1; - m_Font = cFont::GetFont(fontSml); - Setup.UseSmallFont = 0; + m_Font = cFont::CreateFont(Setup.FontSml, min(max(Setup.FontSmlSize, MINFONTSIZE), MAXFONTSIZE)); + if (!m_Font || !m_Font->Height()) { + m_Font = new cFemonDummyFont; + esyslog("ERROR: cFemonOsd::cFemonOsd() cannot create required font."); } - else - m_Font = cFont::GetFont(fontSml); if (OSDHEIGHT < (OSDINFOHEIGHT + OSDROWHEIGHT + OSDSTATUSHEIGHT)) OSDHEIGHT = (OSDINFOHEIGHT + OSDROWHEIGHT + OSDSTATUSHEIGHT); } @@ -179,6 +184,8 @@ cFemonOsd::~cFemonOsd(void) } if (m_Osd) DELETENULL(m_Osd); + if (m_Font) + DELETENULL(m_Font); if (m_Frontend >= 0) { close(m_Frontend); m_Frontend = -1; diff --git a/femonosd.h b/femonosd.h index 3c088df..4d0d1fa 100644 --- a/femonosd.h +++ b/femonosd.h @@ -43,7 +43,7 @@ private: uint32_t m_UNC; fe_status_t m_FrontendStatus; int m_DisplayMode; - const cFont *m_Font; + cFont *m_Font; cTimeMs m_InputTime; cCondWait m_Sleep; cMutex m_Mutex;