Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
31class Q_GUI_EXPORT QWindowsFontDatabase : public QWindowsFontDatabaseBase
32{
33 Q_DISABLE_COPY_MOVE(QWindowsFontDatabase)
34public:
35 enum FontOptions {
36 // Relevant bits from QWindowsIntegration::Options
37 DontUseDirectWriteFonts = 0x40,
38 DontUseColorFonts = 0x80
39 };
40
41 QWindowsFontDatabase();
42 ~QWindowsFontDatabase() override;
43
44 void ensureFamilyPopulated(const QString &familyName);
45
46 void populateFontDatabase() override;
47 void invalidate() override;
48 void removeApplicationFonts();
49 bool supportsColrv0Fonts() const override;
50
51 void populateFamily(const QString &familyName) override;
52 bool populateFamilyAliases(const QString &missingFamily) override;
53 QFontEngine *fontEngine(const QFontDef &fontDef, void *handle) override;
54 QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference) override;
55 QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QFontDatabasePrivate::ExtendedScript script) const override;
56 QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont = nullptr) override;
57 void releaseHandle(void *handle) override;
58 QString fontDir() const override;
59
60 QFont defaultFont() const override { return systemDefaultFont(); }
61 bool fontsAlwaysScalable() const override;
62 void derefUniqueFont(const QString &uniqueFont);
63 void refUniqueFont(const QString &uniqueFont);
64 bool isPrivateFontFamily(const QString &family) const override;
65
66 static QFontEngine *createEngine(const QFontDef &request, const QString &faceName,
67 int dpi,
68 const QSharedPointer<QWindowsFontEngineData> &data);
69
70 static qreal fontSmoothingGamma();
71
72 static void setFontOptions(unsigned options);
73 static unsigned fontOptions();
74
75#ifndef QT_NO_DEBUG_STREAM
76 static void debugFormat(QDebug &d, const LOGFONT &lf);
77#endif // !QT_NO_DEBUG_STREAM
78
79 struct FontHandle {
80 FontHandle(const QString &name) : faceName(name) {}
81 FontHandle(IDWriteFontFace *face, const QString &name);
82 ~FontHandle();
83
84 IDWriteFontFace *fontFace = nullptr;
85 QString faceName;
86 };
87
88private:
89 void addDefaultEUDCFont();
90
91 struct WinApplicationFont {
92 HANDLE handle;
93 QString fileName;
94 };
95
96 QList<WinApplicationFont> m_applicationFonts;
97
98 struct UniqueFontData {
99 HANDLE handle;
100 int refCount;
101 };
102
103 QMutex m_uniqueFontDataMutex; // protects m_uniqueFontData
104 QMap<QString, UniqueFontData> m_uniqueFontData;
105
106 static unsigned m_fontOptions;
107 QStringList m_eudcFonts;
108 bool m_hasPopulatedAliases = false;
109};
110
111#ifndef QT_NO_DEBUG_STREAM
112QDebug operator<<(QDebug, const QFontDef &def);
113#endif
114
115inline quint16 qt_getUShort(const unsigned char *p)
116{
117 quint16 val;
118 val = *p++ << 8;
119 val |= *p;
120
121 return val;
122}
123
125{
126 QString name; // e.g. "DejaVu Sans Condensed"
127 QString style; // e.g. "Italic"
128 QString preferredName; // e.g. "DejaVu Sans"
129 QString preferredStyle; // e.g. "Condensed Italic"
130};
131
133{
135 bool isItalic = false;
136 bool isOverstruck = false;
137 bool isUnderlined = false;
138};
139
140bool qt_localizedName(const QString &name);
141QString qt_getEnglishName(const QString &familyName, bool includeStyle = false);
142QFontNames qt_getCanonicalFontNames(const LOGFONT &lf);
143
147
148 friend inline bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
149 { return lhs.font == rhs.font && lhs.style == rhs.style; }
150 friend inline bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
151 { return !operator==(lhs, rhs); }
152};
153inline size_t qHash(const FontAndStyle &key, size_t seed) noexcept
154{
155 return qHashMulti(seed, key.font, key.style);
156}
157
158QT_END_NAMESPACE
159
160#endif // QWINDOWSFONTDATABASE_H
Font database for Windows.
static QFont::Stretch fromDirectWriteStretch(DWRITE_FONT_STRETCH stretch)
static QFont::Weight fromDirectWriteWeight(DWRITE_FONT_WEIGHT weight)
static QFont::Style fromDirectWriteStyle(DWRITE_FONT_STYLE style)
QT_REQUIRE_CONFIG(directwrite3)
quint16 qt_getUShort(const unsigned char *p)
QFontNames qt_getCanonicalFontNames(const LOGFONT &lf)
QString qt_getEnglishName(const QString &familyName, bool includeStyle=false)
size_t qHash(const FontAndStyle &key, size_t seed) noexcept
bool qt_localizedName(const QString &name)
friend bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
friend bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept