1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QFONTENGINE_QPA_P_H
43 #define QFONTENGINE_QPA_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.
55 #include <QtCore/qconfig.h>
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qendian.h>
58 #include <QtCore/QBuffer>
60 #include "qfontengine_p.h"
62 #include <QtCore/QFile>
72 class Q_GUI_EXPORT QFontEngineQPA : public QFontEngine
75 // if you add new tags please make sure to update the tables in
76 // qpfutil.cpp and tools/makeqpf/qpf2.cpp
78 Tag_FontName, // 0 string
79 Tag_FileName, // 1 string
80 Tag_FileIndex, // 2 quint32
81 Tag_FontRevision, // 3 quint32
82 Tag_FreeText, // 4 string
83 Tag_Ascent, // 5 QFixed
84 Tag_Descent, // 6 QFixed
85 Tag_Leading, // 7 QFixed
86 Tag_XHeight, // 8 QFixed
87 Tag_AverageCharWidth, // 9 QFixed
88 Tag_MaxCharWidth, // 10 QFixed
89 Tag_LineThickness, // 11 QFixed
90 Tag_MinLeftBearing, // 12 QFixed
91 Tag_MinRightBearing, // 13 QFixed
92 Tag_UnderlinePosition, // 14 QFixed
93 Tag_GlyphFormat, // 15 quint8
94 Tag_PixelSize, // 16 quint8
95 Tag_Weight, // 17 quint8
96 Tag_Style, // 18 quint8
97 Tag_EndOfHeader, // 19 string
98 Tag_WritingSystems, // 20 bitfield
123 CurrentMajorVersion = 2,
124 CurrentMinorVersion = 0
127 // The CMap is identical to the TrueType CMap table format
128 // The GMap table is a normal array with the total number of
129 // covered glyphs in the TrueType font
136 struct Q_PACKED Header
138 char magic[4]; // 'QPF2'
139 quint32 lock; // values: 0 = unlocked, 0xffffffff = read-only, otherwise qws client id of locking process
145 struct Q_PACKED Block
152 struct Q_PACKED Glyph
162 QFontEngineQPA(const QFontDef &def, const QByteArray &data);
165 FaceId faceId() const { return face_id; }
166 bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
168 bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
169 void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
171 void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
172 QImage alphaMapForGlyph(glyph_t t);
174 glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
175 glyph_metrics_t boundingBox(glyph_t glyph);
177 QFixed ascent() const;
178 QFixed descent() const;
179 QFixed leading() const;
180 qreal maxCharWidth() const;
181 qreal minLeftBearing() const;
182 qreal minRightBearing() const;
183 QFixed underlinePosition() const;
184 QFixed lineThickness() const;
188 bool canRender(const QChar *string, int len);
189 inline const char *name() const { return "QPF2"; }
191 virtual int glyphCount() const { return glyphMapEntries; }
193 bool isValid() const;
195 const Glyph *findGlyph(glyph_t g) const;
197 static bool verifyHeader(const uchar *data, int size);
198 static QVariant extractHeaderField(const uchar *data, HeaderTag tag);
202 const uchar *fontData;
204 const uchar *externalCMap;
207 quint32 glyphMapOffset;
208 quint32 glyphMapEntries;
209 quint32 glyphDataOffset;
210 quint32 glyphDataSize;
211 QString internalFileName;
212 QString encodedFileName;
216 QByteArray freetypeCMapTable;
217 mutable bool kerning_pairs_loaded;
222 QPAGenerator(QBuffer *device, QFontEngine *engine)
223 : dev(device), fe(engine) {}
228 void writeBlock(QFontEngineQPA::BlockTag tag, const QByteArray &data);
230 void writeTaggedString(QFontEngineQPA::HeaderTag tag, const QByteArray &string);
231 void writeTaggedUInt32(QFontEngineQPA::HeaderTag tag, quint32 value);
232 void writeTaggedUInt8(QFontEngineQPA::HeaderTag tag, quint8 value);
233 void writeTaggedQFixed(QFontEngineQPA::HeaderTag tag, QFixed value);
235 void writeUInt16(quint16 value) { value = qToBigEndian(value); dev->write((const char *)&value, sizeof(value)); }
236 void writeUInt32(quint32 value) { value = qToBigEndian(value); dev->write((const char *)&value, sizeof(value)); }
237 void writeUInt8(quint8 value) { dev->write((const char *)&value, sizeof(value)); }
238 void writeInt8(qint8 value) { dev->write((const char *)&value, sizeof(value)); }
240 void align4() { while (dev->pos() & 3) { dev->putChar('\0'); } }
246 class Q_GUI_EXPORT QFontEngineMultiQPA : public QFontEngineMulti
249 QFontEngineMultiQPA(QFontEngine *fe, int script, const QStringList &fallbacks);
250 QFontEngineMultiQPA(QFontEngine *fe, int script);
252 void loadEngine(int at);
253 static QFontEngine* createMultiFontEngine(QFontEngine *fe, int script);
255 int fallbackFamilyCount() const { return fallbackFamilies.size(); }
256 QString fallbackFamilyAt(int at) const { return fallbackFamilies.at(at); }
258 virtual void ensureFallbackFamiliesQueried();
259 virtual void setFallbackFamiliesList(const QStringList &fallbacks);
262 void init(QFontEngine *fe);
264 mutable QStringList fallbackFamilies;
266 mutable bool fallbacksQueried;
273 #endif // QFONTENGINE_QPA_P_H