1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.gui.font;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.global;
17 import qt.core.metamacros;
18 import qt.core.shareddata;
19 import qt.core.string;
20 import qt.core.stringlist;
21 import qt.core.typeinfo;
22 import qt.core.variant;
23 import qt.gui.paintdevice;
24 import qt.helpers;
25 
26 extern(C++, class) struct QFontPrivate;                                     /* don't touch */
27 
28 /// Binding for C++ class [QFont](https://doc.qt.io/qt-6/qfont.html).
29 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QFont
30 {
31     mixin(Q_GADGET);
32 public:
33     enum StyleHint {
34         Helvetica,  SansSerif = StyleHint.Helvetica,
35         Times,      Serif = StyleHint.Times,
36         Courier,    TypeWriter = StyleHint.Courier,
37         OldEnglish, Decorative = StyleHint.OldEnglish,
38         System,
39         AnyStyle,
40         Cursive,
41         Monospace,
42         Fantasy
43     }
44     /+ Q_ENUM(StyleHint) +/
45 
46     enum StyleStrategy {
47         PreferDefault       = 0x0001,
48         PreferBitmap        = 0x0002,
49         PreferDevice        = 0x0004,
50         PreferOutline       = 0x0008,
51         ForceOutline        = 0x0010,
52         PreferMatch         = 0x0020,
53         PreferQuality       = 0x0040,
54         PreferAntialias     = 0x0080,
55         NoAntialias         = 0x0100,
56         NoSubpixelAntialias = 0x0800,
57         PreferNoShaping     = 0x1000,
58         NoFontMerging       = 0x8000
59     }
60     /+ Q_ENUM(StyleStrategy) +/
61 
62     enum HintingPreference {
63         PreferDefaultHinting        = 0,
64         PreferNoHinting             = 1,
65         PreferVerticalHinting       = 2,
66         PreferFullHinting           = 3
67     }
68     /+ Q_ENUM(HintingPreference) +/
69 
70     enum Weight {
71         Thin = 100,
72         ExtraLight = 200,
73         Light = 300,
74         Normal = 400,
75         Medium = 500,
76         DemiBold = 600,
77         Bold = 700,
78         ExtraBold = 800,
79         Black = 900
80     }
81     /+ Q_ENUM(Weight) +/
82 
83     enum Style {
84         StyleNormal,
85         StyleItalic,
86         StyleOblique
87     }
88     /+ Q_ENUM(Style) +/
89 
90     enum Stretch {
91         AnyStretch     =   0,
92         UltraCondensed =  50,
93         ExtraCondensed =  62,
94         Condensed      =  75,
95         SemiCondensed  =  87,
96         Unstretched    = 100,
97         SemiExpanded   = 112,
98         Expanded       = 125,
99         ExtraExpanded  = 150,
100         UltraExpanded  = 200
101     }
102     /+ Q_ENUM(Stretch) +/
103 
104     enum Capitalization {
105         MixedCase,
106         AllUppercase,
107         AllLowercase,
108         SmallCaps,
109         Capitalize
110     }
111     /+ Q_ENUM(Capitalization) +/
112 
113     enum SpacingType {
114         PercentageSpacing,
115         AbsoluteSpacing
116     }
117     /+ Q_ENUM(SpacingType) +/
118 
119     enum ResolveProperties {
120         NoPropertiesResolved        = 0x0000,
121         FamilyResolved              = 0x0001,
122         SizeResolved                = 0x0002,
123         StyleHintResolved           = 0x0004,
124         StyleStrategyResolved       = 0x0008,
125         WeightResolved              = 0x0010,
126         StyleResolved               = 0x0020,
127         UnderlineResolved           = 0x0040,
128         OverlineResolved            = 0x0080,
129         StrikeOutResolved           = 0x0100,
130         FixedPitchResolved          = 0x0200,
131         StretchResolved             = 0x0400,
132         KerningResolved             = 0x0800,
133         CapitalizationResolved      = 0x1000,
134         LetterSpacingResolved       = 0x2000,
135         WordSpacingResolved         = 0x4000,
136         HintingPreferenceResolved   = 0x8000,
137         StyleNameResolved           = 0x10000,
138         FamiliesResolved            = 0x20000,
139         AllPropertiesResolved       = 0x3ffff
140     }
141     /+ Q_ENUM(ResolveProperties) +/
142 
143     @disable this();
144     pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this))))
145     ref typeof(this) rawConstructor();
146     static typeof(this) create()
147     {
148         typeof(this) r = typeof(this).init;
149         r.rawConstructor();
150         return r;
151     }
152 
153 
154     this(ref const(QString) family, int pointSize = -1, int weight = -1, bool italic = false);
155     /+ explicit +/this(ref const(QStringList) families, int pointSize = -1, int weight = -1, bool italic = false);
156     mixin(changeWindowsMangling(q{mangleClassesTailConst}, q{
157     this(ref const(QFont) font, const(QPaintDevice) pd);
158     }));
159     @disable this(this);
160     this(ref const(QFont) font);
161     ~this();
162 
163     /+ void swap(QFont &other)
164     { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); } +/
165 
166     QString family() const;
167     void setFamily(ref const(QString) );
168 
169     QStringList families() const;
170     void setFamilies(ref const(QStringList) );
171 
172     QString styleName() const;
173     void setStyleName(ref const(QString) );
174 
175     int pointSize() const;
176     void setPointSize(int);
177     qreal pointSizeF() const;
178     void setPointSizeF(qreal);
179 
180     int pixelSize() const;
181     void setPixelSize(int);
182 
183     Weight weight() const;
184     void setWeight(Weight weight);
185 
186     pragma(inline, true) bool bold() const
187     { return weight() > Weight.Medium; }
188     pragma(inline, true) void setBold(bool enable)
189     { setWeight(enable ? Weight.Bold : Weight.Normal); }
190 
191     void setStyle(Style style);
192     Style style() const;
193 
194     pragma(inline, true) bool italic() const
195     {
196         return (style() != Style.StyleNormal);
197     }
198     pragma(inline, true) void setItalic(bool b) {
199         setStyle(b ? Style.StyleItalic : Style.StyleNormal);
200     }
201 
202     bool underline() const;
203     void setUnderline(bool);
204 
205     bool overline() const;
206     void setOverline(bool);
207 
208     bool strikeOut() const;
209     void setStrikeOut(bool);
210 
211     bool fixedPitch() const;
212     void setFixedPitch(bool);
213 
214     bool kerning() const;
215     void setKerning(bool);
216 
217     StyleHint styleHint() const;
218     StyleStrategy styleStrategy() const;
219     void setStyleHint(StyleHint, StyleStrategy /+ = PreferDefault +/);
220     void setStyleStrategy(StyleStrategy s);
221 
222     int stretch() const;
223     void setStretch(int);
224 
225     qreal letterSpacing() const;
226     SpacingType letterSpacingType() const;
227     void setLetterSpacing(SpacingType type, qreal spacing);
228 
229     qreal wordSpacing() const;
230     void setWordSpacing(qreal spacing);
231 
232     void setCapitalization(Capitalization);
233     Capitalization capitalization() const;
234 
235     void setHintingPreference(HintingPreference hintingPreference);
236     HintingPreference hintingPreference() const;
237 
238     // dupicated from QFontInfo
239     bool exactMatch() const;
240 
241     /+ref QFont operator =(ref const(QFont) );+/
242     /+bool operator ==(ref const(QFont) ) const;+/
243     /+bool operator !=(ref const(QFont) ) const;+/
244     /+bool operator <(ref const(QFont) ) const;+/
245     /+auto opCast(T : QVariant)() const;+/
246     bool isCopyOf(ref const(QFont) ) const;
247     /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFont) +/
248 
249     QString key() const;
250 
251     QString toString() const;
252     bool fromString(ref const(QString) );
253 
254     static QString substitute(ref const(QString) );
255     static QStringList substitutes(ref const(QString) );
256     static QStringList substitutions();
257     static void insertSubstitution(ref const(QString), ref const(QString) );
258     static void insertSubstitutions(ref const(QString), ref const(QStringList) );
259     static void removeSubstitutions(ref const(QString) );
260     static void initialize();
261     static void cleanup();
262     static void cacheStatistics();
263 
264     QString defaultFamily() const;
265 
266     QFont resolve(ref const(QFont) ) const;
267     pragma(inline, true) uint resolveMask() const { return resolve_mask; }
268     pragma(inline, true) void setResolveMask(uint mask) { resolve_mask = mask; }
269 
270 /+ #if QT_DEPRECATED_SINCE(6, 0) +/
271     /+ QT_DEPRECATED_VERSION_X_6_0("Use setWeight() instead") +/ void setLegacyWeight(int legacyWeight);
272     /+ QT_DEPRECATED_VERSION_X_6_0("Use weight() instead") +/ int legacyWeight() const;
273 /+ #endif +/
274 
275 private:
276     /+ explicit +/this(QFontPrivate* );
277 
278     void detach();
279 
280 
281     /+ friend class QFontPrivate; +/
282     /+ friend class QFontDialogPrivate; +/
283     /+ friend class QFontMetrics; +/
284     /+ friend class QFontMetricsF; +/
285     /+ friend class QFontInfo; +/
286     /+ friend class QPainter; +/
287     /+ friend class QPainterPrivate; +/
288     /+ friend class QApplication; +/
289     /+ friend class QWidget; +/
290     /+ friend class QWidgetPrivate; +/
291     /+ friend class QTextLayout; +/
292     /+ friend class QTextEngine; +/
293     /+ friend class QStackTextEngine; +/
294     /+ friend class QTextLine; +/
295     /+ friend struct QScriptLine; +/
296     /+ friend class QOpenGLContext; +/
297     /+ friend class QWin32PaintEngine; +/
298     /+ friend class QAlphaPaintEngine; +/
299     /+ friend class QPainterPath; +/
300     /+ friend class QTextItemInt; +/
301     /+ friend class QPicturePaintEngine; +/
302     /+ friend class QPainterReplayer; +/
303     /+ friend class QPaintBufferEngine; +/
304     /+ friend class QCommandLinkButtonPrivate; +/
305     /+ friend class QFontEngine; +/
306 
307 /+ #ifndef QT_NO_DATASTREAM +/
308     version(QT_NO_DATASTREAM){}else
309     {
310         /+ friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &); +/
311         /+ friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &); +/
312     }
313 /+ #endif
314 
315 #ifndef QT_NO_DEBUG_STREAM
316     friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
317 #endif +/
318 
319     QExplicitlySharedDataPointer!(QFontPrivate) d;
320     uint resolve_mask;
321     mixin(CREATE_CONVENIENCE_WRAPPERS);
322 }
323 
324 /+ Q_DECLARE_SHARED(QFont)
325 
326 Q_GUI_EXPORT size_t qHash(const QFont &font, size_t seed = 0) noexcept;
327 
328 
329 
330 /*****************************************************************************
331   QFont stream functions
332  *****************************************************************************/
333 
334 #ifndef QT_NO_DATASTREAM
335 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
336 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
337 #endif
338 
339 #ifndef QT_NO_DEBUG_STREAM
340 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
341 #endif +/
342