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 QRAWFONT_H
41#define QRAWFONT_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtCore/qstring.h>
45#include <QtCore/qiodevice.h>
46#include <QtCore/qglobal.h>
47#include <QtCore/qobject.h>
48#include <QtCore/qpoint.h>
49#include <QtGui/qfont.h>
50#include <QtGui/qtransform.h>
51#include <QtGui/qfontdatabase.h>
52
53#if !defined(QT_NO_RAWFONT)
54
55QT_BEGIN_NAMESPACE
56
57
58class QRawFontPrivate;
59class Q_GUI_EXPORT QRawFont
60{
61public:
62 enum AntialiasingType {
63 PixelAntialiasing,
64 SubPixelAntialiasing
65 };
66
67 enum LayoutFlag {
68 SeparateAdvances = 0,
69 KernedAdvances = 1,
70 UseDesignMetrics = 2
71 };
72 Q_DECLARE_FLAGS(LayoutFlags, LayoutFlag)
73
74 QRawFont();
75 QRawFont(const QString &fileName,
76 qreal pixelSize,
77 QFont::HintingPreference hintingPreference = QFont::PreferDefaultHinting);
78 QRawFont(const QByteArray &fontData,
79 qreal pixelSize,
80 QFont::HintingPreference hintingPreference = QFont::PreferDefaultHinting);
81 QRawFont(const QRawFont &other);
82 QRawFont &operator=(QRawFont &&other) noexcept { swap(other); return *this; }
83 QRawFont &operator=(const QRawFont &other);
84 ~QRawFont();
85
86 void swap(QRawFont &other) noexcept { qSwap(d, other.d); }
87
88 bool isValid() const;
89
90 bool operator==(const QRawFont &other) const;
91 inline bool operator!=(const QRawFont &other) const
92 { return !operator==(other); }
93
94 QString familyName() const;
95 QString styleName() const;
96
97 QFont::Style style() const;
98 int weight() const;
99
100 QVector<quint32> glyphIndexesForString(const QString &text) const;
101 inline QVector<QPointF> advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const;
102 inline QVector<QPointF> advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes, LayoutFlags layoutFlags) const;
103 bool glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const;
104 bool advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const;
105 bool advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs, LayoutFlags layoutFlags) const;
106
107 QImage alphaMapForGlyph(quint32 glyphIndex,
108 AntialiasingType antialiasingType = SubPixelAntialiasing,
109 const QTransform &transform = QTransform()) const;
110 QPainterPath pathForGlyph(quint32 glyphIndex) const;
111 QRectF boundingRect(quint32 glyphIndex) const;
112
113 void setPixelSize(qreal pixelSize);
114 qreal pixelSize() const;
115
116 QFont::HintingPreference hintingPreference() const;
117
118 qreal ascent() const;
119 qreal capHeight() const;
120 qreal descent() const;
121 qreal leading() const;
122 qreal xHeight() const;
123 qreal averageCharWidth() const;
124 qreal maxCharWidth() const;
125 qreal lineThickness() const;
126 qreal underlinePosition() const;
127
128 qreal unitsPerEm() const;
129
130 void loadFromFile(const QString &fileName,
131 qreal pixelSize,
132 QFont::HintingPreference hintingPreference);
133
134 void loadFromData(const QByteArray &fontData,
135 qreal pixelSize,
136 QFont::HintingPreference hintingPreference);
137
138 bool supportsCharacter(uint ucs4) const;
139 bool supportsCharacter(QChar character) const;
140 QList<QFontDatabase::WritingSystem> supportedWritingSystems() const;
141
142 QByteArray fontTable(const char *tagName) const;
143
144 static QRawFont fromFont(const QFont &font,
145 QFontDatabase::WritingSystem writingSystem = QFontDatabase::Any);
146
147private:
148 friend class QRawFontPrivate;
149 friend class QTextLayout;
150 friend class QTextEngine;
151
152 QExplicitlySharedDataPointer<QRawFontPrivate> d;
153};
154
155Q_DECLARE_SHARED(QRawFont)
156
157Q_DECLARE_OPERATORS_FOR_FLAGS(QRawFont::LayoutFlags)
158
159Q_GUI_EXPORT uint qHash(const QRawFont &font, uint seed = 0) noexcept;
160
161inline QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes, QRawFont::LayoutFlags layoutFlags) const
162{
163 QVector<QPointF> advances(glyphIndexes.size());
164 if (advancesForGlyphIndexes(glyphIndexes.constData(), advances.data(), glyphIndexes.size(), layoutFlags))
165 return advances;
166 return QVector<QPointF>();
167}
168
169inline QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const
170{
171 return advancesForGlyphIndexes(glyphIndexes, QRawFont::SeparateAdvances);
172}
173
174QT_END_NAMESPACE
175
176#endif // QT_NO_RAWFONT
177
178#endif // QRAWFONT_H
179