Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qandroidplatformfontdatabase.cpp
Go to the documentation of this file.
1
// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
<
QDir
>
6
#
include
<
QLocale
>
7
8
#
include
"qandroidplatformfontdatabase.h"
9
10
QT_BEGIN_NAMESPACE
11
12
using
namespace
Qt::StringLiterals;
13
14
QString QAndroidPlatformFontDatabase::fontDir()
const
15
{
16
return
"/system/fonts"_L1
;
17
}
18
19
QFont QAndroidPlatformFontDatabase::defaultFont()
const
20
{
21
return
QFont(
"Roboto"_L1
);
22
}
23
24
void
QAndroidPlatformFontDatabase::populateFontDatabase()
25
{
26
QString fontpath = fontDir();
27
QDir dir(fontpath);
28
29
if
(Q_UNLIKELY(!dir.exists())) {
30
qFatal(
"QFontDatabase: Cannot find font directory %s - is Qt installed correctly?"
,
31
qPrintable(fontpath));
32
}
33
34
QStringList nameFilters;
35
nameFilters <<
"*.ttf"_L1
36
<<
"*.otf"_L1
37
<<
"*.ttc"_L1
;
38
39
const
auto
entries = dir.entryInfoList(nameFilters, QDir::Files);
40
for
(
const
QFileInfo &fi : entries) {
41
const
QByteArray file = QFile::encodeName(fi.absoluteFilePath());
42
QFreeTypeFontDatabase::addTTFile(QByteArray(), file);
43
}
44
}
45
46
QStringList QAndroidPlatformFontDatabase::fallbacksForFamily(
const
QString &family,
47
QFont::Style style,
48
QFont::StyleHint styleHint,
49
QFontDatabasePrivate::ExtendedScript script)
const
50
{
51
QStringList result;
52
53
if
(script == QFontDatabasePrivate::Script_Emoji) {
54
result.append(QStringLiteral(
"Noto Color Emoji"
));
55
result.append(QStringLiteral(
"Noto Color Emoji Flags"
));
56
}
57
58
// Prepend CJK fonts by the locale.
59
QLocale locale = QLocale::system();
60
switch
(locale.language()) {
61
case
QLocale::Chinese: {
62
switch
(locale.territory()) {
63
case
QLocale::China:
64
case
QLocale::Singapore:
65
result.append(QStringLiteral(
"Noto Sans Mono CJK SC"
));
66
break
;
67
case
QLocale::Taiwan:
68
case
QLocale::HongKong:
69
case
QLocale::Macao:
70
result.append(QStringLiteral(
"Noto Sans Mono CJK TC"
));
71
break
;
72
default
:
73
// no modifications.
74
break
;
75
}
76
break
;
77
}
78
case
QLocale::Japanese:
79
result.append(QStringLiteral(
"Noto Sans Mono CJK JP"
));
80
break
;
81
case
QLocale::Korean:
82
result.append(QStringLiteral(
"Noto Sans Mono CJK KR"
));
83
break
;
84
default
:
85
// no modifications.
86
break
;
87
}
88
89
if
(styleHint == QFont::Monospace || styleHint == QFont::Courier)
90
result.append(QString(qgetenv(
"QT_ANDROID_FONTS_MONOSPACE"
)).split(u';'));
91
else
if
(styleHint == QFont::Serif)
92
result.append(QString(qgetenv(
"QT_ANDROID_FONTS_SERIF"
)).split(u';'));
93
else
94
result.append(QString(qgetenv(
"QT_ANDROID_FONTS"
)).split(u';'));
95
result.append(QFreeTypeFontDatabase::fallbacksForFamily(family, style, styleHint, script));
96
97
return
result;
98
}
99
100
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
plugins
platforms
android
qandroidplatformfontdatabase.cpp
Generated on
for Qt by
1.18.0