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#if QT_CONFIG(directwrite)
82 FontHandle(IDWriteFontFace *face, const QString &name);
83#endif // !QT_NO_DIRECTWRITE
84 ~FontHandle();
85
86#if QT_CONFIG(directwrite)
87 IDWriteFontFace *fontFace = nullptr;
88#endif // !QT_NO_DIRECTWRITE
89 QString faceName;
90 };
91
92private:
93 void addDefaultEUDCFont();
94
95 struct WinApplicationFont {
96 HANDLE handle;
97 QString fileName;
98 };
99
100 QList<WinApplicationFont> m_applicationFonts;
101
102 struct UniqueFontData {
103 HANDLE handle;
104 int refCount;
105 };
106
107 QMutex m_uniqueFontDataMutex; // protects m_uniqueFontData
108 QMap<QString, UniqueFontData> m_uniqueFontData;
109
110 static unsigned m_fontOptions;
111 QStringList m_eudcFonts;
112 bool m_hasPopulatedAliases = false;
113};
114
115#ifndef QT_NO_DEBUG_STREAM
116QDebug operator<<(QDebug, const QFontDef &def);
117#endif
118
119inline quint16 qt_getUShort(const unsigned char *p)
120{
121 quint16 val;
122 val = *p++ << 8;
123 val |= *p;
124
125 return val;
126}
127
129{
130 QString name; // e.g. "DejaVu Sans Condensed"
131 QString style; // e.g. "Italic"
132 QString preferredName; // e.g. "DejaVu Sans"
133 QString preferredStyle; // e.g. "Condensed Italic"
134};
135
137{
139 bool isItalic = false;
140 bool isOverstruck = false;
141 bool isUnderlined = false;
142};
143
144bool qt_localizedName(const QString &name);
145QString qt_getEnglishName(const QString &familyName, bool includeStyle = false);
146QFontNames qt_getCanonicalFontNames(const LOGFONT &lf);
147
151
152 friend inline bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
153 { return lhs.font == rhs.font && lhs.style == rhs.style; }
154 friend inline bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept
155 { return !operator==(lhs, rhs); }
156};
157inline size_t qHash(const FontAndStyle &key, size_t seed) noexcept
158{
159 return qHashMulti(seed, key.font, key.style);
160}
161
162QT_END_NAMESPACE
163
164#endif // QWINDOWSFONTDATABASE_H
Font database for Windows.
Combined button and popup list for selecting options.
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