Skip to content

Commit 2c412bd

Browse files
committed
GUI/tonalutils: For Tonal support detection, check that the font has all glyphs and they all have the same sizes
1 parent d65857b commit 2c412bd

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/qt/tonalutils.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,31 @@
1010
#include <QRegExpValidator>
1111
#include <QString>
1212

13+
static const QList<QChar> tonal_digits{0xe9df, 0xe9de, 0xe9dd, 0xe9dc, 0xe9db, 0xe9da, 0xe9d9, '8', '7', '6', '5', '4', '3', '2', '1', '0'};
14+
15+
namespace {
16+
17+
bool font_supports_tonal(const QFont& font)
18+
{
19+
const QFontMetrics fm(font);
20+
QString s = "000";
21+
const QSize sz = fm.size(0, s);
22+
for (const auto& c : tonal_digits) {
23+
if (!fm.inFont(c)) return false;
24+
if (sz != fm.size(0, s)) return false;
25+
}
26+
return true;
27+
}
28+
29+
} // anon namespace
30+
1331
bool TonalUtils::Supported()
1432
{
15-
QFontMetrics fm = QFontMetrics(QFont());
16-
return fm.inFont(0xe9d9);
33+
QFont default_font;
34+
if (font_supports_tonal(default_font)) return true;
35+
QFont last_resort_font(default_font.lastResortFamily());
36+
if (font_supports_tonal(last_resort_font)) return true;
37+
return false;
1738
}
1839

1940
static QRegExpValidator tv(QRegExp("-?(?:[\\d\\xe9d9-\\xe9df]+\\.?|[\\d\\xe9d9-\\xe9df]*\\.[\\d\\xe9d9-\\xe9df]*)"), nullptr);

0 commit comments

Comments
 (0)