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 QWINDOWSFONTENGINE_H 41 #define QWINDOWSFONTENGINE_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 <QtGui/private/qfontengine_p.h> 55 56 #include <QtGui/QImage> 57 #include <QtCore/QSharedPointer> 58 #include <QtCore/QMetaType> 59 60 #include <QtCore/qt_windows.h> 61 62 QT_BEGIN_NAMESPACE 63 64 class QWindowsNativeImage; 65 class QWindowsFontEngineData; 66 67 class QWindowsFontEngine : public QFontEngine 68 { 69 Q_DISABLE_COPY_MOVE(QWindowsFontEngine) 70 public: 71 QWindowsFontEngine(const QString &name, LOGFONT lf, 72 const QSharedPointer<QWindowsFontEngineData> &fontEngineData); 73 74 ~QWindowsFontEngine() override; 75 void initFontInfo(const QFontDef &request, 76 int dpi); 77 78 QFixed lineThickness() const override; 79 Properties properties() const override; 80 void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) override; 81 FaceId faceId() const override; 82 bool getSfntTableData(uint tag, uchar *buffer, uint *length) const override; 83 int synthesized() const override; 84 QFixed emSquareSize() const override; 85 86 glyph_t glyphIndex(uint ucs4) const override; 87 bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const override; 88 void recalcAdvances(QGlyphLayout *glyphs, ShaperFlags) const override; 89 90 void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) override; 91 void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs, 92 QPainterPath *path, QTextItem::RenderFlags flags) override; 93 94 HGDIOBJ selectDesignFont() const; 95 96 glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) override; boundingBox(glyph_t g)97 glyph_metrics_t boundingBox(glyph_t g) override { return boundingBox(g, QTransform()); } 98 glyph_metrics_t boundingBox(glyph_t g, const QTransform &t) override; 99 100 101 QFixed ascent() const override; 102 QFixed descent() const override; 103 QFixed leading() const override; 104 QFixed xHeight() const override; 105 QFixed capHeight() const override; 106 QFixed averageCharWidth() const override; 107 qreal maxCharWidth() const override; 108 qreal minLeftBearing() const override; 109 qreal minRightBearing() const override; 110 alphaMapForGlyph(glyph_t t)111 QImage alphaMapForGlyph(glyph_t t) override { return alphaMapForGlyph(t, QTransform()); } 112 QImage alphaMapForGlyph(glyph_t, const QTransform &xform) override; 113 QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform) override; 114 glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, QFixed, const QTransform &matrix, GlyphFormat) override; 115 116 QFontEngine *cloneWithSize(qreal pixelSize) const override; 117 Qt::HANDLE handle() const override; 118 bool supportsTransformation(const QTransform &transform) const override; 119 120 #ifndef Q_CC_MINGW 121 void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0) override; 122 #endif 123 124 bool hasUnreliableGlyphOutline() const override; 125 126 int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs) const; 127 void getCMap(); 128 129 bool getOutlineMetrics(glyph_t glyph, const QTransform &t, glyph_metrics_t *metrics) const; 130 fontEngineData()131 const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; } 132 setUniqueFamilyName(const QString & newName)133 void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; } 134 135 private: 136 QWindowsNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform, 137 QImage::Format mask_format); 138 bool hasCFFTable() const; 139 bool hasCMapTable() const; 140 141 const QSharedPointer<QWindowsFontEngineData> m_fontEngineData; 142 143 const QString _name; 144 QString uniqueFamilyName; 145 HFONT hfont = 0; 146 const LOGFONT m_logfont; 147 uint ttf : 1; 148 uint hasOutline : 1; 149 uint hasUnreliableOutline : 1; 150 uint cffTable : 1; 151 TEXTMETRIC tm; 152 const unsigned char *cmap = nullptr; 153 int cmapSize = 0; 154 QByteArray cmapTable; 155 mutable qreal lbearing = SHRT_MIN; 156 mutable qreal rbearing = SHRT_MIN; 157 QFixed designToDevice; 158 int unitsPerEm = 0; 159 QFixed x_height = -1; 160 FaceId _faceId; 161 162 mutable int synthesized_flags = -1; 163 mutable QFixed lineWidth = -1; 164 mutable unsigned char *widthCache = nullptr; 165 mutable uint widthCacheSize = 0; 166 mutable QFixed *designAdvances = nullptr; 167 mutable int designAdvancesSize = 0; 168 }; 169 170 QT_END_NAMESPACE 171 172 Q_DECLARE_METATYPE(HFONT) 173 Q_DECLARE_METATYPE(LOGFONT) 174 175 #endif // QWINDOWSFONTENGINE_H 176