Make sure QFont's resolve mask is copied on compilers with C++0x support
[profile/ivi/qtbase.git] / src / gui / text / qfont.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
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 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
50 typedef struct FT_FaceRec_* FT_Face;
51 #endif
52
53 QT_BEGIN_HEADER
54
55 QT_BEGIN_NAMESPACE
56
57 QT_MODULE(Gui)
58
59 class QFontPrivate;                                     /* don't touch */
60 class QStringList;
61 class QVariant;
62 class Q3TextFormatCollection;
63
64 class Q_GUI_EXPORT QFont
65 {
66     Q_GADGET
67     Q_ENUMS(StyleStrategy)
68 public:
69     enum StyleHint {
70         Helvetica,  SansSerif = Helvetica,
71         Times,      Serif = Times,
72         Courier,    TypeWriter = Courier,
73         OldEnglish, Decorative = OldEnglish,
74         System,
75         AnyStyle,
76         Cursive,
77         Monospace,
78         Fantasy
79     };
80
81     enum StyleStrategy {
82         PreferDefault       = 0x0001,
83         PreferBitmap        = 0x0002,
84         PreferDevice        = 0x0004,
85         PreferOutline       = 0x0008,
86         ForceOutline        = 0x0010,
87         PreferMatch         = 0x0020,
88         PreferQuality       = 0x0040,
89         PreferAntialias     = 0x0080,
90         NoAntialias         = 0x0100,
91         OpenGLCompatible    = 0x0200,
92         ForceIntegerMetrics = 0x0400,
93         NoFontMerging       = 0x8000
94     };
95
96     enum HintingPreference {
97         PreferDefaultHinting        = 0,
98         PreferNoHinting             = 1,
99         PreferVerticalHinting       = 2,
100         PreferFullHinting           = 3
101     };
102
103     enum Weight {
104         Light    = 25,
105         Normal   = 50,
106         DemiBold = 63,
107         Bold     = 75,
108         Black    = 87
109     };
110
111     enum Style {
112         StyleNormal,
113         StyleItalic,
114         StyleOblique
115     };
116
117     enum Stretch {
118         UltraCondensed =  50,
119         ExtraCondensed =  62,
120         Condensed      =  75,
121         SemiCondensed  =  87,
122         Unstretched    = 100,
123         SemiExpanded   = 112,
124         Expanded       = 125,
125         ExtraExpanded  = 150,
126         UltraExpanded  = 200
127     };
128
129     enum Capitalization {
130         MixedCase,
131         AllUppercase,
132         AllLowercase,
133         SmallCaps,
134         Capitalize
135     };
136
137     enum SpacingType {
138         PercentageSpacing,
139         AbsoluteSpacing
140     };
141
142     enum ResolveProperties {
143         FamilyResolved              = 0x0001,
144         SizeResolved                = 0x0002,
145         StyleHintResolved           = 0x0004,
146         StyleStrategyResolved       = 0x0008,
147         WeightResolved              = 0x0010,
148         StyleResolved               = 0x0020,
149         UnderlineResolved           = 0x0040,
150         OverlineResolved            = 0x0080,
151         StrikeOutResolved           = 0x0100,
152         FixedPitchResolved          = 0x0200,
153         StretchResolved             = 0x0400,
154         KerningResolved             = 0x0800,
155         CapitalizationResolved      = 0x1000,
156         LetterSpacingResolved       = 0x2000,
157         WordSpacingResolved         = 0x4000,
158         HintingPreferenceResolved   = 0x8000,
159         AllPropertiesResolved       = 0xffff
160     };
161
162     QFont();
163     QFont(const QString &family, int pointSize = -1, int weight = -1, bool italic = false);
164     QFont(const QFont &, QPaintDevice *pd);
165     QFont(const QFont &);
166     ~QFont();
167
168     QString family() const;
169     void setFamily(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 #ifdef Q_WS_WIN
246     HFONT handle() const;
247 #else // !Q_WS_WIN
248     Qt::HANDLE handle() const;
249 #endif // Q_WS_WIN
250 #ifdef Q_WS_MAC
251     quint32 macFontID() const;
252 #endif
253 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
254     FT_Face freetypeFace() const;
255 #endif
256
257     // needed for X11
258     void setRawName(const QString &);
259     QString rawName() const;
260
261     QString key() const;
262
263     QString toString() const;
264     bool fromString(const QString &);
265
266     static QString substitute(const QString &);
267     static QStringList substitutes(const QString &);
268     static QStringList substitutions();
269     static void insertSubstitution(const QString&, const QString &);
270     static void insertSubstitutions(const QString&, const QStringList &);
271     static void removeSubstitution(const QString &);
272     static void initialize();
273     static void cleanup();
274 #ifndef Q_WS_QWS
275     static void cacheStatistics();
276 #endif
277
278     QString defaultFamily() const;
279     QString lastResortFamily() const;
280     QString lastResortFont() const;
281
282     QFont resolve(const QFont &) const;
283     inline uint resolve() const { return resolve_mask; }
284     inline void resolve(uint mask) { resolve_mask = mask; }
285
286 #ifdef QT3_SUPPORT
287     static QT3_SUPPORT QFont defaultFont();
288     static QT3_SUPPORT void setDefaultFont(const QFont &);
289     QT3_SUPPORT void setPixelSizeFloat(qreal);
290     QT3_SUPPORT qreal pointSizeFloat() const { return pointSizeF(); }
291     QT3_SUPPORT void setPointSizeFloat(qreal size) { setPointSizeF(size); }
292 #endif
293
294 private:
295     QFont(QFontPrivate *);
296
297     void detach();
298
299 #if defined(Q_WS_MAC)
300     void macSetFont(QPaintDevice *);
301 #elif defined(Q_WS_X11)
302     void x11SetScreen(int screen = -1);
303     int x11Screen() const;
304 #endif
305
306     friend class QFontPrivate;
307     friend class QFontDialogPrivate;
308     friend class QFontMetrics;
309     friend class QFontMetricsF;
310     friend class QFontInfo;
311     friend class QPainter;
312     friend class QPainterPrivate;
313     friend class QPSPrintEngineFont;
314     friend class QApplication;
315     friend class QWidget;
316     friend class QWidgetPrivate;
317     friend class Q3TextFormatCollection;
318     friend class QTextLayout;
319     friend class QTextEngine;
320     friend class QStackTextEngine;
321     friend class QTextLine;
322     friend struct QScriptLine;
323     friend class QGLContext;
324     friend class QWin32PaintEngine;
325     friend class QAlphaPaintEngine;
326     friend class QPainterPath;
327     friend class QTextItemInt;
328     friend class QPicturePaintEngine;
329     friend class QPainterReplayer;
330     friend class QPaintBufferEngine;
331     friend class QCommandLinkButtonPrivate;
332     friend class QFontEngine;
333
334 #ifndef QT_NO_DATASTREAM
335     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
336     friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
337 #endif
338
339     QExplicitlySharedDataPointer<QFontPrivate> d;
340     uint resolve_mask;
341 };
342
343
344 inline bool QFont::bold() const
345 { return weight() > Normal; }
346
347
348 inline void QFont::setBold(bool enable)
349 { setWeight(enable ? Bold : Normal); }
350
351 inline bool QFont::italic() const
352 {
353     return (style() != StyleNormal);
354 }
355
356 inline void QFont::setItalic(bool b) {
357     setStyle(b ? StyleItalic : StyleNormal);
358 }
359
360
361 /*****************************************************************************
362   QFont stream functions
363  *****************************************************************************/
364
365 #ifndef QT_NO_DATASTREAM
366 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QFont &);
367 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
368 #endif
369
370 #ifndef QT_NO_DEBUG_STREAM
371 Q_GUI_EXPORT QDebug operator<<(QDebug, const QFont &);
372 #endif
373
374 QT_END_NAMESPACE
375
376 QT_END_HEADER
377
378 #endif // QFONT_H