Merge master into api_changes
[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 class Q3TextFormatCollection;
59
60 class Q_GUI_EXPORT QFont
61 {
62     Q_GADGET
63     Q_ENUMS(StyleStrategy)
64 public:
65     enum StyleHint {
66         Helvetica,  SansSerif = Helvetica,
67         Times,      Serif = Times,
68         Courier,    TypeWriter = Courier,
69         OldEnglish, Decorative = OldEnglish,
70         System,
71         AnyStyle,
72         Cursive,
73         Monospace,
74         Fantasy
75     };
76
77     enum StyleStrategy {
78         PreferDefault       = 0x0001,
79         PreferBitmap        = 0x0002,
80         PreferDevice        = 0x0004,
81         PreferOutline       = 0x0008,
82         ForceOutline        = 0x0010,
83         PreferMatch         = 0x0020,
84         PreferQuality       = 0x0040,
85         PreferAntialias     = 0x0080,
86         NoAntialias         = 0x0100,
87         OpenGLCompatible    = 0x0200,
88         ForceIntegerMetrics = 0x0400,
89         NoFontMerging       = 0x8000
90     };
91
92     enum HintingPreference {
93         PreferDefaultHinting        = 0,
94         PreferNoHinting             = 1,
95         PreferVerticalHinting       = 2,
96         PreferFullHinting           = 3
97     };
98
99     enum Weight {
100         Light    = 25,
101         Normal   = 50,
102         DemiBold = 63,
103         Bold     = 75,
104         Black    = 87
105     };
106
107     enum Style {
108         StyleNormal,
109         StyleItalic,
110         StyleOblique
111     };
112
113     enum Stretch {
114         UltraCondensed =  50,
115         ExtraCondensed =  62,
116         Condensed      =  75,
117         SemiCondensed  =  87,
118         Unstretched    = 100,
119         SemiExpanded   = 112,
120         Expanded       = 125,
121         ExtraExpanded  = 150,
122         UltraExpanded  = 200
123     };
124
125     enum Capitalization {
126         MixedCase,
127         AllUppercase,
128         AllLowercase,
129         SmallCaps,
130         Capitalize
131     };
132
133     enum SpacingType {
134         PercentageSpacing,
135         AbsoluteSpacing
136     };
137
138     enum ResolveProperties {
139         FamilyResolved              = 0x0001,
140         SizeResolved                = 0x0002,
141         StyleHintResolved           = 0x0004,
142         StyleStrategyResolved       = 0x0008,
143         WeightResolved              = 0x0010,
144         StyleResolved               = 0x0020,
145         UnderlineResolved           = 0x0040,
146         OverlineResolved            = 0x0080,
147         StrikeOutResolved           = 0x0100,
148         FixedPitchResolved          = 0x0200,
149         StretchResolved             = 0x0400,
150         KerningResolved             = 0x0800,
151         CapitalizationResolved      = 0x1000,
152         LetterSpacingResolved       = 0x2000,
153         WordSpacingResolved         = 0x4000,
154         HintingPreferenceResolved   = 0x8000,
155         StyleNameResolved           = 0x10000,
156         AllPropertiesResolved       = 0x1ffff
157     };
158
159     QFont();
160     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
161     QFont(const QFont &, QPaintDevice *pd);
162     QFont(const QFont &);
163     ~QFont();
164
165     QString family() const;
166     void setFamily(const QString &);
167
168     QString styleName() const;
169     void setStyleName(const QString &);
170
171     int pointSize() const;
172     void setPointSize(int);
173     qreal pointSizeF() const;
174     void setPointSizeF(qreal);
175
176     int pixelSize() const;
177     void setPixelSize(int);
178
179     int weight() const;
180     void setWeight(int);
181
182     inline bool bold() const;
183     inline void setBold(bool);
184
185     void setStyle(Style style);
186     Style style() const;
187
188     inline bool italic() const;
189     inline void setItalic(bool b);
190
191     bool underline() const;
192     void setUnderline(bool);
193
194     bool overline() const;
195     void setOverline(bool);
196
197     bool strikeOut() const;
198     void setStrikeOut(bool);
199
200     bool fixedPitch() const;
201     void setFixedPitch(bool);
202
203     bool kerning() const;
204     void setKerning(bool);
205
206     StyleHint styleHint() const;
207     StyleStrategy styleStrategy() const;
208     void setStyleHint(StyleHint, StyleStrategy = PreferDefault);
209     void setStyleStrategy(StyleStrategy s);
210
211     int stretch() const;
212     void setStretch(int);
213
214     qreal letterSpacing() const;
215     SpacingType letterSpacingType() const;
216     void setLetterSpacing(SpacingType type, qreal spacing);
217
218     qreal wordSpacing() const;
219     void setWordSpacing(qreal spacing);
220
221     void setCapitalization(Capitalization);
222     Capitalization capitalization() const;
223
224     void setHintingPreference(HintingPreference hintingPreference);
225     HintingPreference hintingPreference() const;
226
227     // is raw mode still needed?
228     bool rawMode() const;
229     void setRawMode(bool);
230
231     // dupicated from QFontInfo
232     bool exactMatch() const;
233
234     QFont &operator=(const QFont &);
235     bool operator==(const QFont &) const;
236     bool operator!=(const QFont &) const;
237     bool operator<(const QFont &) const;
238     operator QVariant() const;
239     bool isCopyOf(const QFont &) const;
240 #ifdef Q_COMPILER_RVALUE_REFS
241     inline QFont &operator=(QFont &&other)
242     { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask);  return *this; }
243 #endif
244
245     Qt::HANDLE handle() const;
246
247     // needed for X11
248     void setRawName(const QString &);
249     QString rawName() const;
250
251     QString key() const;
252
253     QString toString() const;
254     bool fromString(const QString &);
255
256     static QString substitute(const QString &);
257     static QStringList substitutes(const QString &);
258     static QStringList substitutions();
259     static void insertSubstitution(const QString&, const QString &);
260     static void insertSubstitutions(const QString&, const QStringList &);
261     static void removeSubstitution(const QString &);
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 Q3TextFormatCollection;
292     friend class QTextLayout;
293     friend class QTextEngine;
294     friend class QStackTextEngine;
295     friend class QTextLine;
296     friend struct QScriptLine;
297     friend class QOpenGLContext;
298     friend class QWin32PaintEngine;
299     friend class QAlphaPaintEngine;
300     friend class QPainterPath;
301     friend class QTextItemInt;
302     friend class QPicturePaintEngine;
303     friend class QPainterReplayer;
304     friend class QPaintBufferEngine;
305     friend class QCommandLinkButtonPrivate;
306     friend class QFontEngine;
307
308 #ifndef QT_NO_DATASTREAM
309     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
310     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
311 #endif
312
313     QExplicitlySharedDataPointer<QFontPrivate> d;
314     uint resolve_mask;
315 };
316
317
318 inline bool QFont::bold() const
319 { return weight() > Normal; }
320
321
322 inline void QFont::setBold(bool enable)
323 { setWeight(enable ? Bold : Normal); }
324
325 inline bool QFont::italic() const
326 {
327     return (style() != StyleNormal);
328 }
329
330 inline void QFont::setItalic(bool b) {
331     setStyle(b ? StyleItalic : StyleNormal);
332 }
333
334
335 /*****************************************************************************
336   QFont stream functions
337  *****************************************************************************/
338
339 #ifndef QT_NO_DATASTREAM
340 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
341 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
342 #endif
343
344 #ifndef QT_NO_DEBUG_STREAM
345 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
346 #endif
347
348 QT_END_NAMESPACE
349
350 QT_END_HEADER
351
352 #endif // QFONT_H