1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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; }
79 int lineSpacing() const;
80 int minLeftBearing() const;
81 int minRightBearing() const;
85 int averageCharWidth() const;
87 bool inFont(QChar) const;
88 bool inFontUcs4(uint ucs4) const;
90 int leftBearing(QChar) const;
91 int rightBearing(QChar) const;
92 int width(const QString &, int len = -1) const;
93 int width(const QString &, int len, int flags) const;
95 int width(QChar) const;
96 int charWidth(const QString &str, int pos) const;
98 QRect boundingRect(QChar) const;
100 QRect boundingRect(const QString &text) const;
101 QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const;
102 inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
103 int tabstops=0, int *tabarray=0) const
104 { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
105 QSize size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
107 QRect tightBoundingRect(const QString &text) const;
109 QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
111 int underlinePos() const;
112 int overlinePos() const;
113 int strikeOutPos() const;
114 int lineWidth() const;
116 bool operator==(const QFontMetrics &other) const;
117 inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
120 friend class QFontMetricsF;
121 friend class QStackTextEngine;
123 QExplicitlySharedDataPointer<QFontPrivate> d;
127 class Q_GUI_EXPORT QFontMetricsF
130 explicit QFontMetricsF(const QFont &);
131 QFontMetricsF(const QFont &, QPaintDevice *pd);
132 QFontMetricsF(const QFontMetrics &);
133 QFontMetricsF(const QFontMetricsF &);
136 QFontMetricsF &operator=(const QFontMetricsF &);
137 QFontMetricsF &operator=(const QFontMetrics &);
138 #ifdef Q_COMPILER_RVALUE_REFS
139 inline QFontMetricsF &operator=(QFontMetricsF &&other)
140 { qSwap(d, other.d); return *this; }
142 qreal ascent() const;
143 qreal descent() const;
144 qreal height() const;
145 qreal leading() const;
146 qreal lineSpacing() const;
147 qreal minLeftBearing() const;
148 qreal minRightBearing() const;
149 qreal maxWidth() const;
151 qreal xHeight() const;
152 qreal averageCharWidth() const;
154 bool inFont(QChar) const;
155 bool inFontUcs4(uint ucs4) const;
157 qreal leftBearing(QChar) const;
158 qreal rightBearing(QChar) const;
159 qreal width(const QString &string) const;
161 qreal width(QChar) const;
163 QRectF boundingRect(const QString &string) const;
164 QRectF boundingRect(QChar) const;
165 QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
166 QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
168 QRectF tightBoundingRect(const QString &text) const;
170 QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
172 qreal underlinePos() const;
173 qreal overlinePos() const;
174 qreal strikeOutPos() const;
175 qreal lineWidth() const;
177 bool operator==(const QFontMetricsF &other) const;
178 inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
181 QExplicitlySharedDataPointer<QFontPrivate> d;
188 #endif // QFONTMETRICS_H