1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QFONTMETRICS_H |
5 | #define QFONTMETRICS_H |
6 | |
7 | #include <QtGui/qtguiglobal.h> |
8 | #include <QtGui/qfont.h> |
9 | |
10 | #ifndef QT_INCLUDE_COMPAT |
11 | #include <QtCore/qrect.h> |
12 | #endif |
13 | #include <QtCore/qshareddata.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QRect; |
18 | class QTextOption; |
19 | |
20 | class Q_GUI_EXPORT QFontMetrics |
21 | { |
22 | public: |
23 | explicit QFontMetrics(const QFont &); |
24 | QFontMetrics(const QFont &font, const QPaintDevice *pd); |
25 | QFontMetrics(const QFontMetrics &); |
26 | ~QFontMetrics(); |
27 | |
28 | QFontMetrics &operator=(const QFontMetrics &); |
29 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetrics) |
30 | |
31 | void swap(QFontMetrics &other) noexcept |
32 | { d.swap(other&: other.d); } |
33 | |
34 | int ascent() const; |
35 | int capHeight() const; |
36 | int descent() const; |
37 | int height() const; |
38 | int leading() const; |
39 | int lineSpacing() const; |
40 | int minLeftBearing() const; |
41 | int minRightBearing() const; |
42 | int maxWidth() const; |
43 | |
44 | int xHeight() const; |
45 | int averageCharWidth() const; |
46 | |
47 | bool inFont(QChar) const; |
48 | bool inFontUcs4(uint ucs4) const; |
49 | |
50 | int leftBearing(QChar) const; |
51 | int rightBearing(QChar) const; |
52 | |
53 | int horizontalAdvance(const QString &, int len = -1) const; |
54 | int horizontalAdvance(const QString &, const QTextOption &textOption) const; |
55 | int horizontalAdvance(QChar) const; |
56 | |
57 | QRect boundingRect(QChar) const; |
58 | |
59 | QRect boundingRect(const QString &text) const; |
60 | QRect boundingRect(const QString &text, const QTextOption &textOption) const; |
61 | QRect boundingRect(const QRect &r, int flags, const QString &text, int tabstops = 0, int *tabarray = nullptr) const; |
62 | inline QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text, |
63 | int tabstops = 0, int *tabarray = nullptr) const |
64 | { return boundingRect(r: QRect(x, y, w, h), flags, text, tabstops, tabarray); } |
65 | QSize size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const; |
66 | |
67 | QRect tightBoundingRect(const QString &text) const; |
68 | QRect tightBoundingRect(const QString &text, const QTextOption &textOption) const; |
69 | |
70 | QString elidedText(const QString &text, Qt::TextElideMode mode, int width, int flags = 0) const; |
71 | |
72 | int underlinePos() const; |
73 | int overlinePos() const; |
74 | int strikeOutPos() const; |
75 | int lineWidth() const; |
76 | |
77 | qreal fontDpi() const; |
78 | |
79 | bool operator==(const QFontMetrics &other) const; |
80 | inline bool operator !=(const QFontMetrics &other) const { return !operator==(other); } |
81 | |
82 | private: |
83 | friend class QFontMetricsF; |
84 | friend class QStackTextEngine; |
85 | |
86 | QExplicitlySharedDataPointer<QFontPrivate> d; |
87 | }; |
88 | |
89 | Q_DECLARE_SHARED(QFontMetrics) |
90 | |
91 | class Q_GUI_EXPORT QFontMetricsF |
92 | { |
93 | public: |
94 | explicit QFontMetricsF(const QFont &font); |
95 | QFontMetricsF(const QFont &font, const QPaintDevice *pd); |
96 | QFontMetricsF(const QFontMetrics &); |
97 | QFontMetricsF(const QFontMetricsF &); |
98 | ~QFontMetricsF(); |
99 | |
100 | QFontMetricsF &operator=(const QFontMetricsF &); |
101 | QFontMetricsF &operator=(const QFontMetrics &); |
102 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetricsF) |
103 | |
104 | void swap(QFontMetricsF &other) noexcept { d.swap(other&: other.d); } |
105 | |
106 | qreal ascent() const; |
107 | qreal capHeight() const; |
108 | qreal descent() const; |
109 | qreal height() const; |
110 | qreal leading() const; |
111 | qreal lineSpacing() const; |
112 | qreal minLeftBearing() const; |
113 | qreal minRightBearing() const; |
114 | qreal maxWidth() const; |
115 | |
116 | qreal xHeight() const; |
117 | qreal averageCharWidth() const; |
118 | |
119 | bool inFont(QChar) const; |
120 | bool inFontUcs4(uint ucs4) const; |
121 | |
122 | qreal leftBearing(QChar) const; |
123 | qreal rightBearing(QChar) const; |
124 | |
125 | qreal horizontalAdvance(const QString &string, int length = -1) const; |
126 | qreal horizontalAdvance(QChar) const; |
127 | qreal horizontalAdvance(const QString &string, const QTextOption &textOption) const; |
128 | |
129 | QRectF boundingRect(const QString &string) const; |
130 | QRectF boundingRect(const QString &text, const QTextOption &textOption) const; |
131 | QRectF boundingRect(QChar) const; |
132 | QRectF boundingRect(const QRectF &r, int flags, const QString& string, int tabstops = 0, int *tabarray = nullptr) const; |
133 | QSizeF size(int flags, const QString& str, int tabstops = 0, int *tabarray = nullptr) const; |
134 | |
135 | QRectF tightBoundingRect(const QString &text) const; |
136 | QRectF tightBoundingRect(const QString &text, const QTextOption &textOption) const; |
137 | |
138 | QString elidedText(const QString &text, Qt::TextElideMode mode, qreal width, int flags = 0) const; |
139 | |
140 | qreal underlinePos() const; |
141 | qreal overlinePos() const; |
142 | qreal strikeOutPos() const; |
143 | qreal lineWidth() const; |
144 | |
145 | qreal fontDpi() const; |
146 | |
147 | bool operator==(const QFontMetricsF &other) const; |
148 | inline bool operator !=(const QFontMetricsF &other) const { return !operator==(other); } |
149 | |
150 | private: |
151 | QExplicitlySharedDataPointer<QFontPrivate> d; |
152 | }; |
153 | |
154 | Q_DECLARE_SHARED(QFontMetricsF) |
155 | |
156 | QT_END_NAMESPACE |
157 | |
158 | #endif // QFONTMETRICS_H |
159 | |