diff options
author | Ville Skyttä <ville.skytta@iki.fi> | 2009-07-13 01:12:24 +0300 |
---|---|---|
committer | Ville Skyttä <ville.skytta@iki.fi> | 2009-07-13 01:12:24 +0300 |
commit | 41d45011c24740abfcaae9ecf0ea3f1906c6f29e (patch) | |
tree | 40c29c378b9f96b2c166246f63660c9b4e6cf08a /font.c | |
parent | 457026f870e5d2916347212ead617ff15b1e9bf1 (diff) | |
download | vdr-plugin-text2skin-41d45011c24740abfcaae9ecf0ea3f1906c6f29e.tar.gz vdr-plugin-text2skin-41d45011c24740abfcaae9ecf0ea3f1906c6f29e.tar.bz2 |
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)
Diffstat (limited to 'font.c')
-rw-r--r-- | font.c | 64 |
1 files changed, 49 insertions, 15 deletions
@@ -6,9 +6,48 @@ #include "render.h" #include <vdr/tools.h> -#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; } |