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 QFONTMETRICS_H
41#define QFONTMETRICS_H
42
43#include <QtGui/qtguiglobal.h>
44#include <QtGui/qfont.h>
45#include <QtCore/qsharedpointer.h>
46#ifndef QT_INCLUDE_COMPAT
47#include <QtCore/qrect.h>
48#endif
49
50QT_BEGIN_NAMESPACE
51
52class QRect;
53
54class Q_GUI_EXPORT QFontMetrics
55{
56public:
57 explicit QFontMetrics(const QFont &);
58 QFontMetrics(const QFont &font, const QPaintDevice *pd);
59 QFontMetrics(const QFontMetrics &);
60 ~QFontMetrics();
61
62 QFontMetrics &operator=(const QFontMetrics &);
63 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetrics)
64
65 void swap(QFontMetrics &other) noexcept
66 { qSwap(d, other.d); }
67
68 int ascent() const;
69 int capHeight() const;
70 int descent() const;
71 int height() const;
72 int leading() const;
73 int lineSpacing() const;
74 int minLeftBearing() const;
75 int minRightBearing() const;
76 int maxWidth() const;
77
78 int xHeight() const;
79 int averageCharWidth() const;
80
81 bool inFont(QChar) const;
82 bool inFontUcs4(uint ucs4) const;
83
84 int leftBearing(QChar) const;
85 int rightBearing(QChar) const;
86
87 int horizontalAdvance(const QString &, int len = -1) const;
88 int horizontalAdvance(QChar) const;
89
90 QRect boundingRect(QChar) const;
91
92 QRect boundingRect(const QString &text) const;
93 QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops = 0, int *tabarray = nullptr) const;
94 inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
95 int tabstops = 0, int *tabarray = nullptr) const
96 { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
97 QSize size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const;
98
99 QRect tightBoundingRect(const QString &text) const;
100
101 QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
102
103 int underlinePos() const;
104 int overlinePos() const;
105 int strikeOutPos() const;
106 int lineWidth() const;
107
108 qreal fontDpi() const;
109
110 bool operator==(const QFontMetrics &other) const;
111 inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
112
113private:
114 friend class QFontMetricsF;
115 friend class QStackTextEngine;
116
117 QExplicitlySharedDataPointer<QFontPrivate> d;
118};
119
120Q_DECLARE_SHARED(QFontMetrics)
121
122class Q_GUI_EXPORT QFontMetricsF
123{
124public:
125 explicit QFontMetricsF(const QFont &font);
126 QFontMetricsF(const QFont &font, const QPaintDevice *pd);
127 QFontMetricsF(const QFontMetrics &);
128 QFontMetricsF(const QFontMetricsF &);
129 ~QFontMetricsF();
130
131 QFontMetricsF &operator=(const QFontMetricsF &);
132 QFontMetricsF &operator=(const QFontMetrics &);
133 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetricsF)
134
135 void swap(QFontMetricsF &other) noexcept { qSwap(d, other.d); }
136
137 qreal ascent() const;
138 qreal capHeight() const;
139 qreal descent() const;
140 qreal height() const;
141 qreal leading() const;
142 qreal lineSpacing() const;
143 qreal minLeftBearing() const;
144 qreal minRightBearing() const;
145 qreal maxWidth() const;
146
147 qreal xHeight() const;
148 qreal averageCharWidth() const;
149
150 bool inFont(QChar) const;
151 bool inFontUcs4(uint ucs4) const;
152
153 qreal leftBearing(QChar) const;
154 qreal rightBearing(QChar) const;
155
156 qreal horizontalAdvance(const QString &string, int length = -1) const;
157 qreal horizontalAdvance(QChar) const;
158
159 QRectF boundingRect(const QString &string) const;
160 QRectF boundingRect(QChar) const;
161 QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops = 0, int *tabarray = nullptr) const;
162 QSizeF size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const;
163
164 QRectF tightBoundingRect(const QString &text) const;
165
166 QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
167
168 qreal underlinePos() const;
169 qreal overlinePos() const;
170 qreal strikeOutPos() const;
171 qreal lineWidth() const;
172
173 qreal fontDpi() const;
174
175 bool operator==(const QFontMetricsF &other) const;
176 inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
177
178private:
179 QExplicitlySharedDataPointer<QFontPrivate> d;
180};
181
182Q_DECLARE_SHARED(QFontMetricsF)
183
184QT_END_NAMESPACE
185
186#endif // QFONTMETRICS_H
187