Qt 6.x
The Qt SDK
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/qt_windows.h>
25
27
28class QDebug;
29
31{
32 Q_DISABLE_COPY_MOVE(QWindowsFontDatabase)
33public:
35 // Relevant bits from QWindowsIntegration::Options
36 DontUseDirectWriteFonts = 0x40,
37 DontUseColorFonts = 0x80
38 };
39
41 ~QWindowsFontDatabase() override;
42
43 void ensureFamilyPopulated(const QString &familyName);
44
45 void populateFontDatabase() override;
46 void invalidate() override;
47
48 void populateFamily(const QString &familyName) override;
49 bool populateFamilyAliases(const QString &missingFamily) override;
50 QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) override;
51 QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
52 QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const override;
54 void releaseHandle(void *handle) override;
55 QString fontDir() const override;
56
57 QFont defaultFont() const override { return systemDefaultFont(); }
58 bool fontsAlwaysScalable() const override;
59 void derefUniqueFont(const QString &uniqueFont);
60 void refUniqueFont(const QString &uniqueFont);
61 bool isPrivateFontFamily(const QString &family) const override;
62
63 static QFontEngine *createEngine(const QFontDef &request, const QString &faceName,
64 int dpi,
66
68
69 static void setFontOptions(unsigned options);
70 static unsigned fontOptions();
71
72#ifndef QT_NO_DEBUG_STREAM
73 static void debugFormat(QDebug &d, const LOGFONT &lf);
74#endif // !QT_NO_DEBUG_STREAM
75
76private:
77 void removeApplicationFonts();
78 void addDefaultEUDCFont();
79
80 struct WinApplicationFont {
81 HANDLE handle;
83 };
84
85 QList<WinApplicationFont> m_applicationFonts;
86
87 struct UniqueFontData {
89 QAtomicInt refCount;
90 };
91
92 QMap<QString, UniqueFontData> m_uniqueFontData;
93
94 static unsigned m_fontOptions;
95 QStringList m_eudcFonts;
96 bool m_hasPopulatedAliases = false;
97};
98
99#ifndef QT_NO_DEBUG_STREAM
100QDebug operator<<(QDebug, const QFontDef &def);
101#endif
102
103inline quint16 qt_getUShort(const unsigned char *p)
104{
105 quint16 val;
106 val = *p++ << 8;
107 val |= *p;
108
109 return val;
110}
111
113{
114 QString name; // e.g. "DejaVu Sans Condensed"
115 QString style; // e.g. "Italic"
116 QString preferredName; // e.g. "DejaVu Sans"
117 QString preferredStyle; // e.g. "Condensed Italic"
118};
119
121{
123 bool isItalic = false;
124 bool isOverstruck = false;
125 bool isUnderlined = false;
126};
127
128bool qt_localizedName(const QString &name);
129QString qt_getEnglishName(const QString &familyName, bool includeStyle = false);
130QFontNames qt_getCanonicalFontNames(const LOGFONT &lf);
131
135
136 friend inline bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
137 { return lhs.font == rhs.font && lhs.style == rhs.style; }
138 friend inline bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
139 { return !operator==(lhs, rhs); }
140};
141inline size_t qHash(const FontAndStyle &key, size_t seed) noexcept
142{
143 return qHashMulti(seed, key.font, key.style);
144}
145
147
148#endif // QWINDOWSFONTDATABASE_H
\inmodule QtCore
Definition qatomic.h:112
\inmodule QtCore
Definition qbytearray.h:57
Script
Definition qchar.h:144
\inmodule QtCore
\reentrant
Definition qfont.h:20
StyleHint
Style hints are used by the \l{QFont}{font matching} algorithm to find an appropriate default family ...
Definition qfont.h:23
HintingPreference
Definition qfont.h:52
Style
This enum describes the different styles of glyphs that are used to display text.
Definition qfont.h:73
Definition qlist.h:74
Definition qmap.h:186
virtual QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *font=nullptr)
Adds an application font described by the font contained supplied fontData or using the font containe...
virtual bool populateFamilyAliases(const QString &missingFamily)
virtual QString fontDir() const
Returns the directory containing the fonts used by the database.
virtual bool fontsAlwaysScalable() const
Return true if all fonts are considered scalable when using this font database.
virtual void releaseHandle(void *handle)
Releases the specified font handle.
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...
virtual void populateFamily(const QString &familyName)
This function is called whenever a lazily populated family, populated through registerFontFamily(),...
virtual bool isPrivateFontFamily(const QString &family) const
Returns true if the font family is private.
virtual void invalidate()
This function is called whenever the font database is invalidated.
virtual void populateFontDatabase()
This function is called once at startup by Qt's internal font database.
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QFontEngine * fontEngine(const QFontDef &fontDef, void *handle) override
Returns the font engine that can be used to render the font described by the font definition,...
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.
void * HANDLE
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
GLuint GLuint GLfloat weight
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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:43
double qreal
Definition qtypes.h:92
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