Fix uses of qRound on non-floating-point types.
[profile/ivi/qtbase.git] / src / gui / text / qfontengine_coretext_p.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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QFONTENGINE_CORETEXT_P_H
43 #define QFONTENGINE_CORETEXT_P_H
44
45 #include <private/qfontengine_p.h>
46
47 #if !defined(Q_WS_MAC) || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QRawFontPrivate;
54 class QCoreTextFontEngineMulti;
55 class QCoreTextFontEngine : public QFontEngine
56 {
57 public:
58     QCoreTextFontEngine(CTFontRef font, const QFontDef &def);
59     QCoreTextFontEngine(CGFontRef font, const QFontDef &def);
60     ~QCoreTextFontEngine();
61
62     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
63     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
64
65     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
66     virtual glyph_metrics_t boundingBox(glyph_t glyph);
67
68     virtual QFixed ascent() const;
69     virtual QFixed descent() const;
70     virtual QFixed leading() const;
71     virtual QFixed xHeight() const;
72     virtual qreal maxCharWidth() const;
73     virtual QFixed averageCharWidth() const;
74
75     virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
76                                  QPainterPath *path, QTextItem::RenderFlags);
77
78     virtual const char *name() const { return "QCoreTextFontEngine"; }
79
80     virtual bool canRender(const QChar *string, int len);
81
82     virtual int synthesized() const { return synthesisFlags; }
83     virtual bool supportsSubPixelPositions() const { return true; }
84
85     virtual Type type() const { return QFontEngine::Mac; }
86
87     void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
88
89     virtual FaceId faceId() const;
90     virtual bool getSfntTableData(uint /*tag*/, uchar * /*buffer*/, uint * /*length*/) const;
91     virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
92     virtual QImage alphaMapForGlyph(glyph_t, QFixed subPixelPosition);
93     virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, int margin, const QTransform &t);
94     virtual qreal minRightBearing() const;
95     virtual qreal minLeftBearing() const;
96     virtual QFixed emSquareSize() const;
97
98     virtual QFontEngine *cloneWithSize(qreal pixelSize) const;
99
100 private:
101     friend class QRawFontPrivate;
102
103     void init();
104     QImage imageForGlyph(glyph_t glyph, QFixed subPixelPosition, int margin, bool colorful);
105     CTFontRef ctfont;
106     CGFontRef cgFont;
107     int synthesisFlags;
108     CGAffineTransform transform;
109     QFixed avgCharWidth;
110     friend class QCoreTextFontEngineMulti;
111 };
112
113 class QCoreTextFontEngineMulti : public QFontEngineMulti
114 {
115 public:
116     QCoreTextFontEngineMulti(const QCFString &name, const QFontDef &fontDef, bool kerning);
117     QCoreTextFontEngineMulti(CTFontRef ctFontRef, const QFontDef &fontDef, bool kerning);
118     ~QCoreTextFontEngineMulti();
119
120     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
121                               QTextEngine::ShaperFlags flags) const;
122     bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
123                       QTextEngine::ShaperFlags flags,
124                       unsigned short *logClusters, const HB_CharAttributes *charAttributes,
125                       QScriptItem *si) const;
126
127     virtual const char *name() const { return "CoreText"; }
128     inline CTFontRef macFontID() const { return ctfont; }
129
130 protected:
131     virtual void loadEngine(int at);
132
133 private:
134     void init(bool kerning);
135     inline const QCoreTextFontEngine *engineAt(int i) const
136     { return static_cast<const QCoreTextFontEngine *>(engines.at(i)); }
137
138     uint fontIndexForFont(CTFontRef font) const;
139     CTFontRef ctfont;
140     mutable QCFType<CFMutableDictionaryRef> attributeDict;
141     CGAffineTransform transform;
142     friend class QFontDialogPrivate;
143 };
144
145 CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef);
146
147 QT_END_NAMESPACE
148
149 QT_END_HEADER
150
151 #endif// !defined(Q_WS_MAC) || (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
152
153 #endif // QFONTENGINE_CORETEXT_P_H