Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include <QDir>
5#include <QLocale>
6
8
10
11using namespace Qt::StringLiterals;
12
14{
15 return "/system/fonts"_L1;
16}
17
19{
20 return QFont("Roboto"_L1);
21}
22
24{
25 QString fontpath = fontDir();
26 QDir dir(fontpath);
27
28 if (Q_UNLIKELY(!dir.exists())) {
29 qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
30 qPrintable(fontpath));
31 }
32
33 QStringList nameFilters;
34 nameFilters << "*.ttf"_L1
35 << "*.otf"_L1
36 << "*.ttc"_L1;
37
38 const auto entries = dir.entryInfoList(nameFilters, QDir::Files);
39 for (const QFileInfo &fi : entries) {
40 const QByteArray file = QFile::encodeName(fi.absoluteFilePath());
42 }
43}
44
46 QFont::Style style,
47 QFont::StyleHint styleHint,
48 QChar::Script script) const
49{
51
52 // Prepend CJK fonts by the locale.
53 QLocale locale = QLocale::system();
54 switch (locale.language()) {
55 case QLocale::Chinese: {
56 switch (locale.territory()) {
57 case QLocale::China:
59 result.append(QStringLiteral("Noto Sans Mono CJK SC"));
60 break;
61 case QLocale::Taiwan:
63 case QLocale::Macao:
64 result.append(QStringLiteral("Noto Sans Mono CJK TC"));
65 break;
66 default:
67 // no modifications.
68 break;
69 }
70 break;
71 }
73 result.append(QStringLiteral("Noto Sans Mono CJK JP"));
74 break;
75 case QLocale::Korean:
76 result.append(QStringLiteral("Noto Sans Mono CJK KR"));
77 break;
78 default:
79 // no modifications.
80 break;
81 }
82
83 if (styleHint == QFont::Monospace || styleHint == QFont::Courier)
84 result.append(QString(qgetenv("QT_ANDROID_FONTS_MONOSPACE")).split(u';'));
85 else if (styleHint == QFont::Serif)
86 result.append(QString(qgetenv("QT_ANDROID_FONTS_SERIF")).split(u';'));
87 else
88 result.append(QString(qgetenv("QT_ANDROID_FONTS")).split(u';'));
89 result.append(QFreeTypeFontDatabase::fallbacksForFamily(family, style, styleHint, script));
90
91 return result;
92}
93
QString fontDir() const override
Returns the directory containing the fonts used by the database.
void populateFontDatabase() override
This function is called once at startup by Qt's internal font database.
QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const override
Returns a list of alternative fonts for the specified family and style and script using the styleHint...
QFont defaultFont() const override
Returns the default system font.
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qdir.h:20
@ Files
Definition qdir.h:23
static QByteArray encodeName(const QString &fileName)
Converts fileName to an 8-bit encoding that you can use in native APIs.
Definition qfile.h:158
\reentrant
Definition qfont.h:22
StyleHint
Style hints are used by the \l{QFont}{font matching} algorithm to find an appropriate default family ...
Definition qfont.h:25
@ Monospace
Definition qfont.h:33
@ Serif
Definition qfont.h:27
@ Courier
Definition qfont.h:28
Style
This enum describes the different styles of glyphs that are used to display text.
Definition qfont.h:76
static QStringList addTTFile(const QByteArray &fontData, const QByteArray &file, QFontDatabasePrivate::ApplicationFont *applicationFont=nullptr)
@ Macao
Definition qlocale.h:707
@ HongKong
Definition qlocale.h:675
@ Taiwan
Definition qlocale.h:796
@ China
Definition qlocale.h:618
@ Singapore
Definition qlocale.h:778
static QLocale system()
Returns a QLocale object initialized to the system locale.
Definition qlocale.cpp:2862
@ Korean
Definition qlocale.h:186
@ Chinese
Definition qlocale.h:102
@ Japanese
Definition qlocale.h:164
virtual QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const
Returns a list of alternative fonts for the specified family and style and script using the styleHint...
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
#define qFatal
Definition qlogging.h:168
GLuint64EXT * result
[6]
static void split(QT_FT_Vector *b)
#define qPrintable(string)
Definition qstring.h:1531
#define QStringLiteral(str)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QFile file
[0]
QString dir
[11]