Qt 4.8
qfontmetrics.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QFONTMETRICS_H
43 #define QFONTMETRICS_H
44 
45 #include <QtGui/qfont.h>
46 #include <QtCore/qsharedpointer.h>
47 #ifndef QT_INCLUDE_COMPAT
48 #include <QtCore/qrect.h>
49 #endif
50 
52 
54 
55 QT_MODULE(Gui)
56 
57 #ifdef Q_WS_QWS
58 class QFontEngine;
59 #endif
60 
61 class QTextCodec;
62 class QRect;
63 
64 
66 {
67 public:
68  QFontMetrics(const QFont &);
69  QFontMetrics(const QFont &, QPaintDevice *pd);
70  QFontMetrics(const QFontMetrics &);
71  ~QFontMetrics();
72 
73  QFontMetrics &operator=(const QFontMetrics &);
74 #ifdef Q_COMPILER_RVALUE_REFS
75  inline QFontMetrics &operator=(QFontMetrics &&other)
76  { qSwap(d, other.d); return *this; }
77 #endif
78 
79  int ascent() const;
80  int descent() const;
81  int height() const;
82  int leading() const;
83  int lineSpacing() const;
84  int minLeftBearing() const;
85  int minRightBearing() const;
86  int maxWidth() const;
87 
88  int xHeight() const;
89  int averageCharWidth() const;
90 
91  bool inFont(QChar) const;
92  bool inFontUcs4(uint ucs4) const;
93 
94  int leftBearing(QChar) const;
95  int rightBearing(QChar) const;
96  int width(const QString &, int len = -1) const;
97  int width(const QString &, int len, int flags) const;
98 
99  int width(QChar) const;
100  int charWidth(const QString &str, int pos) const;
101 
102  QRect boundingRect(QChar) const;
103 
104  QRect boundingRect(const QString &text) const;
105  QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const;
106  inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
107  int tabstops=0, int *tabarray=0) const
108  { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
109  QSize size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
110 
111  QRect tightBoundingRect(const QString &text) const;
112 
113  QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
114 
115  int underlinePos() const;
116  int overlinePos() const;
117  int strikeOutPos() const;
118  int lineWidth() const;
119 
120  bool operator==(const QFontMetrics &other); // 5.0 - remove me
121  bool operator==(const QFontMetrics &other) const;
122  inline bool operator !=(const QFontMetrics &other) { return !operator==(other); } // 5.0 - remove me
123  inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
124 
125 #ifdef QT3_SUPPORT
126  inline QRect boundingRect(const QString &text, int len) const
127  { return boundingRect(text.left(len)); }
128  inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString& str, int len,
129  int tabstops=0, int *tabarray=0) const
130  { return boundingRect(QRect(x, y, w, h), flags, str.left(len), tabstops, tabarray); }
131  inline QSize size(int flags, const QString& str, int len, int tabstops=0, int *tabarray=0) const
132  { return size(flags, str.left(len), tabstops, tabarray); }
133 #endif
134 private:
135 #if defined(Q_WS_MAC)
136  friend class QFontPrivate;
137 #endif
138  friend class QFontMetricsF;
139  friend class QStackTextEngine;
140 
142 };
143 
144 
146 {
147 public:
148  QFontMetricsF(const QFont &);
149  QFontMetricsF(const QFont &, QPaintDevice *pd);
150  QFontMetricsF(const QFontMetrics &);
151  QFontMetricsF(const QFontMetricsF &);
152  ~QFontMetricsF();
153 
154  QFontMetricsF &operator=(const QFontMetricsF &);
155  QFontMetricsF &operator=(const QFontMetrics &);
156 #ifdef Q_COMPILER_RVALUE_REFS
157  inline QFontMetricsF &operator=(QFontMetricsF &&other)
158  { qSwap(d, other.d); return *this; }
159 #endif
160  qreal ascent() const;
161  qreal descent() const;
162  qreal height() const;
163  qreal leading() const;
164  qreal lineSpacing() const;
165  qreal minLeftBearing() const;
166  qreal minRightBearing() const;
167  qreal maxWidth() const;
168 
169  qreal xHeight() const;
170  qreal averageCharWidth() const;
171 
172  bool inFont(QChar) const;
173  bool inFontUcs4(uint ucs4) const;
174 
175  qreal leftBearing(QChar) const;
176  qreal rightBearing(QChar) const;
177  qreal width(const QString &string) const;
178 
179  qreal width(QChar) const;
180 
181  QRectF boundingRect(const QString &string) const;
182  QRectF boundingRect(QChar) const;
183  QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
184  QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
185 
186  QRectF tightBoundingRect(const QString &text) const;
187 
188  QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
189 
190  qreal underlinePos() const;
191  qreal overlinePos() const;
192  qreal strikeOutPos() const;
193  qreal lineWidth() const;
194 
195  bool operator==(const QFontMetricsF &other); // 5.0 - remove me
196  bool operator==(const QFontMetricsF &other) const;
197  inline bool operator !=(const QFontMetricsF &other) { return !operator==(other); } // 5.0 - remove me
198  inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
199 
200 private:
202 };
203 
205 
207 
208 #endif // QFONTMETRICS_H
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontmetrics.h:201
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
TextElideMode
Definition: qnamespace.h:263
bool operator!=(QBool b1, bool b2)
Definition: qglobal.h:2026
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text, int tabstops=0, int *tabarray=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qfontmetrics.h:106
static const QRectF boundingRect(const QPointF *points, int pointCount)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
unsigned int uint
Definition: qglobal.h:996
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QTextCodec class provides conversions between text encodings.
Definition: qtextcodec.h:62
#define QT_END_HEADER
Definition: qglobal.h:137
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
QExplicitlySharedDataPointer< QFontPrivate > d
Definition: qfontmetrics.h:141
#define text
Definition: qobjectdefs.h:80