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
qwindowsfontdatabase_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWINDOWSFONTDATABASE_H
5#define QWINDOWSFONTDATABASE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19
20#include <qpa/qplatformfontdatabase.h>
21#include <QtCore/QSharedPointer>
22#include <QtCore/QLoggingCategory>
23#include <QtCore/qhashfunctions.h>
24#include <QtCore/qmutex.h>
25#include <QtCore/qt_windows.h>
26
28
29class QDebug;
30
32{
33 Q_DISABLE_COPY_MOVE(QWindowsFontDatabase)
34public:
36 // Relevant bits from QWindowsIntegration::Options
37 DontUseDirectWriteFonts = 0x40,
38 DontUseColorFonts = 0x80
39 };
40
42 ~QWindowsFontDatabase() override;
43
44 void ensureFamilyPopulated(const QString &familyName);
45
46 void populateFontDatabase() override;
47 void invalidate() override;
48 void removeApplicationFonts();
49
50 void populateFamily(const QString &familyName) override;
51 bool populateFamilyAliases(const QString &missingFamily) override;
52 QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) override;
53 QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
54 QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const override;
55 QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont = nullptr) override;
56 void releaseHandle(void *handle) override;
57 QString fontDir() const override;
58
59 QFont defaultFont() const override { return systemDefaultFont(); }
60 bool fontsAlwaysScalable() const override;
61 void derefUniqueFont(const QString &uniqueFont);
62 void refUniqueFont(const QString &uniqueFont);
63 bool isPrivateFontFamily(const QString &family) const override;
64
65 static QFontEngine *createEngine(const QFontDef &request, const QString &faceName,
66 int dpi,
67 const QSharedPointer<QWindowsFontEngineData> &data);
68
70
71 static void setFontOptions(unsigned options);
72 static unsigned fontOptions();
73
74#ifndef QT_NO_DEBUG_STREAM
75 static void debugFormat(QDebug &d, const LOGFONT &lf);
76#endif // !QT_NO_DEBUG_STREAM
77
78 struct FontHandle {
79 FontHandle(const QString &name) : faceName(name) {}
80 FontHandle(IDWriteFontFace *face, const QString &name);
82
83 IDWriteFontFace *fontFace = nullptr;
85 };
86
87private:
88 void addDefaultEUDCFont();
89
90 struct WinApplicationFont {
91 HANDLE handle;
93 };
94
95 QList<WinApplicationFont> m_applicationFonts;
96
97 struct UniqueFontData {
98 HANDLE handle;
99 int refCount;
100 };
101
102 QMutex m_uniqueFontDataMutex; // protects m_uniqueFontData
103 QMap<QString, UniqueFontData> m_uniqueFontData;
104
105 static unsigned m_fontOptions;
106 QStringList m_eudcFonts;
107 bool m_hasPopulatedAliases = false;
108};
109
110#ifndef QT_NO_DEBUG_STREAM
111QDebug operator<<(QDebug, const QFontDef &def);
112#endif
113
114inline quint16 qt_getUShort(const unsigned char *p)
115{
116 quint16 val;
117 val = *p++ << 8;
118 val |= *p;
119
120 return val;
121}
122
124{
125 QString name; // e.g. "DejaVu Sans Condensed"
126 QString style; // e.g. "Italic"
127 QString preferredName; // e.g. "DejaVu Sans"
128 QString preferredStyle; // e.g. "Condensed Italic"
129};
130
132{
134 bool isItalic = false;
135 bool isOverstruck = false;
136 bool isUnderlined = false;
137};
138
139bool qt_localizedName(const QString &name);
140QString qt_getEnglishName(const QString &familyName, bool includeStyle = false);
141QFontNames qt_getCanonicalFontNames(const LOGFONT &lf);
142
146
147 friend inline bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
148 { return lhs.font == rhs.font && lhs.style == rhs.style; }
149 friend inline bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
150 { return !operator==(lhs, rhs); }
151};
152inline size_t qHash(const FontAndStyle &key, size_t seed) noexcept
153{
154 return qHashMulti(seed, key.font, key.style);
155}
156
158
159#endif // QWINDOWSFONTDATABASE_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\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
HintingPreference
Definition qfont.h:55
Style
This enum describes the different styles of glyphs that are used to display text.
Definition qfont.h:76
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Font database for Windows.
QFont defaultFont() const override
Returns the default system font.
void ensureFamilyPopulated(const QString &familyName)
Combined button and popup list for selecting options.
static QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script)
Engine * createEngine(QGeoServiceProviderPrivate *)
static Q_CONSTINIT qreal fontSmoothingGamma
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
GLuint64 GLenum void * handle
GLuint64 key
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum face
GLuint GLuint GLfloat weight
GLuint name
GLenum GLsizeiptr const void * fontData
GLuint GLfloat * val
GLfloat GLfloat p
[1]
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
unsigned short quint16
Definition qtypes.h:48
double qreal
Definition qtypes.h:187
quint16 qt_getUShort(const unsigned char *p)
QFontNames qt_getCanonicalFontNames(const LOGFONT &lf)
QString qt_getEnglishName(const QString &familyName, bool includeStyle=false)
QDebug operator<<(QDebug, const QFontDef &def)
size_t qHash(const FontAndStyle &key, size_t seed) noexcept
bool qt_localizedName(const QString &name)
QNetworkRequest request(url)
friend bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
friend bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept