Export QTextImageHandler and add accessor for image
[profile/ivi/qtbase.git] / src / gui / text / qfontmetrics.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
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
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
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
65 class Q_GUI_EXPORT QFontMetrics
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) const;
121     inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
122
123 private:
124 #if defined(Q_WS_MAC)
125     friend class QFontPrivate;
126 #endif
127     friend class QFontMetricsF;
128     friend class QStackTextEngine;
129
130     QExplicitlySharedDataPointer<QFontPrivate> d;
131 };
132
133
134 class Q_GUI_EXPORT QFontMetricsF
135 {
136 public:
137     QFontMetricsF(const QFont &);
138     QFontMetricsF(const QFont &, QPaintDevice *pd);
139     QFontMetricsF(const QFontMetrics &);
140     QFontMetricsF(const QFontMetricsF &);
141     ~QFontMetricsF();
142
143     QFontMetricsF &operator=(const QFontMetricsF &);
144     QFontMetricsF &operator=(const QFontMetrics &);
145 #ifdef Q_COMPILER_RVALUE_REFS
146     inline QFontMetricsF &operator=(QFontMetricsF &&other)
147     { qSwap(d, other.d); return *this; }
148 #endif
149     qreal ascent() const;
150     qreal descent() const;
151     qreal height() const;
152     qreal leading() const;
153     qreal lineSpacing() const;
154     qreal minLeftBearing() const;
155     qreal minRightBearing() const;
156     qreal maxWidth() const;
157
158     qreal xHeight() const;
159     qreal averageCharWidth() const;
160
161     bool inFont(QChar) const;
162     bool inFontUcs4(uint ucs4) const;
163
164     qreal leftBearing(QChar) const;
165     qreal rightBearing(QChar) const;
166     qreal width(const QString &string) const;
167
168     qreal width(QChar) const;
169
170     QRectF boundingRect(const QString &string) const;
171     QRectF boundingRect(QChar) const;
172     QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops=0, int *tabarray=0) const;
173     QSizeF size(int flags, const QString& str, int tabstops=0, int *tabarray=0) const;
174
175     QRectF tightBoundingRect(const QString &text) const;
176
177     QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const;
178
179     qreal underlinePos() const;
180     qreal overlinePos() const;
181     qreal strikeOutPos() const;
182     qreal lineWidth() const;
183
184     bool operator==(const QFontMetricsF &other) const;
185     inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
186
187 private:
188     QExplicitlySharedDataPointer<QFontPrivate> d;
189 };
190
191 QT_END_NAMESPACE
192
193 QT_END_HEADER
194
195 #endif // QFONTMETRICS_H