1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #ifndef QFONTMETRICS_H
43 #define QFONTMETRICS_H
45 #include <QtGui/qfont.h>
46 #include <QtCore/qsharedpointer.h>
47 #ifndef QT_INCLUDE_COMPAT
48 #include <QtCore/qrect.h>
61 class Q_GUI_EXPORT QFontMetrics
64 explicit QFontMetrics(const QFont &);
65 QFontMetrics(const QFont &, QPaintDevice *pd);
66 QFontMetrics(const QFontMetrics &);
69 QFontMetrics &operator=(const QFontMetrics &);
70 #ifdef Q_COMPILER_RVALUE_REFS
71 inline QFontMetrics &operator=(QFontMetrics &&other)
72 { qSwap(d, other.d); return *this; }
75 void swap(QFontMetrics &other) { qSwap(d, other.d); }
81 int lineSpacing() const;
82 int minLeftBearing() const;
83 int minRightBearing() const;
87 int averageCharWidth() const;
89 bool inFont(QChar) const;
90 bool inFontUcs4(uint ucs4) const;
92 int leftBearing(QChar) const;
93 int rightBearing(QChar) const;
94 int width(const QString &, int len = -1) const;
95 int width(const QString &, int len, int flags) const;
97 int width(QChar) const;
98 int charWidth(const QString &str, int pos) const;
100 QRect boundingRect(QChar) const;
102 QRect boundingRect(const QString &text) const;
103 QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const;
104 inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
105 int tabstops=0, int *tabarray=0) const
106 { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
107 QSize size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
109 QRect tightBoundingRect(const QString &text) const;
111 QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
113 int underlinePos() const;
114 int overlinePos() const;
115 int strikeOutPos() const;
116 int lineWidth() const;
118 bool operator==(const QFontMetrics &other) const;
119 inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
122 friend class QFontMetricsF;
123 friend class QStackTextEngine;
125 QExplicitlySharedDataPointer<QFontPrivate> d;
128 Q_DECLARE_SHARED(QFontMetrics)
130 class Q_GUI_EXPORT QFontMetricsF
133 explicit QFontMetricsF(const QFont &);
134 QFontMetricsF(const QFont &, QPaintDevice *pd);
135 QFontMetricsF(const QFontMetrics &);
136 QFontMetricsF(const QFontMetricsF &);
139 QFontMetricsF &operator=(const QFontMetricsF &);
140 QFontMetricsF &operator=(const QFontMetrics &);
141 #ifdef Q_COMPILER_RVALUE_REFS
142 inline QFontMetricsF &operator=(QFontMetricsF &&other)
143 { qSwap(d, other.d); return *this; }
146 void swap(QFontMetricsF &other) { qSwap(d, other.d); }
148 qreal ascent() const;
149 qreal descent() const;
150 qreal height() const;
151 qreal leading() const;
152 qreal lineSpacing() const;
153 qreal minLeftBearing() const;
154 qreal minRightBearing() const;
155 qreal maxWidth() const;
157 qreal xHeight() const;
158 qreal averageCharWidth() const;
160 bool inFont(QChar) const;
161 bool inFontUcs4(uint ucs4) const;
163 qreal leftBearing(QChar) const;
164 qreal rightBearing(QChar) const;
165 qreal width(const QString &string) const;
167 qreal width(QChar) const;
169 QRectF boundingRect(const QString &string) const;
170 QRectF boundingRect(QChar) const;
171 QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
172 QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
174 QRectF tightBoundingRect(const QString &text) const;
176 QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
178 qreal underlinePos() const;
179 qreal overlinePos() const;
180 qreal strikeOutPos() const;
181 qreal lineWidth() const;
183 bool operator==(const QFontMetricsF &other) const;
184 inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
187 QExplicitlySharedDataPointer<QFontPrivate> d;
190 Q_DECLARE_SHARED(QFontMetricsF)
196 #endif // QFONTMETRICS_H