diff options
-rw-r--r-- | glcdskin/font.c | 44 | ||||
-rw-r--r-- | glcdskin/font.h | 2 |
2 files changed, 36 insertions, 10 deletions
diff --git a/glcdskin/font.c b/glcdskin/font.c index a8c22c8..bffdfe6 100644 --- a/glcdskin/font.c +++ b/glcdskin/font.c @@ -33,6 +33,12 @@ cSkinFont::~cSkinFont(void) { #endif } +bool cSkinFont::FileExists(const std::string& path) +{ + std::ifstream f(path.c_str()); + return (f.is_open()); +} + bool cSkinFont::ParseUrl(const std::string & url) { bool isFontconfig = false; @@ -143,16 +149,7 @@ bool cSkinFont::ParseUrl(const std::string & url) } mFile += "fonts/"; mFile += rawfont; -#if (__GNUC__ < 3) - std::ifstream f(mFile.c_str(), std::ios::in | std::ios::binary); -#else - std::ifstream f(mFile.c_str(), std::ios_base::in | std::ios_base::binary); -#endif - if (f.is_open()) - { - f.close(); - } - else + if (!FileExists(mFile)) { // then try generic font dir mFile = mSkin->Config().FontPath(); @@ -162,6 +159,33 @@ bool cSkinFont::ParseUrl(const std::string & url) mFile += '/'; } mFile += rawfont; + +#ifdef HAVE_FONTCONFIG + // If we have fontconfig, then at last search for the font file in + // all system default font directories + if (!FileExists(mFile)) + { + if (cSkinFont::FcInitCount <= 0) + { + FcInit(); + } + cSkinFont::FcInitCount++; + + FcStrList* dirlist = FcConfigGetFontDirs(NULL); + FcChar8* dir; + while ((dir = FcStrListNext(dirlist))) + { + mFile.assign((const char*)dir); + mFile += '/'; + mFile += rawfont; + if (FileExists(mFile)) + { + break; + } + } + FcStrListDone(dirlist); + } +#endif } } diff --git a/glcdskin/font.h b/glcdskin/font.h index 80e5556..3813e6e 100644 --- a/glcdskin/font.h +++ b/glcdskin/font.h @@ -51,6 +51,8 @@ private: static int FcInitCount; + bool FileExists(const std::string& path); + public: cSkinFont(cSkin * Parent); ~cSkinFont(void); |