Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 443 lines (383 sloc) 13.134 kB
1f825a6 @stuartm More fixes in libmythui of issues reported by the krazy2 static analy…
stuartm authored
1
2 #include "mythfontproperties.h"
3
1e89f31 No more qt3support in libmythui.
Isaac Richards authored
4 #include <QApplication>
2688e5a @daniel-kristjansson Cleanup. Remove QDomElement include where not strictly needed in a he…
daniel-kristjansson authored
5 #include <QDomDocument>
bd699a4 Try to pick better (meaning, antialiasable) fonts if the theme's sele…
Isaac Richards authored
6
7860579 Get rid of the circular dependencies between libraries.
Isaac Richards authored
7 #include "mythverbose.h"
8 #include "mythdb.h"
9
10 #include "mythuihelper.h"
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
11 #include "mythmainwindow.h"
0a77575 @stuartm Provide more information such as line number, element type and name i…
stuartm authored
12 #include "xmlparsebase.h"
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
13
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
14 MythFontProperties::MythFontProperties() :
15 m_color(QColor(Qt::white)), m_hasShadow(false), m_shadowAlpha(255),
21ad970 @stuartm Permit fonts to be inherited in the local context as well as global.
stuartm authored
16 m_hasOutline(false), m_outlineAlpha(255), m_bFreeze(false)
17 {
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
18 CalcHash();
19 }
20
21 void MythFontProperties::SetFace(const QFont &face)
22 {
23 m_face = face;
24 CalcHash();
25 }
26
27 void MythFontProperties::SetColor(const QColor &color)
28 {
29 m_color = color;
30 CalcHash();
31 }
32
21ad970 @stuartm Permit fonts to be inherited in the local context as well as global.
stuartm authored
33 void MythFontProperties::SetShadow(bool on, const QPoint &offset,
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
34 const QColor &color, int alpha)
35 {
36 m_hasShadow = on;
37 m_shadowOffset = offset;
38 m_shadowColor = color;
39 m_shadowAlpha = alpha;
40 CalcHash();
41 }
42
21ad970 @stuartm Permit fonts to be inherited in the local context as well as global.
stuartm authored
43 void MythFontProperties::SetOutline(bool on, const QColor &color,
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
44 int size, int alpha)
45 {
46 m_hasOutline = on;
47 m_outlineColor = color;
48 m_outlineSize = size;
49 m_outlineAlpha = alpha;
50 CalcHash();
51 }
52
53 void MythFontProperties::GetShadow(QPoint &offset, QColor &color, int &alpha) const
54 {
55 offset = m_shadowOffset;
56 color = m_shadowColor;
57 alpha = m_shadowAlpha;
58 }
59
60 void MythFontProperties::GetOutline(QColor &color, int &size, int &alpha) const
61 {
62 color = m_outlineColor;
63 size = m_outlineSize;
64 alpha = m_outlineAlpha;
65 }
66
b715a93 Significant speedup for the opengl painter for some videocards.
Isaac Richards authored
67 void MythFontProperties::GetOffset(QPoint &offset) const
68 {
69 offset = m_drawingOffset;
70 }
71
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
72 void MythFontProperties::CalcHash(void)
73 {
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
74 if (m_bFreeze)
75 return;
76
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
77 m_hash = QString("%1%2%3%4").arg(m_face.toString())
78 .arg(m_color.name()).arg(m_hasShadow).arg(m_hasOutline);
79
80 if (m_hasShadow)
81 m_hash += QString("%1%2%3%4").arg(m_shadowOffset.x())
82 .arg(m_shadowOffset.y()).arg(m_shadowColor.name())
83 .arg(m_shadowAlpha);
84
85 if (m_hasOutline)
86 m_hash += QString("%1%2%3").arg(m_outlineColor.name())
87 .arg(m_outlineSize).arg(m_outlineAlpha);
b715a93 Significant speedup for the opengl painter for some videocards.
Isaac Richards authored
88
89 m_drawingOffset = QPoint(0, 0);
90
91 if (m_hasOutline)
92 {
93 m_drawingOffset = QPoint(m_outlineSize, m_outlineSize);
94 }
95
96 if (m_hasShadow && !m_hasOutline)
97 {
98 if (m_shadowOffset.x() < 0)
99 m_drawingOffset.setX(-m_shadowOffset.x());
100 if (m_shadowOffset.y() < 0)
101 m_drawingOffset.setY(-m_shadowOffset.y());
102 }
103 if (m_hasShadow && !m_hasOutline)
104 {
105 if (m_shadowOffset.x() < 0 && m_shadowOffset.x() < -m_outlineSize)
106 m_drawingOffset.setX(-m_shadowOffset.x());
107 if (m_shadowOffset.y() < 0 && m_shadowOffset.y() < -m_outlineSize)
108 m_drawingOffset.setY(-m_shadowOffset.y());
109 }
b39633d The menu is now drawn by mythui. Random stuff might be broken. This…
Isaac Richards authored
110 }
111
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
112 void MythFontProperties::Freeze(void)
113 {
114 m_bFreeze = true;
115 }
116
117 void MythFontProperties::Unfreeze(void)
118 {
119 m_bFreeze = false;
120 CalcHash();
121 }
122
123 MythFontProperties *MythFontProperties::ParseFromXml(QDomElement &element,
21ad970 @stuartm Permit fonts to be inherited in the local context as well as global.
stuartm authored
124 MythUIType *parent,
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
125 bool addToGlobal)
126 {
127 // Crappy, but cached. Move to GlobalFontMap?
7860579 Get rid of the circular dependencies between libraries.
Isaac Richards authored
128 QString fontSizeType = GetMythDB()->GetSetting("ThemeFontSizeType", "default");
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
129
130 bool fromBase = false;
131 MythFontProperties *newFont = new MythFontProperties();
132 newFont->Freeze();
133
134 QString name = element.attribute("name", "");
2322d2f @stuartm Fix leak of MythFontProperties if a font definition is incomplete. Re…
stuartm authored
135 if (name.isEmpty())
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
136 {
0a77575 @stuartm Provide more information such as line number, element type and name i…
stuartm authored
137 XML_ERROR(element, "Font needs a name");
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
138 return NULL;
139 }
140
141 if (addToGlobal && GetGlobalFontMap()->Contains(name))
142 {
ffac9d9 @stuartm Replace remaining instances of base= with from= in fonts. Removes the…
stuartm authored
143 VERBOSE(VB_FILE, QString("Warning, already have a global font "
144 "called: %1").arg(name));
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
145 return NULL;
146 }
147
e6bb33c @stuartm In order to maintain consistency with the rest of mythui, change the …
stuartm authored
148 QString base = element.attribute("from", "");
149
150 if (!base.isEmpty())
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
151 {
383b781 @NigelPearson Fix segfault caused by [18109]
NigelPearson authored
152 MythFontProperties *tmp = NULL;
21ad970 @stuartm Permit fonts to be inherited in the local context as well as global.
stuartm authored
153
154 if (parent)
155 tmp = parent->GetFont(base);
156
157 if (!tmp)
158 tmp = GetGlobalFontMap()->GetFont(base);
159
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
160 if (!tmp)
161 {
0a77575 @stuartm Provide more information such as line number, element type and name i…
stuartm authored
162 XML_ERROR(element, QString("Specified base font '%1' does not "
163 "exist for font %2").arg(base).arg(name));
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
164 return NULL;
165 }
166
167 *newFont = *tmp;
168 fromBase = true;
169 }
170
095c573 @stuartm Support specifying font size in pixels (height) alongside the traditi…
stuartm authored
171 int size, pixelsize;
172 size = pixelsize = -1;
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
173
174 QString face = element.attribute("face", "");
2322d2f @stuartm Fix leak of MythFontProperties if a font definition is incomplete. Re…
stuartm authored
175 if (face.isEmpty())
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
176 {
177 if (!fromBase)
178 {
0a77575 @stuartm Provide more information such as line number, element type and name i…
stuartm authored
179 XML_ERROR(element, "Font needs a face");
2322d2f @stuartm Fix leak of MythFontProperties if a font definition is incomplete. Re…
stuartm authored
180 delete newFont;
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
181 return NULL;
182 }
183 }
184 else
bd699a4 Try to pick better (meaning, antialiasable) fonts if the theme's sele…
Isaac Richards authored
185 {
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
186 newFont->m_face.setFamily(face);
9f90f88 @stuartm Seems as though QFont::exactMatch() is broken and has been broken for…
stuartm authored
187 // NOTE: exactMatch() is broken and always returns false
188 // if (!newFont->m_face.exactMatch())
189 // {
190 // QFont tmp = QApplication::font();
191 // newFont->m_face.setFamily(tmp.family());
192 // }
bd699a4 Try to pick better (meaning, antialiasable) fonts if the theme's sele…
Isaac Richards authored
193 }
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
194
195 QString hint = element.attribute("stylehint", "");
2322d2f @stuartm Fix leak of MythFontProperties if a font definition is incomplete. Re…
stuartm authored
196 if (!hint.isEmpty())
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
197 {
198 newFont->m_face.setStyleHint((QFont::StyleHint)hint.toInt());
199 }
200
201 for (QDomNode child = element.firstChild(); !child.isNull();
202 child = child.nextSibling())
203 {
204 QDomElement info = child.toElement();
205 if (!info.isNull())
206 {
207 if (info.tagName() == "size")
208 {
209 size = getFirstText(info).toInt();
210 }
095c573 @stuartm Support specifying font size in pixels (height) alongside the traditi…
stuartm authored
211 else if (info.tagName() == "pixelsize")
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
212 {
095c573 @stuartm Support specifying font size in pixels (height) alongside the traditi…
stuartm authored
213 pixelsize = getFirstText(info).toInt();
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
214 }
215 else if (info.tagName() == "color")
216 {
217 newFont->m_color = QColor(getFirstText(info));
218 }
219 else if (info.tagName() == "dropcolor" ||
220 info.tagName() == "shadowcolor")
221 {
222 newFont->m_shadowColor = QColor(getFirstText(info));
223 }
224 else if (info.tagName() == "shadow" ||
225 info.tagName() == "shadowoffset")
226 {
227 newFont->m_hasShadow = true;
228 newFont->m_shadowOffset = parsePoint(info);
229 }
230 else if (info.tagName() == "shadowalpha")
231 {
232 newFont->m_shadowAlpha = getFirstText(info).toInt();
233 }
234 else if (info.tagName() == "outlinecolor")
235 {
236 newFont->m_outlineColor = QColor(getFirstText(info));
237 }
238 else if (info.tagName() == "outlinesize")
239 {
240 newFont->m_hasOutline = true;
241 newFont->m_outlineSize = getFirstText(info).toInt();
242 }
243 else if (info.tagName() == "outlinealpha")
244 {
245 newFont->m_outlineAlpha = getFirstText(info).toInt();
246 }
247 else if (info.tagName() == "bold")
248 {
249 newFont->m_face.setBold(parseBool(info));
250 }
251 else if (info.tagName() == "italics")
252 {
253 newFont->m_face.setItalic(parseBool(info));
254 }
255 else if (info.tagName() == "underline")
256 {
257 newFont->m_face.setUnderline(parseBool(info));
258 }
9ea1833 Add "wordspacing" and "letterspacing" font properties in MythUI. All…
Robert McNamara authored
259 else if (info.tagName() == "letterspacing")
260 {
261 newFont->m_face.setLetterSpacing(QFont::AbsoluteSpacing,
262 getFirstText(info).toInt());
263 }
264 else if (info.tagName() == "wordspacing")
265 {
266 newFont->m_face.setWordSpacing(getFirstText(info).toInt());
267 }
ff1f271 Expand MythUI font parsing with decoration, weight, and stretch value…
Robert McNamara authored
268 else if (info.tagName() == "decoration")
269 {
270 QString dec = getFirstText(info).toLower();
1f825a6 @stuartm More fixes in libmythui of issues reported by the krazy2 static analy…
stuartm authored
271 QStringList values = dec.split(',');
ff1f271 Expand MythUI font parsing with decoration, weight, and stretch value…
Robert McNamara authored
272
273 QStringList::Iterator it;
274 for ( it = values.begin(); it != values.end(); ++it )
275 {
276 if (*it == "underline")
277 newFont->m_face.setUnderline(true);
278 else if (*it == "overline")
279 newFont->m_face.setOverline(true);
280 else if (*it == "strikeout")
281 newFont->m_face.setStrikeOut(true);
282 }
283 }
284 else if (info.tagName() == "weight")
285 {
286 QString weight = getFirstText(info).toLower();
287
288 if (weight == "ultralight" ||
289 weight == "1")
290 newFont->m_face.setWeight(1);
291 else if (weight == "light" ||
292 weight == "2")
293 newFont->m_face.setWeight(QFont::Light);
294 else if (weight == "normal" ||
295 weight == "3")
296 newFont->m_face.setWeight(QFont::Normal);
297 else if (weight == "demibold" ||
298 weight == "4")
299 newFont->m_face.setWeight(QFont::DemiBold);
300 else if (weight == "bold" ||
301 weight == "5")
302 newFont->m_face.setWeight(QFont::Bold);
303 else if (weight == "black" ||
304 weight == "6")
305 newFont->m_face.setWeight(QFont::Black);
306 else if (weight == "ultrablack" ||
307 weight == "7")
308 newFont->m_face.setWeight(100);
309 else
310 newFont->m_face.setWeight(QFont::Normal);
311 }
312 else if (info.tagName() == "stretch")
313 {
314 QString stretch = getFirstText(info).toLower();
315
316 if (stretch == "ultracondensed" ||
317 stretch == "1")
318 newFont->m_face.setStretch(QFont::UltraCondensed);
319 else if (stretch == "extracondensed" ||
320 stretch == "2")
321 newFont->m_face.setStretch(QFont::ExtraCondensed);
322 else if (stretch == "condensed" ||
323 stretch == "3")
324 newFont->m_face.setStretch(QFont::Condensed);
325 else if (stretch == "semicondensed" ||
326 stretch == "4")
327 newFont->m_face.setStretch(QFont::SemiCondensed);
328 else if (stretch == "unstretched" ||
329 stretch == "5")
330 newFont->m_face.setStretch(QFont::Unstretched);
331 else if (stretch == "semiexpanded" ||
332 stretch == "6")
333 newFont->m_face.setStretch(QFont::SemiExpanded);
334 else if (stretch == "expanded" ||
335 stretch == "7")
336 newFont->m_face.setStretch(QFont::Expanded);
337 else if (stretch == "extraexpanded" ||
338 stretch == "8")
339 newFont->m_face.setStretch(QFont::ExtraExpanded);
340 else if (stretch == "ultraexpanded" ||
341 stretch == "9")
342 newFont->m_face.setStretch(QFont::UltraExpanded);
343 else
344 newFont->m_face.setStretch(QFont::Unstretched);
345 }
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
346 else
347 {
0a77575 @stuartm Provide more information such as line number, element type and name i…
stuartm authored
348 XML_ERROR(info, QString("Unknown tag in font %1").arg(name));
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
349 return NULL;
350 }
351 }
352 }
353
095c573 @stuartm Support specifying font size in pixels (height) alongside the traditi…
stuartm authored
354 if (size <= 0 && pixelsize <= 0 && !fromBase)
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
355 {
0a77575 @stuartm Provide more information such as line number, element type and name i…
stuartm authored
356 XML_ERROR(element, "Error, font size must be > 0");
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
357 return NULL;
358 }
095c573 @stuartm Support specifying font size in pixels (height) alongside the traditi…
stuartm authored
359 else if (pixelsize > 0)
360 newFont->m_face.setPixelSize(GetMythMainWindow()->NormY(pixelsize));
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
361 else if (size > 0)
21ad970 @stuartm Permit fonts to be inherited in the local context as well as global.
stuartm authored
362 newFont->m_face.setPointSize(GetMythMainWindow()->NormalizeFontSize(size));
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
363
364 newFont->Unfreeze();
365
366 if (addToGlobal)
367 GetGlobalFontMap()->AddFont(name, newFont);
368
369 return newFont;
370 }
371
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
372 static FontMap *gFontMap = NULL;
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
373
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
374 // FIXME: remove
7860579 Get rid of the circular dependencies between libraries.
Isaac Richards authored
375 QMap<QString, fontProp> globalFontMap;
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
376
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
377 MythFontProperties *FontMap::GetFont(const QString &text)
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
378 {
379 if (text.isEmpty())
380 return NULL;
381
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
382 if (m_FontMap.contains(text))
383 return &(m_FontMap[text]);
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
384 return NULL;
385 }
386
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
387 bool FontMap::AddFont(const QString &text, MythFontProperties *font)
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
388 {
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
389 if (!font || text.isEmpty())
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
390 return false;
391
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
392 if (m_FontMap.contains(text))
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
393 {
394 VERBOSE(VB_IMPORTANT, QString("Already have a font: %1").arg(text));
395 return false;
396 }
397
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
398 m_FontMap[text] = *font;
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
399
400 {
401 /* FIXME backwards compat, remove */
402 fontProp oldf;
403
404 oldf.face = font->m_face;
405 oldf.color = font->m_color;
406 if (font->m_hasShadow)
407 {
408 oldf.dropColor = font->m_shadowColor;
409 oldf.shadowOffset = font->m_shadowOffset;
410 }
411
412 globalFontMap[text] = oldf;
413 }
414
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
415 return true;
416 }
417
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
418 bool FontMap::Contains(const QString &text)
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
419 {
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
420 return m_FontMap.contains(text);
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
421 }
422
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
423 void FontMap::Clear(void)
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
424 {
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
425 m_FontMap.clear();
3e0c22a Finally have a new XML parsing framework for mythui that I'm happy wi…
Isaac Richards authored
426
427 //FIXME: remove
428 globalFontMap.clear();
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
429 }
430
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
431 FontMap *FontMap::GetGlobalFontMap(void)
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
432 {
433 if (!gFontMap)
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
434 gFontMap = new FontMap();
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
435 return gFontMap;
436 }
437
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
438 FontMap *GetGlobalFontMap(void)
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
439 {
35d3db0 Flesh out the rest of the UI types for parsing/inheriting, and make i…
Isaac Richards authored
440 return FontMap::GetGlobalFontMap();
e02cc1a Silly little storage class for fonts.
Isaac Richards authored
441 }
442
Something went wrong with that request. Please try again.