source: trunk/src/gui/text/qfontmetrics.h@ 605

Last change on this file since 605 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 6.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
51QT_BEGIN_HEADER
52
53QT_BEGIN_NAMESPACE
54
55QT_MODULE(Gui)
56
57#ifdef Q_WS_QWS
58class QFontEngine;
59#endif
60
61class QTextCodec;
62class QRect;
63
64
65class Q_GUI_EXPORT QFontMetrics
66{
67public:
68 QFontMetrics(const QFont &);
69 QFontMetrics(const QFont &, QPaintDevice *pd);
70 QFontMetrics(const QFontMetrics &);
71 ~QFontMetrics();
72
73 QFontMetrics &operator=(const QFontMetrics &);
74
75 int ascent() const;
76 int descent() const;
77 int height() const;
78 int leading() const;
79 int lineSpacing() const;
80 int minLeftBearing() const;
81 int minRightBearing() const;
82 int maxWidth() const;
83
84 int xHeight() const;
85 int averageCharWidth() const;
86
87 bool inFont(QChar) const;
88
89 int leftBearing(QChar) const;
90 int rightBearing(QChar) const;
91 int width(const QString &, int len = -1) const;
92
93 int width(QChar) const;
94 int charWidth(const QString &str, int pos) const;
95
96 QRect boundingRect(QChar) const;
97
98 QRect boundingRect(const QString &text) const;
99 QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops=0, int *tabarray=0) const;
100 inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
101 int tabstops=0, int *tabarray=0) const
102 { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
103 QSize size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
104
105 QRect tightBoundingRect(const QString &text) const;
106
107 QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
108
109 int underlinePos() const;
110 int overlinePos() const;
111 int strikeOutPos() const;
112 int lineWidth() const;
113
114 bool operator==(const QFontMetrics &other); // 5.0 - remove me
115 bool operator==(const QFontMetrics &other) const;
116 inline bool operator !=(const QFontMetrics &other) { return !operator==(other); } // 5.0 - remove me
117 inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
118
119#ifdef QT3_SUPPORT
120 inline QRect boundingRect(const QString &text, int len) const
121 { return boundingRect(text.left(len)); }
122 inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString& str, int len,
123 int tabstops=0, int *tabarray=0) const
124 { return boundingRect(QRect(x, y, w, h), flags, str.left(len), tabstops, tabarray); }
125 inline QSize size(int flags, const QString& str, int len, int tabstops=0, int *tabarray=0) const
126 { return size(flags, str.left(len), tabstops, tabarray); }
127#endif
128private:
129#if defined(Q_WS_MAC)
130 friend class QFontPrivate;
131#endif
132 friend class QFontMetricsF;
133 friend class QStackTextEngine;
134
135 QExplicitlySharedDataPointer<QFontPrivate> d;
136};
137
138
139class Q_GUI_EXPORT QFontMetricsF
140{
141public:
142 QFontMetricsF(const QFont &);
143 QFontMetricsF(const QFont &, QPaintDevice *pd);
144 QFontMetricsF(const QFontMetrics &);
145 QFontMetricsF(const QFontMetricsF &);
146 ~QFontMetricsF();
147
148 QFontMetricsF &operator=(const QFontMetricsF &);
149 QFontMetricsF &operator=(const QFontMetrics &);
150
151 qreal ascent() const;
152 qreal descent() const;
153 qreal height() const;
154 qreal leading() const;
155 qreal lineSpacing() const;
156 qreal minLeftBearing() const;
157 qreal minRightBearing() const;
158 qreal maxWidth() const;
159
160 qreal xHeight() const;
161 qreal averageCharWidth() const;
162
163 bool inFont(QChar) const;
164
165 qreal leftBearing(QChar) const;
166 qreal rightBearing(QChar) const;
167 qreal width(const QString &string) const;
168
169 qreal width(QChar) const;
170
171 QRectF boundingRect(const QString &string) const;
172 QRectF boundingRect(QChar) const;
173 QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
174 QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
175
176 QRectF tightBoundingRect(const QString &text) const;
177
178 QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
179
180 qreal underlinePos() const;
181 qreal overlinePos() const;
182 qreal strikeOutPos() const;
183 qreal lineWidth() const;
184
185 bool operator==(const QFontMetricsF &other); // 5.0 - remove me
186 bool operator==(const QFontMetricsF &other) const;
187 inline bool operator !=(const QFontMetricsF &other) { return !operator==(other); } // 5.0 - remove me
188 inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
189
190private:
191 QExplicitlySharedDataPointer<QFontPrivate> d;
192};
193
194QT_END_NAMESPACE
195
196QT_END_HEADER
197
198#endif // QFONTMETRICS_H
Note: See TracBrowser for help on using the repository browser.