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
qwindowsfontenginedirectwrite_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 QWINDOWSFONTENGINEDIRECTWRITE_H
5#define QWINDOWSFONTENGINEDIRECTWRITE_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
18#include <QtGui/qtguiglobal.h>
19#include <QtGui/private/qtgui-config_p.h>
20
22
23#include <QtGui/private/qfontengine_p.h>
24#include <QtCore/QSharedPointer>
25
26#include <dwrite_2.h>
27
28struct IDWriteFont;
29struct IDWriteFontFace;
30struct IDWriteFontFile;
31struct IDWriteFactory;
32struct IDWriteBitmapRenderTarget;
33struct IDWriteGdiInterop;
34struct IDWriteGlyphRunAnalysis;
35struct IDWriteColorGlyphRunEnumerator;
36
37#if QT_CONFIG(directwritecolrv1)
38struct IDWriteFontFace7;
39struct IDWritePaintReader;
40struct DWRITE_PAINT_ELEMENT;
41#endif
42
43QT_BEGIN_NAMESPACE
44
45class QWindowsFontEngineData;
46class QColrPaintGraphRenderer;
47
48class Q_GUI_EXPORT QWindowsFontEngineDirectWrite : public QFontEngine
49{
50 Q_DISABLE_COPY_MOVE(QWindowsFontEngineDirectWrite)
51public:
52 explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace,
53 qreal pixelSize,
54 const QSharedPointer<QWindowsFontEngineData> &d);
55 ~QWindowsFontEngineDirectWrite() override;
56
57 void initFontInfo(const QFontDef &request, int dpi);
58
59 QFixed lineThickness() const override;
60 QFixed underlinePosition() const override;
61 bool getSfntTableData(uint tag, uchar *buffer, uint *length) const override;
62 QFixed emSquareSize() const override;
63
64 glyph_t glyphIndex(uint ucs4) const override;
65 int stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
66 ShaperFlags flags) const override;
67 void recalcAdvances(QGlyphLayout *glyphs, ShaperFlags) const override;
68
69 void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
70 QPainterPath *path, QTextItem::RenderFlags flags) override;
71
72 glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) override;
73 glyph_metrics_t boundingBox(glyph_t g) override;
74 glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, const QFixedPoint&,
75 const QTransform &matrix, GlyphFormat) override;
76
77 QFixed capHeight() const override;
78 QFixed xHeight() const override;
79 qreal maxCharWidth() const override;
80 FaceId faceId() const override;
81
82 bool supportsHorizontalSubPixelPositions() const override;
83
84 HFONT createHFONT() const;
85
86 QImage alphaMapForGlyph(glyph_t glyph, const QFixedPoint &subPixelPosition) override;
87 QImage alphaMapForGlyph(glyph_t glyph,
88 const QFixedPoint &subPixelPosition,
89 const QTransform &t) override;
90 QImage alphaRGBMapForGlyph(glyph_t t,
91 const QFixedPoint &subPixelPosition,
92 const QTransform &xform) override;
93 QImage bitmapForGlyph(glyph_t,
94 const QFixedPoint &subPixelPosition,
95 const QTransform &t,
96 const QColor &color) override;
97
98 QFontEngine *cloneWithSize(qreal pixelSize) const override;
99 Qt::HANDLE handle() const override;
100
101 const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; }
102
103 static QString fontNameSubstitute(const QString &familyName);
104
105 IDWriteFontFace *directWriteFontFace() const { return m_directWriteFontFace; }
106
107 void setUniqueFamilyName(const QString &newName) { m_uniqueFamilyName = newName; }
108
109 void initializeHeightMetrics() const override;
110
111 Properties properties() const override;
112
113 QPainterPath unscaledGlyph(glyph_t glyph) const;
114 void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) override;
115
116 QList<QFontVariableAxis> variableAxes() const override;
117
118private:
119#if QT_CONFIG(directwritecolrv1)
120 bool traverseColr1(IDWritePaintReader *paintReader,
121 IDWriteFontFace7 *face7,
122 const DWRITE_PAINT_ELEMENT *paintElement,
123 QColrPaintGraphRenderer *graphRenderer) const;
124 bool renderColr1GlyphRun(QImage *image,
125 const DWRITE_GLYPH_RUN *glyphRun,
126 const DWRITE_MATRIX &transform,
127 QColor color) const;
128#endif
129
130 QRect paintGraphBounds(glyph_t glyph, const DWRITE_MATRIX &transform) const;
131 QRect alphaTextureBounds(glyph_t glyph, const DWRITE_MATRIX &transform);
132 QRect colorBitmapBounds(glyph_t glyph, const DWRITE_MATRIX &transform);
133 bool renderColr0GlyphRun(QImage *image,
134 const DWRITE_COLOR_GLYPH_RUN *colorGlyphRun,
135 const DWRITE_MATRIX &transform,
136 DWRITE_RENDERING_MODE renderMode,
137 DWRITE_MEASURING_MODE measureMode,
138 DWRITE_GRID_FIT_MODE gridFitMode,
139 QColor color,
140 QRect boundingRect) const;
141 QImage renderColorGlyph(DWRITE_GLYPH_RUN *glyphRun,
142 const DWRITE_MATRIX &transform,
143 DWRITE_RENDERING_MODE renderMode,
144 DWRITE_MEASURING_MODE measureMode,
145 DWRITE_GRID_FIT_MODE gridFitMode,
146 QColor color,
147 QRect boundingRect) const;
148 QImage imageForGlyph(glyph_t t,
149 const QFixedPoint &subPixelPosition,
150 int margin,
151 const QTransform &xform,
152 const QColor &color = QColor());
153 void collectMetrics();
154 void renderGlyphRun(QImage *destination,
155 float r,
156 float g,
157 float b,
158 float a,
159 IDWriteGlyphRunAnalysis *glyphAnalysis,
160 const QRect &boundingRect,
161 DWRITE_RENDERING_MODE renderMode) const;
162 static QString filenameFromFontFile(IDWriteFontFile *fontFile);
163 DWRITE_RENDERING_MODE hintingPreferenceToRenderingMode(const QFontDef &fontDef) const;
164
165 const QSharedPointer<QWindowsFontEngineData> m_fontEngineData;
166
167 IDWriteFontFace *m_directWriteFontFace;
168 IDWriteBitmapRenderTarget *m_directWriteBitmapRenderTarget;
169
170 QFixed m_lineThickness;
171 QFixed m_underlinePosition;
172 int m_unitsPerEm;
173 QFixed m_capHeight;
174 QFixed m_xHeight;
175 QFixed m_maxAdvanceWidth;
176 FaceId m_faceId;
177 QString m_uniqueFamilyName;
178 QList<QFontVariableAxis> m_variableAxes;
179 DWRITE_PIXEL_GEOMETRY m_pixelGeometry = DWRITE_PIXEL_GEOMETRY_RGB;
180};
181
182QT_END_NAMESPACE
183
184#endif // QWINDOWSFONTENGINEDIRECTWRITE_H
Font database for Windows.
Windows font engine using Direct Write.
QT_REQUIRE_CONFIG(thread)
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