3 #include <QFontDatabase>
5 #include <QMutexLocker>
13 #define LOC QString("MythFontManager: ")
30 const QString ®isteredFor)
33 LoadFonts(directory, registeredFor, &maxDirs);
35 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
36 QFontDatabase database;
37 QStringList families = database.families();
39 QStringList families = QFontDatabase::families();
41 for (
const QString & family : std::as_const(families))
43 QString result = QString(
"Font Family '%1': ").arg(family);
44 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
45 QStringList styles = database.styles(family);
47 QStringList styles = QFontDatabase::styles(family);
49 for (
const QString & style : std::as_const(styles))
51 result += QString(
"%1(").arg(style);
54 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
55 QList<int> pointList = database.smoothSizes(family, style);
57 QList<int> pointList = QFontDatabase::smoothSizes(family, style);
59 for (
int points : std::as_const(pointList))
60 sizes += QString::number(points) +
' ';
62 result += QString(
"%1) ").arg(sizes.trimmed());
65 LOG(VB_GUI, LOG_DEBUG,
LOC + result.trimmed());
82 const QString ®isteredFor,
int *maxDirs)
84 if (directory.isEmpty() || directory ==
"/" || registeredFor.isEmpty())
89 LOG(VB_GENERAL, LOG_WARNING,
LOC +
90 "Reached the maximum directory depth "
91 "for a font directory structure. Terminating font scan.");
99 QFileInfoList files = dir.entryInfoList();
100 for (
const auto&
info : std::as_const(files))
104 if (!
info.baseName().isEmpty() &&
info.isDir())
119 if (registeredFor.isEmpty())
122 QMutexLocker locker(&
m_lock);
129 LOG(VB_FILE, LOG_DEBUG,
LOC +
130 QString(
"Removing application font '%1'")
136 if (QFontDatabase::removeApplicationFont(fontRef->
GetFontID()))
138 LOG(VB_FILE, LOG_DEBUG,
LOC +
139 QString(
"Successfully removed application font '%1'")
144 LOG(VB_GENERAL, LOG_WARNING,
LOC +
145 QString(
"Unable to remove application font '%1'")
168 const QString ®isteredFor)
170 if (directory.isEmpty() || directory ==
"/" || registeredFor.isEmpty())
173 LOG(VB_FILE, LOG_DEBUG,
LOC +
174 QString(
"Scanning directory '%1' for font files.").arg(directory));
177 QStringList nameFilters = QStringList() <<
"*.ttf" <<
"*.otf" <<
"*.ttc";
178 QFileInfoList fontFileInfos = dir.entryInfoList(nameFilters);
179 for (
const auto &
info : std::as_const(fontFileInfos)) {
191 const QString ®isteredFor)
193 if (fontPath.isEmpty() || fontPath ==
"/" || registeredFor.isEmpty())
196 QMutexLocker locker(&
m_lock);
199 LOG(VB_GUI | VB_FILE, LOG_INFO,
LOC +
200 QString(
"Font file '%1' already loaded")
205 LOG(VB_GUI | VB_FILE, LOG_INFO,
LOC +
206 QString(
"Unable to load font(s) in file '%1'")
212 LOG(VB_GUI | VB_FILE, LOG_INFO,
LOC +
213 QString(
"Loading font file: '%1'").arg(fontPath));
215 int result = QFontDatabase::addApplicationFont(fontPath);
218 LOG(VB_GUI | VB_FILE, LOG_DEBUG,
LOC +
219 QString(
"In file '%1', found font(s) '%2'")
221 QFontDatabase::applicationFontFamilies(result)
226 LOG(VB_GENERAL, LOG_WARNING,
LOC +
227 QString(
"Unable to register font(s) in file '%1'")
233 LOG(VB_GENERAL, LOG_WARNING,
LOC +
234 QString(
"Unable to load font(s) in file '%1'")
249 const QString ®isteredFor,
255 QList<MythFontReference*> values;
257 if (values.isEmpty())
277 return !values.isEmpty();