source: trunk/src/gui/text/qfontengine_qpf_p.h@ 318

Last change on this file since 318 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QFONTENGINE_QPF_P_H
43#define QFONTENGINE_QPF_P_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 "qfontengine_p.h"
57#include <qendian.h>
58#include <qbuffer.h>
59
60#ifndef QT_NO_QWS_QPF2
61#if !defined(QT_NO_FREETYPE)
62# include "qfontengine_ft_p.h"
63#endif
64#endif
65
66QT_BEGIN_NAMESPACE
67
68#ifndef QT_NO_QWS_QPF2
69
70class QFontEngine;
71class QFreetypeFace;
72
73class Q_GUI_EXPORT QFontEngineQPF : public QFontEngine
74{
75public:
76 // if you add new tags please make sure to update the tables in
77 // qpfutil.cpp and tools/makeqpf/qpf2.cpp
78 enum HeaderTag {
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
100
101 NumTags
102 };
103
104 enum TagType {
105 StringType,
106 FixedType,
107 UInt8Type,
108 UInt32Type,
109 BitFieldType
110 };
111
112 struct Tag
113 {
114 quint16 tag;
115 quint16 size;
116 };
117
118 enum GlyphFormat {
119 BitmapGlyphs = 1,
120 AlphamapGlyphs = 8
121 };
122
123 enum {
124 CurrentMajorVersion = 2,
125 CurrentMinorVersion = 0
126 };
127
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
131 enum BlockTag {
132 CMapBlock,
133 GMapBlock,
134 GlyphBlock
135 };
136
137 struct Q_PACKED Header
138 {
139 char magic[4]; // 'QPF2'
140 quint32 lock; // values: 0 = unlocked, 0xffffffff = read-only, otherwise qws client id of locking process
141 quint8 majorVersion;
142 quint8 minorVersion;
143 quint16 dataSize;
144 };
145
146 struct Q_PACKED Block
147 {
148 quint16 tag;
149 quint16 pad;
150 quint32 dataSize;
151 };
152
153 struct Q_PACKED Glyph
154 {
155 quint8 width;
156 quint8 height;
157 quint8 bytesPerLine;
158 qint8 x;
159 qint8 y;
160 qint8 advance;
161 };
162
163#ifdef QT_FONTS_ARE_RESOURCES
164 QFontEngineQPF(const QFontDef &def, const uchar *bytes, int size);
165#else
166 QFontEngineQPF(const QFontDef &def, int fd, QFontEngine *renderingFontEngine = 0);
167#endif
168 ~QFontEngineQPF();
169
170 FaceId faceId() const { return face_id; }
171 bool getSfntTableData(uint tag, uchar *buffer, uint *length) const;
172
173 bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
174 void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
175
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);
179
180 glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
181 glyph_metrics_t boundingBox(glyph_t glyph);
182
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;
191
192 Type type() const;
193
194 bool canRender(const QChar *string, int len);
195 inline const char *name() const { return "QPF2"; }
196
197 virtual int glyphCount() const { return glyphMapEntries; }
198
199 bool isValid() const;
200
201 const Glyph *findGlyph(glyph_t g) const;
202
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);
206
207#if !defined(QT_NO_FREETYPE)
208 FT_Face lockFace() const;
209 void unlockFace() const;
210 void doKerning(QGlyphLayout *g, QTextEngine::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;
213#endif
214
215 inline QString fontFile() const { return fileName; }
216
217 QFontEngine *renderingEngine() const { return renderingFontEngine; }
218
219 QFontEngine *takeRenderingEngine()
220 {
221 QFontEngine *engine = renderingFontEngine;
222 renderingFontEngine = 0;
223 return engine;
224 }
225
226private:
227#if !defined(QT_NO_FREETYPE)
228 void ensureGlyphsLoaded(const QGlyphLayout &glyphs);
229 void loadGlyph(glyph_t glyph);
230 bool lockFile();
231 void unlockFile();
232 void remapFontData();
233#endif
234
235 int fd;
236 const uchar *fontData;
237 int dataSize;
238 const uchar *externalCMap;
239 quint32 cmapOffset;
240 int cmapSize;
241 quint32 glyphMapOffset;
242 quint32 glyphMapEntries;
243 quint32 glyphDataOffset;
244 quint32 glyphDataSize;
245 QString fileName;
246 bool readOnly;
247
248 QFreetypeFace *freetype;
249 FaceId face_id;
250 QByteArray freetypeCMapTable;
251 mutable bool kerning_pairs_loaded;
252 QFontEngine *renderingFontEngine;
253};
254
255struct QPFGenerator
256{
257 QPFGenerator(QBuffer *device, QFontEngine *engine)
258 : dev(device), fe(engine) {}
259
260 void generate();
261 void writeHeader();
262 void writeGMap();
263 void writeBlock(QFontEngineQPF::BlockTag tag, const QByteArray &data);
264
265 void writeTaggedString(QFontEngineQPF::HeaderTag tag, const QByteArray &string);
266 void writeTaggedUInt32(QFontEngineQPF::HeaderTag tag, quint32 value);
267 void writeTaggedUInt8(QFontEngineQPF::HeaderTag tag, quint8 value);
268 void writeTaggedQFixed(QFontEngineQPF::HeaderTag tag, QFixed value);
269
270 void writeUInt16(quint16 value) { value = qToBigEndian(value); dev->write((const char *)&value, sizeof(value)); }
271 void writeUInt32(quint32 value) { value = qToBigEndian(value); dev->write((const char *)&value, sizeof(value)); }
272 void writeUInt8(quint8 value) { dev->write((const char *)&value, sizeof(value)); }
273 void writeInt8(qint8 value) { dev->write((const char *)&value, sizeof(value)); }
274
275 void align4() { while (dev->pos() & 3) { dev->putChar('\0'); } }
276
277 QBuffer *dev;
278 QFontEngine *fe;
279};
280
281#endif // QT_NO_QWS_QPF2
282
283class QFontEngineMultiQWS : public QFontEngineMulti
284{
285public:
286 QFontEngineMultiQWS(QFontEngine *fe, int script, const QStringList &fallbacks);
287
288 void loadEngine(int at);
289 void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
290
291private:
292 QStringList fallbackFamilies;
293 int script;
294};
295
296QT_END_NAMESPACE
297
298#endif // QFONTENGINE_QPF_P_H
Note: See TracBrowser for help on using the repository browser.