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 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRawFont)
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 QList<quint32> glyphIndexesForString(const QString &text) const;
101 inline QList<QPointF> advancesForGlyphIndexes(const QList<quint32> &glyphIndexes) const;
102 inline QList<QPointF> advancesForGlyphIndexes(const QList<quint32> &glyphIndexes,
103 LayoutFlags layoutFlags) const;
104 bool glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const;
105 bool advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const;
106 bool advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs, LayoutFlags layoutFlags) const;
107
108 QImage alphaMapForGlyph(quint32 glyphIndex,
109 AntialiasingType antialiasingType = SubPixelAntialiasing,
110 const QTransform &transform = QTransform()) const;
111 QPainterPath pathForGlyph(quint32 glyphIndex) const;
112 QRectF boundingRect(quint32 glyphIndex) const;
113
114 void setPixelSize(qreal pixelSize);
115 qreal pixelSize() const;
116
117 QFont::HintingPreference hintingPreference() const;
118
119 qreal ascent() const;
120 qreal capHeight() const;
121 qreal descent() const;
122 qreal leading() const;
123 qreal xHeight() const;
124 qreal averageCharWidth() const;
125 qreal maxCharWidth() const;
126 qreal lineThickness() const;
127 qreal underlinePosition() const;
128
129 qreal unitsPerEm() const;
130
131 void loadFromFile(const QString &fileName,
132 qreal pixelSize,
133 QFont::HintingPreference hintingPreference);
134
135 void loadFromData(const QByteArray &fontData,
136 qreal pixelSize,
137 QFont::HintingPreference hintingPreference);
138
139 bool supportsCharacter(uint ucs4) const;
140 bool supportsCharacter(QChar character) const;
141 QList<QFontDatabase::WritingSystem> supportedWritingSystems() const;
142
143 QByteArray fontTable(const char *tagName) const;
144
145 static QRawFont fromFont(const QFont &font,
146 QFontDatabase::WritingSystem writingSystem = QFontDatabase::Any);
147
148private:
149 friend class QRawFontPrivate;
150 friend class QTextLayout;
151 friend class QTextEngine;
152
153 QExplicitlySharedDataPointer<QRawFontPrivate> d;
154};
155
156Q_DECLARE_SHARED(QRawFont)
157
158Q_DECLARE_OPERATORS_FOR_FLAGS(QRawFont::LayoutFlags)
159
160Q_GUI_EXPORT size_t qHash(const QRawFont &font, size_t seed = 0) noexcept;
161
162inline QList<QPointF> QRawFont::advancesForGlyphIndexes(const QList<quint32> &glyphIndexes,
163 QRawFont::LayoutFlags layoutFlags) const
164{
165 QList<QPointF> advances(glyphIndexes.size());
166 if (advancesForGlyphIndexes(glyphIndexes.constData(), advances.data(), glyphIndexes.size(), layoutFlags))
167 return advances;
168 return QList<QPointF>();
169}
170
171inline QList<QPointF> QRawFont::advancesForGlyphIndexes(const QList<quint32> &glyphIndexes) const
172{
173 return advancesForGlyphIndexes(glyphIndexes, QRawFont::SeparateAdvances);
174}
175
176QT_END_NAMESPACE
177
178#endif // QT_NO_RAWFONT
179
180#endif // QRAWFONT_H
181