7 #include <QCoreApplication>
8 #include <QDomDocument>
10 #include <QFontDatabase>
12 #include <QRegularExpression>
21 #define LOC QString("MythFontProperties: ")
54 const QColor &color,
int alpha)
139 int newStretch = lroundf((
float)
m_stretch * ((
float)stretch / 100.0F));
144 m_face.setStretch(newStretch);
156 float pixels = (float)points / 72.0F * 100.0F;
173 const QDomElement &element,
180 static bool s_showAvailable =
true;
181 bool fromBase =
false;
185 if (element.tagName() ==
"font")
187 LOG(VB_GENERAL, LOG_WARNING,
LOC +
188 QString(
"File %1: Use of 'font' is deprecated in favour of "
192 QString name = element.attribute(
"name",
"");
196 filename, element,
"Font requires a name");
201 QString base = element.attribute(
"from",
"");
216 QString(
"Specified base font '%1' does not exist.").
arg(base));
229 QString
face = element.attribute(
"face",
"");
235 "Font needs a face");
242 newFont->m_face.setFamily(
face);
251 QString(
"Attempting to define '%1'\n\t\t\t"
252 "with face '%2', but it already "
253 "exists with face '%3'")
254 .
arg(name).
arg(QFontInfo(newFont->m_face).family())
255 .arg((
tmp) ? QFontInfo(
tmp->m_face).family() :
"ERROR"));
261 QString hint = element.attribute(
"stylehint",
"");
264 newFont->m_face.setStyleHint((QFont::StyleHint)hint.toInt());
267 for (QDomNode child = element.firstChild(); !child.isNull();
268 child = child.nextSibling())
270 QDomElement info = child.toElement();
273 if (info.tagName() ==
"size")
277 else if (info.tagName() ==
"pixelsize")
281 else if (info.tagName() ==
"color")
285 else if (info.tagName() ==
"gradient")
289 else if (info.tagName() ==
"shadowcolor")
293 else if (info.tagName() ==
"shadowoffset")
295 newFont->m_hasShadow =
true;
296 newFont->m_shadowOffset =
parsePoint(info,
false);
298 else if (info.tagName() ==
"shadowalpha")
302 else if (info.tagName() ==
"outlinecolor")
306 else if (info.tagName() ==
"outlinesize")
308 newFont->m_hasOutline =
true;
311 else if (info.tagName() ==
"outlinealpha")
315 else if (info.tagName() ==
"italics")
317 newFont->m_face.setItalic(
parseBool(info));
319 else if (info.tagName() ==
"letterspacing")
321 newFont->m_face.setLetterSpacing(QFont::AbsoluteSpacing,
324 else if (info.tagName() ==
"wordspacing")
326 newFont->m_face.setWordSpacing(
getFirstText(info).toInt());
328 else if (info.tagName() ==
"decoration")
331 QStringList values = dec.split(
',');
333 QStringList::Iterator it;
334 for ( it = values.begin(); it != values.end(); ++it )
336 if (*it ==
"underline")
337 newFont->m_face.setUnderline(
true);
338 else if (*it ==
"overline")
339 newFont->m_face.setOverline(
true);
340 else if (*it ==
"strikeout")
341 newFont->m_face.setStrikeOut(
true);
344 else if (info.tagName() ==
"weight")
348 if (weight ==
"ultralight" ||
350 newFont->m_face.setWeight(1);
351 else if (weight ==
"light" ||
353 newFont->m_face.setWeight(QFont::Light);
354 else if (weight ==
"normal" ||
356 newFont->m_face.setWeight(QFont::Normal);
357 else if (weight ==
"demibold" ||
359 newFont->m_face.setWeight(QFont::DemiBold);
360 else if (weight ==
"bold" ||
362 newFont->m_face.setWeight(QFont::Bold);
363 else if (weight ==
"black" ||
365 newFont->m_face.setWeight(QFont::Black);
366 else if (weight ==
"ultrablack" ||
368 newFont->m_face.setWeight(99);
370 newFont->m_face.setWeight(QFont::Normal);
372 else if (info.tagName() ==
"stretch")
376 if (stretch ==
"ultracondensed" ||
378 newFont->m_stretch = QFont::UltraCondensed;
379 else if (stretch ==
"extracondensed" ||
381 newFont->m_stretch = QFont::ExtraCondensed;
382 else if (stretch ==
"condensed" ||
384 newFont->m_stretch = QFont::Condensed;
385 else if (stretch ==
"semicondensed" ||
387 newFont->m_stretch = QFont::SemiCondensed;
388 else if (stretch ==
"unstretched" ||
390 newFont->m_stretch = QFont::Unstretched;
391 else if (stretch ==
"semiexpanded" ||
393 newFont->m_stretch = QFont::SemiExpanded;
394 else if (stretch ==
"expanded" ||
396 newFont->m_stretch = QFont::Expanded;
397 else if (stretch ==
"extraexpanded" ||
399 newFont->m_stretch = QFont::ExtraExpanded;
400 else if (stretch ==
"ultraexpanded" ||
402 newFont->m_stretch = QFont::UltraExpanded;
404 newFont->m_stretch = QFont::Unstretched;
406 newFont->m_face.setStretch(newFont->m_stretch);
411 QString(
"Unknown tag in font '%1'").
arg(name));
418 if (size <= 0 && pixelsize <= 0 && !fromBase)
421 "Font size must be greater than 0.");
427 newFont->SetPixelSize(pixelsize);
431 newFont->SetPointSize(size);
436 QFontInfo fi(newFont->m_face);
438 fi.family().remove(QRegularExpression(
"\\[.*]")).trimmed();
439 if (newFont->m_face.family() != fi_family)
442 QString(
"Failed to load '%1', got '%2' instead")
443 .
arg(newFont->m_face.family()).arg(fi.family()));
447 LOG(VB_GUI, LOG_DEBUG,
"Available fonts:");
449 QFontDatabase database;
451 QStringList families = database.families();
452 for (
const QString & family : qAsConst(families))
454 QStringList family_styles;
456 family_styles << family +
"::";
457 QStringList styles = database.styles(family);
458 for (
const QString & style : qAsConst(styles))
460 family_styles << style +
":";
464 QList<int> pointList = database.smoothSizes(family, style);
465 for (
int points : qAsConst(pointList))
470 sizes += QString::number(points);
474 family_styles << sizes.trimmed();
476 LOG(VB_GUI, LOG_DEBUG, family_styles.join(
" "));
478 s_showAvailable =
false;
484 QString(
"loaded '%1'").
arg(fi.family()));
510 if (!font || text.isEmpty())
515 LOG(VB_GENERAL, LOG_ERR,
LOC +
516 QString(
"Already have a font: %1").
arg(text));
558 height = rect.height();
561 QMap<QString, MythFontProperties>::iterator it;
564 (*it).Rescale(height);