summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Reimer <manuel.reimer@gmx.de>2020-08-14 18:41:32 +0200
committerManuel Reimer <manuel.reimer@gmx.de>2020-08-14 18:41:32 +0200
commitbe3007e0c05b9084344497d5279b611a8ee59c84 (patch)
tree240c9fadd36e134a243fdc59b743654cef28ff05
parent6015f5c14f80ca4dd54ef96a6d5825caad9550bb (diff)
downloadgraphlcd-base-be3007e0c05b9084344497d5279b611a8ee59c84.tar.gz
graphlcd-base-be3007e0c05b9084344497d5279b611a8ee59c84.tar.bz2
Fall back to system font directories if font file is missing
-rw-r--r--glcdskin/font.c44
-rw-r--r--glcdskin/font.h2
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);