1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #ifndef QFONTENGINE_QPF_P_H
43 #define QFONTENGINE_QPF_P_H
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.
56 #include "qfontengine_p.h"
60 #ifndef QT_NO_QWS_QPF2
61 #if !defined(QT_NO_FREETYPE)
62 # include "qfontengine_ft_p.h"
68 #ifndef QT_NO_QWS_QPF2
73 class Q_GUI_EXPORT QFontEngineQPF : public QFontEngine
76 // if you add new tags please make sure to update the tables in
77 // qpfutil.cpp and tools/makeqpf/qpf2.cpp
79 Tag_FontName, // 0 string
80 Tag_FileName, // 1 string
81 Tag_FileIndex, // 2 quint32
82 Tag_FontRevision, // 3 quint32
83 Tag_FreeText, // 4 string
84 Tag_Ascent, // 5 QFixed
85 Tag_Descent, // 6 QFixed
86 Tag_Leading, // 7 QFixed
87 Tag_XHeight, // 8 QFixed
88 Tag_AverageCharWidth, // 9 QFixed
89 Tag_MaxCharWidth, // 10 QFixed
90 Tag_LineThickness, // 11 QFixed
91 Tag_MinLeftBearing, // 12 QFixed
92 Tag_MinRightBearing, // 13 QFixed
93 Tag_UnderlinePosition, // 14 QFixed
94 Tag_GlyphFormat, // 15 quint8
95 Tag_PixelSize, // 16 quint8
96 Tag_Weight, // 17 quint8
97 Tag_Style, // 18 quint8
98 Tag_EndOfHeader, // 19 string
99 Tag_WritingSystems, // 20 bitfield
124 CurrentMajorVersion = 2,
125 CurrentMinorVersion = 0
128 // The CMap is identical to the TrueType CMap table format
129 // The GMap table is a normal array with the total number of
130 // covered glyphs in the TrueType font
137 struct Q_PACKED Header
139 char magic[4]; // 'QPF2'
140 quint32 lock; // values: 0 = unlocked, 0xffffffff = read-only, otherwise qws client id of locking process
146 struct Q_PACKED Block
153 struct Q_PACKED Glyph
163 #ifdef QT_FONTS_ARE_RESOURCES
164 QFontEngineQPF(const QFontDef &def, const uchar *bytes, int size);
166 QFontEngineQPF(const QFontDef &def, int fd, QFontEngine *renderingFontEngine = 0);
170 FaceId faceId() const { return face_id; }
171 bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
173 bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const;
174 void recalcAdvances(QGlyphLayout *, ShaperFlags) const;
176 void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
177 void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
178 QImage alphaMapForGlyph(glyph_t t);
180 glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
181 glyph_metrics_t boundingBox(glyph_t glyph);
183 QFixed ascent() const;
184 QFixed descent() const;
185 QFixed leading() const;
186 qreal maxCharWidth() const;
187 qreal minLeftBearing() const;
188 qreal minRightBearing() const;
189 QFixed underlinePosition() const;
190 QFixed lineThickness() const;
194 bool canRender(const QChar *string, int len);
195 inline const char *name() const { return "QPF2"; }
197 virtual int glyphCount() const { return glyphMapEntries; }
199 bool isValid() const;
201 const Glyph *findGlyph(glyph_t g) const;
203 static bool verifyHeader(const uchar *data, int size);
204 static QVariant extractHeaderField(const uchar *data, HeaderTag tag);
205 static QList<QByteArray> cleanUpAfterClientCrash(const QList<int> &crashedClientIds);
207 #if !defined(QT_NO_FREETYPE)
208 FT_Face lockFace() const;
209 void unlockFace() const;
210 void doKerning(QGlyphLayout *g, ShaperFlags flags) const;
211 virtual HB_Error getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints);
212 virtual QFixed emSquareSize() const;
215 inline QString fontFile() const { return fileName; }
217 QFontEngine *renderingEngine() const { return renderingFontEngine; }
219 QFontEngine *takeRenderingEngine()
221 QFontEngine *engine = renderingFontEngine;
222 renderingFontEngine = 0;
227 #if !defined(QT_NO_FREETYPE)
228 void ensureGlyphsLoaded(const QGlyphLayout &glyphs);
229 void loadGlyph(glyph_t glyph);
232 void remapFontData();
236 const uchar *fontData;
238 const uchar *externalCMap;
241 quint32 glyphMapOffset;
242 quint32 glyphMapEntries;
243 quint32 glyphDataOffset;
244 quint32 glyphDataSize;
246 QByteArray encodedFileName;
249 QFreetypeFace *freetype;
251 QByteArray freetypeCMapTable;
252 mutable bool kerning_pairs_loaded;
253 QFontEngine *renderingFontEngine;
258 QPFGenerator(QBuffer *device, QFontEngine *engine)
259 : dev(device), fe(engine) {}
264 void writeBlock(QFontEngineQPF::BlockTag tag, const QByteArray &data);
266 void writeTaggedString(QFontEngineQPF::HeaderTag tag, const QByteArray &string);
267 void writeTaggedUInt32(QFontEngineQPF::HeaderTag tag, quint32 value);
268 void writeTaggedUInt8(QFontEngineQPF::HeaderTag tag, quint8 value);
269 void writeTaggedQFixed(QFontEngineQPF::HeaderTag tag, QFixed value);
271 void writeUInt16(quint16 value) { value = qToBigEndian(value); dev->write((const char *)&value, sizeof(value)); }
272 void writeUInt32(quint32 value) { value = qToBigEndian(value); dev->write((const char *)&value, sizeof(value)); }
273 void writeUInt8(quint8 value) { dev->write((const char *)&value, sizeof(value)); }
274 void writeInt8(qint8 value) { dev->write((const char *)&value, sizeof(value)); }
276 void align4() { while (dev->pos() & 3) { dev->putChar('\0'); } }
282 #endif // QT_NO_QWS_QPF2
284 class QFontEngineMultiQWS : public QFontEngineMulti
287 QFontEngineMultiQWS(QFontEngine *fe, int script, const QStringList &fallbacks);
289 void loadEngine(int at);
290 void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
293 QStringList fallbackFamilies;
299 #endif // QFONTENGINE_QPF_P_H