1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.gui.fontmetrics;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.global;
19 import qt.core.namespace;
20 import qt.core.qchar;
21 import qt.core.rect;
22 import qt.core.shareddata;
23 import qt.core.size;
24 import qt.core.string;
25 import qt.core.typeinfo;
26 import qt.gui.font;
27 import qt.gui.paintdevice;
28 import qt.helpers;
29 
30 /+ #ifndef QT_INCLUDE_COMPAT
31 #endif
32 
33 
34 
35 
36 class QTextCodec;
37 class QRect; +/
38 
39 
40 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QFontMetrics
41 {
42 public:
43     /+ explicit +/this(ref const(QFont) );
44 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
45     this(ref const(QFont) font, QPaintDevice pd);
46 /+ #ifndef Q_QDOC +/
47     // the template is necessary to make QFontMetrics(font,nullptr) and QFontMetrics(font,NULL)
48     // not ambiguous. Implementation detail that should not be documented.
49     /+ template<char = 0>
50 #endif +/
51     /+ QFontMetrics(const QFont &font, const QPaintDevice *pd)
52         : QFontMetrics(font, const_cast<QPaintDevice*>(pd))
53     {} +/
54 /+ #else
55     QFontMetrics(const QFont &font, const QPaintDevice *pd);
56 #endif +/
57     @disable this(this);
58     this(ref const(QFontMetrics) );
59     ~this();
60 
61     /+ref QFontMetrics operator =(ref const(QFontMetrics) );+/
62     /+ inline QFontMetrics &operator=(QFontMetrics &&other) noexcept
63     { qSwap(d, other.d); return *this; } +/
64 
65     /+ void swap(QFontMetrics &other) noexcept
66     { qSwap(d, other.d); } +/
67 
68     int ascent() const;
69     int capHeight() const;
70     int descent() const;
71     int height() const;
72     int leading() const;
73     int lineSpacing() const;
74     int minLeftBearing() const;
75     int minRightBearing() const;
76     int maxWidth() const;
77 
78     int xHeight() const;
79     int averageCharWidth() const;
80 
81     bool inFont(QChar) const;
82     bool inFontUcs4(uint ucs4) const;
83 
84     int leftBearing(QChar) const;
85     int rightBearing(QChar) const;
86 
87 /+ #if QT_DEPRECATED_SINCE(5, 11) +/
88     /+ QT_DEPRECATED_X("Use QFontMetrics::horizontalAdvance") +/
89         int width(ref const(QString) , int len = -1) const;
90     /+ QT_DEPRECATED_X("Use QFontMetrics::horizontalAdvance") +/
91         int width(ref const(QString) , int len, int flags) const;
92     /+ QT_DEPRECATED_X("Use QFontMetrics::horizontalAdvance") +/
93         int width(QChar) const;
94 /+ #endif +/
95 
96     int horizontalAdvance(ref const(QString) , int len = -1) const;
97     int horizontalAdvance(QChar) const;
98 
99 /+ #if QT_VERSION < QT_VERSION_CHECK(6,0,0) +/
100     /+ QT_DEPRECATED +/ int charWidth(ref const(QString) str, int pos) const;
101 /+ #endif +/
102 
103     QRect boundingRect(QChar) const;
104 
105     QRect boundingRect(ref const(QString) text) const;
106     QRect boundingRect(ref const(QRect) r, int flags, ref const(QString) text, int tabstops = 0, int* tabarray = null) const;
107     pragma(inline, true) QRect boundingRect(int x, int y, int w, int h, int flags, ref const(QString) text,
108                                   int tabstops = 0, int* tabarray = null) const
109         { auto tmp = QRect(x, y, w, h); return boundingRect(tmp, flags, text, tabstops, tabarray); }
110     QSize size(int flags, ref const(QString) str, int tabstops = 0, int* tabarray = null) const;
111 
112     QRect tightBoundingRect(ref const(QString) text) const;
113 
114     QString elidedText(ref const(QString) text, /+ Qt:: +/qt.core.namespace.TextElideMode mode, int width, int flags = 0) const;
115 
116     int underlinePos() const;
117     int overlinePos() const;
118     int strikeOutPos() const;
119     int lineWidth() const;
120 
121     qreal fontDpi() const;
122 
123     /+bool operator ==(ref const(QFontMetrics) other) const;+/
124     /+pragma(inline, true) bool operator !=(ref const(QFontMetrics) other) const { return !operator==(other); }+/
125 
126 private:
127     /+ friend class QFontMetricsF; +/
128     /+ friend class QStackTextEngine; +/
129 
130     QExplicitlySharedDataPointer!(QFontPrivate) d;
131 }
132 
133 /+ Q_DECLARE_SHARED(QFontMetrics) +/
134 
135 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QFontMetricsF
136 {
137 public:
138     /+ explicit +/this(ref const(QFont) font);
139 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/
140     this(ref const(QFont) font, QPaintDevice pd);
141 /+ #ifndef Q_QDOC +/
142     // the template is necessary to make QFontMetrics(font,nullptr) and QFontMetrics(font,NULL)
143     // not ambiguous. Implementation detail that should not be documented.
144     /+ template<char = 0>
145 #endif +/
146     /+ QFontMetricsF(const QFont &font, const QPaintDevice *pd)
147         : QFontMetricsF(font, const_cast<QPaintDevice*>(pd))
148     {} +/
149 /+ #else
150     QFontMetricsF(const QFont &font, const QPaintDevice *pd);
151 #endif +/
152     this(ref const(QFontMetrics) );
153     @disable this(this);
154     this(ref const(QFontMetricsF) );
155     ~this();
156 
157     /+ref QFontMetricsF operator =(ref const(QFontMetricsF) );+/
158     /+ref QFontMetricsF operator =(ref const(QFontMetrics) );+/
159     /+ inline QFontMetricsF &operator=(QFontMetricsF &&other) noexcept
160     { qSwap(d, other.d); return *this; } +/
161 
162     /+ void swap(QFontMetricsF &other) noexcept { qSwap(d, other.d); } +/
163 
164     qreal ascent() const;
165     qreal capHeight() const;
166     qreal descent() const;
167     qreal height() const;
168     qreal leading() const;
169     qreal lineSpacing() const;
170     qreal minLeftBearing() const;
171     qreal minRightBearing() const;
172     qreal maxWidth() const;
173 
174     qreal xHeight() const;
175     qreal averageCharWidth() const;
176 
177     bool inFont(QChar) const;
178     bool inFontUcs4(uint ucs4) const;
179 
180     qreal leftBearing(QChar) const;
181     qreal rightBearing(QChar) const;
182 
183 /+ #if QT_DEPRECATED_SINCE(5, 11) +/
184     qreal width(ref const(QString) string) const;
185     qreal width(QChar) const;
186 /+ #endif +/
187 
188     qreal horizontalAdvance(ref const(QString) string, int length = -1) const;
189     qreal horizontalAdvance(QChar) const;
190 
191     QRectF boundingRect(ref const(QString) string) const;
192     QRectF boundingRect(QChar) const;
193     QRectF boundingRect(ref const(QRectF) r, int flags, ref const(QString) string, int tabstops = 0, int* tabarray = null) const;
194     QSizeF size(int flags, ref const(QString) str, int tabstops = 0, int* tabarray = null) const;
195 
196     QRectF tightBoundingRect(ref const(QString) text) const;
197 
198     QString elidedText(ref const(QString) text, /+ Qt:: +/qt.core.namespace.TextElideMode mode, qreal width, int flags = 0) const;
199 
200     qreal underlinePos() const;
201     qreal overlinePos() const;
202     qreal strikeOutPos() const;
203     qreal lineWidth() const;
204 
205     qreal fontDpi() const;
206 
207     /+bool operator ==(ref const(QFontMetricsF) other) const;+/
208     /+pragma(inline, true) bool operator !=(ref const(QFontMetricsF) other) const { return !operator==(other); }+/
209 
210 private:
211     QExplicitlySharedDataPointer!(QFontPrivate) d;
212 }
213 
214 /+ Q_DECLARE_SHARED(QFontMetricsF) +/
215