summaryrefslogtreecommitdiff
path: root/glcdskin/font.c
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2010-04-17 19:16:26 +0200
committermrwastl <mrwastl@users.sourceforge.net>2010-04-17 19:16:26 +0200
commit68ac6628a31cb1472275b5282c5cf9a971d9bddd (patch)
tree0ef788b563efab6688b0381cedd43baaefbc66cc /glcdskin/font.c
parent1011961a8af0615ee25b79d2bbd7e6820b851556 (diff)
downloadgraphlcd-base-68ac6628a31cb1472275b5282c5cf9a971d9bddd.tar.gz
graphlcd-base-68ac6628a31cb1472275b5282c5cf9a971d9bddd.tar.bz2
backport of skin-support from 0.2.x to 0.1.x, changes for gcc 4.3 conformity
Diffstat (limited to 'glcdskin/font.c')
-rw-r--r--glcdskin/font.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/glcdskin/font.c b/glcdskin/font.c
new file mode 100644
index 0000000..731b1fa
--- /dev/null
+++ b/glcdskin/font.c
@@ -0,0 +1,119 @@
+#include <syslog.h>
+
+#include <fstream>
+
+#include "font.h"
+#include "skin.h"
+#include "function.h"
+
+namespace GLCD
+{
+
+cSkinFont::cSkinFont(cSkin * Parent)
+: mSkin(Parent),
+ mCondition(NULL),
+ mDummyDisplay(mSkin),
+ mDummyObject(&mDummyDisplay)
+{
+}
+
+bool cSkinFont::ParseUrl(const std::string & url)
+{
+ std::string::size_type count = std::string::npos;
+
+ if (url.find("fnt:") == 0)
+ {
+ mType = ftFNT;
+ mSize = 0;
+ }
+ else if (url.find("ft2:") == 0)
+ {
+ mType = ftFT2;
+ std::string::size_type pos = url.find(":", 4);
+ if (pos == std::string::npos)
+ {
+ syslog(LOG_ERR, "cFontElement::Load(): No font size specified in %s\n", url.c_str());
+ return false;
+ }
+ std::string tmp = url.substr(pos + 1);
+ mSize = atoi(tmp.c_str());
+ count = pos - 4;
+ }
+ else
+ {
+ syslog(LOG_ERR, "cSkinFont::ParseUrl(): Unknown font type in %s\n", url.c_str());
+ return false;
+ }
+
+ if (url[4] == '/' || url.find("./") == 4 || url.find("../") == 4)
+ mFile = url.substr(4, count);
+ else
+ {
+ // first try skin's font dir
+ mFile = mSkin->Config().SkinPath();
+ if (mFile.length() > 0)
+ {
+ if (mFile[mFile.length() - 1] != '/')
+ mFile += '/';
+ }
+ mFile += "fonts/";
+ mFile += url.substr(4, count);
+#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
+ {
+ // then try generic font dir
+ mFile = mSkin->Config().FontPath();
+ if (mFile.length() > 0)
+ {
+ if (mFile[mFile.length() - 1] != '/')
+ mFile += '/';
+ }
+ mFile += url.substr(4, count);
+ }
+ }
+
+ if (mType == ftFNT)
+ {
+ return mFont.LoadFNT(mFile);
+ }
+ else
+ {
+ return mFont.LoadFT2(mFile, mSkin->Config().CharSet(), mSize);
+ }
+}
+
+bool cSkinFont::ParseCondition(const std::string & Text)
+{
+ cSkinFunction *result = new cSkinFunction(&mDummyObject);
+ if (result->Parse(Text))
+ {
+ delete mCondition;
+ mCondition = result;
+ return true;
+ }
+ return false;
+}
+
+cSkinFonts::cSkinFonts(void)
+{
+}
+
+cSkinFonts::~cSkinFonts()
+{
+ iterator it = begin();
+ while (it != end())
+ {
+ delete (*it);
+ it++;
+ }
+}
+
+} // end of namespace