Get started with patching up the Qt GUI docs
[profile/ivi/qtbase.git] / src / gui / text / qfont.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QFONT_H
43 #define QFONT_H
44
45 #include <QtGui/qwindowdefs.h>
46 #include <QtCore/qstring.h>
47 #include <QtCore/qsharedpointer.h>
48
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54
55 class QFontPrivate;                                     /* don't touch */
56 class QStringList;
57 class QVariant;
58
59 class Q_GUI_EXPORT QFont
60 {
61     Q_GADGET
62     Q_ENUMS(StyleStrategy)
63 public:
64     enum StyleHint {
65         Helvetica,  SansSerif = Helvetica,
66         Times,      Serif = Times,
67         Courier,    TypeWriter = Courier,
68         OldEnglish, Decorative = OldEnglish,
69         System,
70         AnyStyle,
71         Cursive,
72         Monospace,
73         Fantasy
74     };
75
76     enum StyleStrategy {
77         PreferDefault       = 0x0001,
78         PreferBitmap        = 0x0002,
79         PreferDevice        = 0x0004,
80         PreferOutline       = 0x0008,
81         ForceOutline        = 0x0010,
82         PreferMatch         = 0x0020,
83         PreferQuality       = 0x0040,
84         PreferAntialias     = 0x0080,
85         NoAntialias         = 0x0100,
86         OpenGLCompatible    = 0x0200,
87         ForceIntegerMetrics = 0x0400,
88         NoFontMerging       = 0x8000
89     };
90
91     enum HintingPreference {
92         PreferDefaultHinting        = 0,
93         PreferNoHinting             = 1,
94         PreferVerticalHinting       = 2,
95         PreferFullHinting           = 3
96     };
97
98     enum Weight {
99         Light    = 25,
100         Normal   = 50,
101         DemiBold = 63,
102         Bold     = 75,
103         Black    = 87
104     };
105
106     enum Style {
107         StyleNormal,
108         StyleItalic,
109         StyleOblique
110     };
111
112     enum Stretch {
113         UltraCondensed =  50,
114         ExtraCondensed =  62,
115         Condensed      =  75,
116         SemiCondensed  =  87,
117         Unstretched    = 100,
118         SemiExpanded   = 112,
119         Expanded       = 125,
120         ExtraExpanded  = 150,
121         UltraExpanded  = 200
122     };
123
124     enum Capitalization {
125         MixedCase,
126         AllUppercase,
127         AllLowercase,
128         SmallCaps,
129         Capitalize
130     };
131
132     enum SpacingType {
133         PercentageSpacing,
134         AbsoluteSpacing
135     };
136
137     enum ResolveProperties {
138         FamilyResolved              = 0x0001,
139         SizeResolved                = 0x0002,
140         StyleHintResolved           = 0x0004,
141         StyleStrategyResolved       = 0x0008,
142         WeightResolved              = 0x0010,
143         StyleResolved               = 0x0020,
144         UnderlineResolved           = 0x0040,
145         OverlineResolved            = 0x0080,
146         StrikeOutResolved           = 0x0100,
147         FixedPitchResolved          = 0x0200,
148         StretchResolved             = 0x0400,
149         KerningResolved             = 0x0800,
150         CapitalizationResolved      = 0x1000,
151         LetterSpacingResolved       = 0x2000,
152         WordSpacingResolved         = 0x4000,
153         HintingPreferenceResolved   = 0x8000,
154         StyleNameResolved           = 0x10000,
155         AllPropertiesResolved       = 0x1ffff
156     };
157
158     QFont();
159     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
160     QFont(const QFont &, QPaintDevice *pd);
161     QFont(const QFont &);
162     ~QFont();
163
164     QString family() const;
165     void setFamily(const QString &);
166
167     QString styleName() const;
168     void setStyleName(const QString &);
169
170     int pointSize() const;
171     void setPointSize(int);
172     qreal pointSizeF() const;
173     void setPointSizeF(qreal);
174
175     int pixelSize() const;
176     void setPixelSize(int);
177
178     int weight() const;
179     void setWeight(int);
180
181     inline bool bold() const;
182     inline void setBold(bool);
183
184     void setStyle(Style style);
185     Style style() const;
186
187     inline bool italic() const;
188     inline void setItalic(bool b);
189
190     bool underline() const;
191     void setUnderline(bool);
192
193     bool overline() const;
194     void setOverline(bool);
195
196     bool strikeOut() const;
197     void setStrikeOut(bool);
198
199     bool fixedPitch() const;
200     void setFixedPitch(bool);
201
202     bool kerning() const;
203     void setKerning(bool);
204
205     StyleHint styleHint() const;
206     StyleStrategy styleStrategy() const;
207     void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
208     void setStyleStrategy(StyleStrategy s);
209
210     int stretch() const;
211     void setStretch(int);
212
213     qreal letterSpacing() const;
214     SpacingType letterSpacingType() const;
215     void setLetterSpacing(SpacingType type, qreal spacing);
216
217     qreal wordSpacing() const;
218     void setWordSpacing(qreal spacing);
219
220     void setCapitalization(Capitalization);
221     Capitalization capitalization() const;
222
223     void setHintingPreference(HintingPreference hintingPreference);
224     HintingPreference hintingPreference() const;
225
226     // is raw mode still needed?
227     bool rawMode() const;
228     void setRawMode(bool);
229
230     // dupicated from QFontInfo
231     bool exactMatch() const;
232
233     QFont &operator=(const QFont &);
234     bool operator==(const QFont &) const;
235     bool operator!=(const QFont &) const;
236     bool operator<(const QFont &) const;
237     operator QVariant() const;
238     bool isCopyOf(const QFont &) const;
239 #ifdef Q_COMPILER_RVALUE_REFS
240     inline QFont &operator=(QFont &&other)
241     { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask);  return *this; }
242 #endif
243
244     // needed for X11
245     void setRawName(const QString &);
246     QString rawName() const;
247
248     QString key() const;
249
250     QString toString() const;
251     bool fromString(const QString &);
252
253     static QString substitute(const QString &);
254     static QStringList substitutes(const QString &);
255     static QStringList substitutions();
256     static void insertSubstitution(const QString&, const QString &);
257     static void insertSubstitutions(const QString&, const QStringList &);
258     static void removeSubstitutions(const QString &);
259 #if QT_DEPRECATED_SINCE(5, 0)
260     static QT_DEPRECATED void removeSubstitution(const QString &family) { removeSubstitutions(family); }
261 #endif
262     static void initialize();
263     static void cleanup();
264     static void cacheStatistics();
265
266     QString defaultFamily() const;
267     QString lastResortFamily() const;
268     QString lastResortFont() const;
269
270     QFont resolve(const QFont &) const;
271     inline uint resolve() const { return resolve_mask; }
272     inline void resolve(uint mask) { resolve_mask = mask; }
273
274 private:
275     explicit QFont(QFontPrivate *);
276
277     void detach();
278
279
280     friend class QFontPrivate;
281     friend class QFontDialogPrivate;
282     friend class QFontMetrics;
283     friend class QFontMetricsF;
284     friend class QFontInfo;
285     friend class QPainter;
286     friend class QPainterPrivate;
287     friend class QPSPrintEngineFont;
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     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
309     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
310 #endif
311
312     QExplicitlySharedDataPointer<QFontPrivate> d;
313     uint resolve_mask;
314 };
315
316
317 inline bool QFont::bold() const
318 { return weight() > Normal; }
319
320
321 inline void QFont::setBold(bool enable)
322 { setWeight(enable ? Bold : Normal); }
323
324 inline bool QFont::italic() const
325 {
326     return (style() != StyleNormal);
327 }
328
329 inline void QFont::setItalic(bool b) {
330     setStyle(b ? StyleItalic : StyleNormal);
331 }
332
333
334 /*****************************************************************************
335   QFont stream functions
336  *****************************************************************************/
337
338 #ifndef QT_NO_DATASTREAM
339 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
340 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
341 #endif
342
343 #ifndef QT_NO_DEBUG_STREAM
344 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
345 #endif
346
347 QT_END_NAMESPACE
348
349 QT_END_HEADER
350
351 #endif // QFONT_H