QtBase  v6.3.1
qfontmetrics.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QFONTMETRICS_H
41 #define QFONTMETRICS_H
42 
43 #include <QtGui/qtguiglobal.h>
44 #include <QtGui/qfont.h>
45 #include <QtCore/qsharedpointer.h>
46 #ifndef QT_INCLUDE_COMPAT
47 #include <QtCore/qrect.h>
48 #endif
49 
51 
52 class QRect;
53 class QTextOption;
54 
55 class Q_GUI_EXPORT QFontMetrics
56 {
57 public:
58  explicit QFontMetrics(const QFont &);
59  QFontMetrics(const QFont &font, const QPaintDevice *pd);
60  QFontMetrics(const QFontMetrics &);
61  ~QFontMetrics();
62 
63  QFontMetrics &operator=(const QFontMetrics &);
65 
67  { d.swap(other.d); }
68 
69  int ascent() const;
70  int capHeight() const;
71  int descent() const;
72  int height() const;
73  int leading() const;
74  int lineSpacing() const;
75  int minLeftBearing() const;
76  int minRightBearing() const;
77  int maxWidth() const;
78 
79  int xHeight() const;
80  int averageCharWidth() const;
81 
82  bool inFont(QChar) const;
83  bool inFontUcs4(uint ucs4) const;
84 
85  int leftBearing(QChar) const;
86  int rightBearing(QChar) const;
87 
88  int horizontalAdvance(const QString &, int len = -1) const;
89  int horizontalAdvance(const QString &, const QTextOption &textOption) const;
90  int horizontalAdvance(QChar) const;
91 
92  QRect boundingRect(QChar) const;
93 
94  QRect boundingRect(const QString &text) const;
95  QRect boundingRect(const QString &text, const QTextOption &textOption) const;
96  QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops = 0, int *tabarray = nullptr) const;
97  inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text,
98  int tabstops = 0, int *tabarray = nullptr) const
99  { return boundingRect(QRect(x, y, w, h), flags, text, tabstops, tabarray); }
100  QSize size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const;
101 
102  QRect tightBoundingRect(const QString &text) const;
103  QRect tightBoundingRect(const QString &text, const QTextOption &textOption) const;
104 
105  QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const;
106 
107  int underlinePos() const;
108  int overlinePos() const;
109  int strikeOutPos() const;
110  int lineWidth() const;
111 
112  qreal fontDpi() const;
113 
114  bool operator==(const QFontMetrics &other) const;
115  inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); }
116 
117 private:
118  friend class QFontMetricsF;
119  friend class QStackTextEngine;
120 
122 };
123 
125 
126 class Q_GUI_EXPORT QFontMetricsF
127 {
128 public:
129  explicit QFontMetricsF(const QFont &font);
130  QFontMetricsF(const QFont &font, const QPaintDevice *pd);
131  QFontMetricsF(const QFontMetrics &);
132  QFontMetricsF(const QFontMetricsF &);
133  ~QFontMetricsF();
134 
135  QFontMetricsF &operator=(const QFontMetricsF &);
136  QFontMetricsF &operator=(const QFontMetrics &);
138 
139  void swap(QFontMetricsF &other) noexcept { d.swap(other.d); }
140 
141  qreal ascent() const;
142  qreal capHeight() 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;
150 
151  qreal xHeight() const;
152  qreal averageCharWidth() const;
153 
154  bool inFont(QChar) const;
155  bool inFontUcs4(uint ucs4) const;
156 
157  qreal leftBearing(QChar) const;
158  qreal rightBearing(QChar) const;
159 
160  qreal horizontalAdvance(const QString &string, int length = -1) const;
161  qreal horizontalAdvance(QChar) const;
162  qreal horizontalAdvance(const QString &string, const QTextOption &textOption) const;
163 
164  QRectF boundingRect(const QString &string) const;
165  QRectF boundingRect(const QString &text, const QTextOption &textOption) const;
166  QRectF boundingRect(QChar) const;
167  QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops = 0, int *tabarray = nullptr) const;
168  QSizeF size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const;
169 
170  QRectF tightBoundingRect(const QString &text) const;
171  QRectF tightBoundingRect(const QString &text, const QTextOption &textOption) const;
172 
174 
175  qreal underlinePos() const;
176  qreal overlinePos() const;
177  qreal strikeOutPos() const;
178  qreal lineWidth() const;
179 
180  qreal fontDpi() const;
181 
182  bool operator==(const QFontMetricsF &other) const;
183  inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); }
184 
185 private:
187 };
188 
190 
192 
193 #endif // QFONTMETRICS_H
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:84
template< typename Enum > bool operator!=(Enum lhs, QFlags< Enum > rhs)
template< typename Enum > bool operator==(Enum lhs, QFlags< Enum > rhs)
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:127
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:56
QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text, int tabstops=0, int *tabarray=nullptr) const
Definition: qfontmetrics.h:97
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
QString elidedText(Qt::TextElideMode mode, const QFixed &width, int flags=0, int from=0, int count=-1) const
QFixed maxWidth
The QTextOption class provides a description of general rich text properties. \inmodule QtGui.
Definition: qtextoption.h:54
QString str
[2]
QString text
[meta data]
TextElideMode
Definition: qnamespace.h:213
void
Definition: png.h:1080
constexpr bool operator!=(const timespec &t1, const timespec &t2)
Definition: qcore_unix_p.h:124
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
unsigned int uint
Definition: qglobal.h:334
#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class)
Definition: qglobal.h:563
@ text
bool operator==(const QMakeBaseKey &one, const QMakeBaseKey &two)
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLboolean r
[2]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei width
GLbitfield flags
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLenum GLsizei len
Definition: qopenglext.h:3292
#define Q_DECLARE_SHARED(TYPE)
Definition: qtypeinfo.h:197
QSharedPointer< T > other(t)
[5]
this swap(other)