1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* GraphLCD plugin for Video Disc Recorder
*
* layout.c - layout classes
*
* This file is released under the GNU General Public License. Refer
* to the COPYING file distributed with this package.
*
* (c) 2005 Andreas Regel <andreas.regel AT powarman.de>
*/
#include <syslog.h>
#include <fstream>
#include "global.h"
#include "layout.h"
#include "strfct.h"
#include <vdr/config.h>
#include <vdr/i18n.h>
#include <vdr/plugin.h>
cFontElement::cFontElement(const std::string & fontName)
: name(fontName),
type(0),
file(""),
size(0)
{
}
bool cFontElement::Load(const std::string & url)
{
if (url.find("fnt:") == 0)
{
type = ftFNT;
if (url[4] == '/')
file = url.substr(4);
else
{
file = cPlugin::ConfigDirectory(PLUGIN_NAME);
file += "/fonts/";
file += url.substr(4);
}
size = 0;
return font.LoadFNT(file);
}
else if (url.find("ft2:") == 0)
{
type = 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);
size = atoi(tmp.c_str());
if (url[4] == '/')
file = url.substr(4, pos - 4);
else
{
file = cPlugin::ConfigDirectory(PLUGIN_NAME);
file += "/fonts/";
file += url.substr(4, pos - 4);
}
#if APIVERSNUM >= 10503
return font.LoadFT2(file, cCharSetConv::SystemCharacterTable(), size);
#else
return font.LoadFT2(file, I18nCharSets()[Setup.OSDLanguage], size);
#endif
}
else
{
syslog(LOG_ERR, "cFontElement::Load(): Unknown font type in %s\n", url.c_str());
return false;
}
}
cFontList::cFontList()
{
}
cFontList::~cFontList()
{
std::list <cFontElement *>::iterator it;
cFontElement * elem;
for (it = fonts.begin(); it != fonts.end(); it++)
{
elem = *it;
delete elem;
}
fonts.clear();
}
bool cFontList::Load(const std::string & fileName)
{
std::fstream file;
char readLine[1000];
std::string line;
#if (__GNUC__ < 3)
file.open(fileName.c_str(), std::ios::in);
#else
file.open(fileName.c_str(), std::ios_base::in);
#endif
if (!file.is_open())
return false;
while (!file.eof())
{
file.getline(readLine, 1000);
line = trim(readLine);
if (line.length() == 0)
continue;
if (line[0] == '#')
continue;
Parse(line);
}
file.close();
return true;
}
bool cFontList::Parse(const std::string & line)
{
std::string::size_type pos;
std::string fontName;
std::string fontUrl;
cFontElement * elem;
pos = line.find("=");
if (pos == std::string::npos)
return false;
fontName = trim(line.substr(0, pos));
fontUrl = trim(line.substr(pos + 1));
//printf("%s = %s\n", fontName.c_str(), fontUrl.c_str());
elem = new cFontElement(fontName);
if (elem->Load(fontUrl))
{
fonts.push_back(elem);
return true;
}
else
{
delete elem;
return false;
}
}
const GLCD::cFont * cFontList::GetFont(const std::string & name) const
{
std::list <cFontElement *>::const_iterator it;
cFontElement * elem;
for (it = fonts.begin(); it != fonts.end(); it++)
{
elem = *it;
if (elem->Name() == name)
{
return elem->Font();
}
}
return NULL;
}
|