From 41d45011c24740abfcaae9ecf0ea3f1906c6f29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 13 Jul 2009 01:12:24 +0300 Subject: Replace internal freetype font handling with VDR's font facilities. Skins that use fonts other than VDR's standard "Osd", "Fix", and "Sml" need to be adapted to use font names as understood by VDR's CreateFont() (Family:Style as of writing this) instead of filenames in their font attributes' names, to use '@' instead of ':' as the separator before sizes, and have fonts shipped with the skin installed and configured in fontconfig. Typically, install font files (if necessary) to a dir somewhere, run fc-cache(1) on the dir, replace for example font="SomeFont.ttf:22,85" with font="Some Font@22,85" or font="SomeFontBold.ttf:22,85" with font="Some Font:Bold@22,85" in the *.skin file. Also, in case the shipped fonts are derivatives of some existing ones, they may need to be properly renamed to something so they will be used instead of the original if it happens to be installed. (closes #36) --- font.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'font.c') diff --git a/font.c b/font.c index 78c5cc7..0792b2e 100644 --- a/font.c +++ b/font.c @@ -6,9 +6,48 @@ #include "render.h" #include -#ifdef HAVE_FREETYPE -cGraphtftFont cText2SkinFont::mFontCache; -#endif + +cText2SkinFontCache::cText2SkinFontCache(void) +{ +} + +cText2SkinFontCache::~cText2SkinFontCache() +{ + Clear(); +} + +bool cText2SkinFontCache::Load(string Name, string CacheName, int Size) +{ + if ( _cache.find(CacheName) != _cache.end() ) + return true; + cFont* newFont = cFont::CreateFont(Name.c_str(), Size); + if ( newFont == NULL ) + return false; + _cache[CacheName] = newFont; + return true; +} + +const cFont* cText2SkinFontCache::GetFont(string CacheName) +{ + if (CacheName == "Sml") return cFont::GetFont(fontSml); + else if (CacheName == "Fix") return cFont::GetFont(fontFix); + else if ( _cache.find(CacheName) != _cache.end() ) + { + return _cache[CacheName]; + } + return cFont::GetFont(fontOsd); +} + +void cText2SkinFontCache::Clear() +{ + cache_map::iterator it = _cache.begin(); + for (; it != _cache.end(); ++it) + delete((*it).second); + _cache.clear(); +} + + +cText2SkinFontCache cText2SkinFont::mFontCache; cText2SkinFont::cText2SkinFont(void) { @@ -18,27 +57,22 @@ cText2SkinFont::~cText2SkinFont() { } -const cFont *cText2SkinFont::Load(const std::string &Path, const std::string &Filename, int Size, - int Width) +const cFont *cText2SkinFont::Load(const string &Name, int Size) { - if (Filename == "Osd") + if (Name == "Osd") return cFont::GetFont(fontOsd); - else if (Filename == "Fix") + else if (Name == "Fix") return cFont::GetFont(fontFix); - else if (Filename == "Sml") + else if (Name == "Sml") return cFont::GetFont(fontSml); const cFont *res = NULL; -#ifdef HAVE_FREETYPE char *cachename; - asprintf(&cachename, "%s_%d_%d_%d", Filename.c_str(), Size, Width, I18nCurrentLanguage()); - if (mFontCache.Load(Path + "/" + Filename, cachename, Size, I18nCurrentLanguage(), Width)) + asprintf(&cachename, "%s_%d", Name.c_str(), Size); + if (mFontCache.Load(Name, cachename, Size)) res = mFontCache.GetFont(cachename); else - esyslog("ERROR: Text2Skin: Couldn't load font %s:%d", Filename.c_str(), Size); + esyslog("ERROR: Text2Skin: Couldn't load font %s:%d", Name.c_str(), Size); free(cachename); -#else - esyslog("ERROR: Text2Skin: Font engine not enabled at compile time!"); -#endif return res; } -- cgit v1.2.3