1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QWINDOWSFONTENGINEDIRECTWRITE_H
41 #define QWINDOWSFONTENGINEDIRECTWRITE_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists purely as an
48 // implementation detail.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtCore/qglobal.h>
55 
56 #ifndef QT_NO_DIRECTWRITE
57 
58 #include <QtGui/private/qfontengine_p.h>
59 #include <QtCore/QSharedPointer>
60 
61 struct IDWriteFont;
62 struct IDWriteFontFace;
63 struct IDWriteFontFile;
64 struct IDWriteFactory;
65 struct IDWriteBitmapRenderTarget;
66 struct IDWriteGdiInterop;
67 struct IDWriteGlyphRunAnalysis;
68 
69 QT_BEGIN_NAMESPACE
70 
71 class QWindowsFontEngineData;
72 
73 class QWindowsFontEngineDirectWrite : public QFontEngine
74 {
75     Q_DISABLE_COPY_MOVE(QWindowsFontEngineDirectWrite)
76 public:
77     explicit QWindowsFontEngineDirectWrite(IDWriteFontFace *directWriteFontFace,
78                                     qreal pixelSize,
79                                     const QSharedPointer<QWindowsFontEngineData> &d);
80     ~QWindowsFontEngineDirectWrite() override;
81 
82     void initFontInfo(const QFontDef &request, int dpi);
83 
84     QFixed lineThickness() const override;
85     QFixed underlinePosition() const override;
86     bool getSfntTableData(uint tag, uchar *buffer, uint *length) const override;
87     QFixed emSquareSize() const override;
88 
89     glyph_t glyphIndex(uint ucs4) const override;
90     bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
91                       ShaperFlags flags) const override;
92     void recalcAdvances(QGlyphLayout *glyphs, ShaperFlags) const override;
93 
94     void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
95                          QPainterPath *path, QTextItem::RenderFlags flags) override;
96 
97     glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) override;
98     glyph_metrics_t boundingBox(glyph_t g) override;
99     glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed,
100                                         const QTransform &matrix, GlyphFormat) override;
101 
102     QFixed ascent() const override;
103     QFixed capHeight() const override;
104     QFixed descent() const override;
105     QFixed leading() const override;
106     QFixed xHeight() const override;
107     qreal maxCharWidth() const override;
108     FaceId faceId() const override;
109 
110     bool supportsSubPixelPositions() const override;
111 
112     QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition) override;
113     QImage alphaMapForGlyph(glyph_t glyph, QFixed subPixelPosition, const QTransform &t) override;
114     QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform) override;
115     QImage bitmapForGlyph(glyph_t, QFixed subPixelPosition, const QTransform &t, const QColor &color) override;
116 
117     QFontEngine *cloneWithSize(qreal pixelSize) const override;
118     Qt::HANDLE handle() const override;
119 
fontEngineData()120     const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; }
121 
122     static QString fontNameSubstitute(const QString &familyName);
123 
directWriteFontFace()124     IDWriteFontFace *directWriteFontFace() const { return m_directWriteFontFace; }
125 
setUniqueFamilyName(const QString & newName)126     void setUniqueFamilyName(const QString &newName) { m_uniqueFamilyName = newName; }
127 
128 private:
129     QImage imageForGlyph(glyph_t t, QFixed subPixelPosition, int margin, const QTransform &xform, const QColor &color = QColor());
130     void collectMetrics();
131     void renderGlyphRun(QImage *destination, float r, float g, float b, float a, IDWriteGlyphRunAnalysis *glyphAnalysis, const QRect &boundingRect);
132     static QString filenameFromFontFile(IDWriteFontFile *fontFile);
133 
134     const QSharedPointer<QWindowsFontEngineData> m_fontEngineData;
135 
136     IDWriteFontFace *m_directWriteFontFace;
137     IDWriteBitmapRenderTarget *m_directWriteBitmapRenderTarget;
138 
139     QFixed m_lineThickness;
140     QFixed m_underlinePosition;
141     int m_unitsPerEm;
142     QFixed m_ascent;
143     QFixed m_capHeight;
144     QFixed m_descent;
145     QFixed m_xHeight;
146     QFixed m_lineGap;
147     QFixed m_maxAdvanceWidth;
148     FaceId m_faceId;
149     QString m_uniqueFamilyName;
150 };
151 
152 QT_END_NAMESPACE
153 
154 #endif // QT_NO_DIRECTWRITE
155 
156 #endif // QWINDOWSFONTENGINEDIRECTWRITE_H
157