Fix font printing on Windows using the native engine.
[profile/ivi/qtbase.git] / src / plugins / platforms / windows / qwindowsfontengine.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 QWINDOWSFONTENGINE_H
43 #define QWINDOWSFONTENGINE_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtGui/private/qfontengine_p.h>
57
58 #include <QtGui/QImage>
59 #include <QtCore/QSharedPointer>
60 #include <QtCore/QMetaType>
61
62 #include "qtwindows_additional.h"
63
64 QT_BEGIN_NAMESPACE
65
66 class QWindowsNativeImage;
67 class QWindowsFontEngineData;
68
69 class QWindowsFontEngine : public QFontEngine
70 {
71     Q_OBJECT
72     Q_PROPERTY(HFONT hFont READ hFont STORED false)
73     Q_PROPERTY(LOGFONT logFont READ logFont STORED false)
74     Q_PROPERTY(bool trueType READ trueType STORED false)
75
76 public:
77     QWindowsFontEngine(const QString &name, HFONT, bool, LOGFONT,
78                        const QSharedPointer<QWindowsFontEngineData> &fontEngineData);
79
80     ~QWindowsFontEngine();
81     void initFontInfo(const QFontDef &request,
82                       HDC fontHdc,  int dpi);
83
84     virtual QFixed lineThickness() const;
85     virtual Properties properties() const;
86     virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
87     virtual FaceId faceId() const;
88     virtual bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
89     virtual int synthesized() const;
90     virtual QFixed emSquareSize() const;
91
92     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
93     virtual void recalcAdvances(QGlyphLayout *glyphs, QTextEngine::ShaperFlags) const;
94
95     virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
96     virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
97                          QPainterPath *path, QTextItem::RenderFlags flags);
98
99     HGDIOBJ selectDesignFont() const;
100
101     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
102     virtual glyph_metrics_t boundingBox(glyph_t g) { return boundingBox(g, QTransform()); }
103     virtual glyph_metrics_t boundingBox(glyph_t g, const QTransform &t);
104
105
106     virtual QFixed ascent() const;
107     virtual QFixed descent() const;
108     virtual QFixed leading() const;
109     virtual QFixed xHeight() const;
110     virtual QFixed averageCharWidth() const;
111     virtual qreal maxCharWidth() const;
112     virtual qreal minLeftBearing() const;
113     virtual qreal minRightBearing() const;
114
115     virtual const char *name() const;
116
117     bool canRender(const QChar *string, int len);
118
119     Type type() const;
120
121     virtual QImage alphaMapForGlyph(glyph_t t) { return alphaMapForGlyph(t, QTransform()); }
122     virtual QImage alphaMapForGlyph(glyph_t, const QTransform &xform);
123     virtual QImage alphaRGBMapForGlyph(glyph_t t, QFixed subPixelPosition, const QTransform &xform);
124
125     virtual QFontEngine *cloneWithSize(qreal pixelSize) const;
126
127 #ifndef Q_CC_MINGW
128     virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
129 #endif
130
131     int getGlyphIndexes(const QChar *ch, int numChars, QGlyphLayout *glyphs, bool mirrored) const;
132     void getCMap();
133
134     bool getOutlineMetrics(glyph_t glyph, const QTransform &t, glyph_metrics_t *metrics) const;
135
136     const QSharedPointer<QWindowsFontEngineData> &fontEngineData() const { return m_fontEngineData; }
137
138     // Properties accessed by QWin32PrintEngine (QtPrintSupport)
139     LOGFONT logFont() const { return m_logfont; }
140     HFONT hFont() const     { return hfont; }
141     bool trueType() const   { return ttf; }
142
143     void setUniqueFamilyName(const QString &newName) { uniqueFamilyName = newName; }
144
145 private:
146     QWindowsNativeImage *drawGDIGlyph(HFONT font, glyph_t, int margin, const QTransform &xform,
147                                       QImage::Format mask_format);
148
149     const QSharedPointer<QWindowsFontEngineData> m_fontEngineData;
150
151     const QString     _name;
152     QString     uniqueFamilyName;
153     const HFONT       hfont;
154     const LOGFONT     m_logfont;
155     uint        stockFont  : 1;
156     uint        ttf        : 1;
157     uint        hasOutline : 1;
158     TEXTMETRIC  tm;
159     int         lw;
160     const unsigned char *cmap;
161     QByteArray cmapTable;
162     mutable qreal lbearing;
163     mutable qreal rbearing;
164     QFixed designToDevice;
165     int unitsPerEm;
166     QFixed x_height;
167     FaceId _faceId;
168
169     mutable int synthesized_flags;
170     mutable QFixed lineWidth;
171     mutable unsigned char *widthCache;
172     mutable uint widthCacheSize;
173     mutable QFixed *designAdvances;
174     mutable int designAdvancesSize;
175 };
176
177 class QWindowsMultiFontEngine : public QFontEngineMulti
178 {
179 public:
180     QWindowsMultiFontEngine(QFontEngine *first, const QStringList &fallbacks);
181     virtual ~QWindowsMultiFontEngine();
182     void loadEngine(int at);
183
184     QStringList fallbacks;
185 };
186
187 QT_END_NAMESPACE
188
189 Q_DECLARE_METATYPE(HFONT)
190 Q_DECLARE_METATYPE(LOGFONT)
191
192 #endif // QWINDOWSFONTENGINE_H
193