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