Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qfontengine_qpf2.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | static const QFontEngineQPF2::TagType tagTypes[QFontEngineQPF2::NumTags] = { | - | ||||||
10 | QFontEngineQPF2::StringType, | - | ||||||
11 | QFontEngineQPF2::StringType, | - | ||||||
12 | QFontEngineQPF2::UInt32Type, | - | ||||||
13 | QFontEngineQPF2::UInt32Type, | - | ||||||
14 | QFontEngineQPF2::StringType, | - | ||||||
15 | QFontEngineQPF2::FixedType, | - | ||||||
16 | QFontEngineQPF2::FixedType, | - | ||||||
17 | QFontEngineQPF2::FixedType, | - | ||||||
18 | QFontEngineQPF2::FixedType, | - | ||||||
19 | QFontEngineQPF2::FixedType, | - | ||||||
20 | QFontEngineQPF2::FixedType, | - | ||||||
21 | QFontEngineQPF2::FixedType, | - | ||||||
22 | QFontEngineQPF2::FixedType, | - | ||||||
23 | QFontEngineQPF2::FixedType, | - | ||||||
24 | QFontEngineQPF2::FixedType, | - | ||||||
25 | QFontEngineQPF2::UInt8Type, | - | ||||||
26 | QFontEngineQPF2::UInt8Type, | - | ||||||
27 | QFontEngineQPF2::UInt8Type, | - | ||||||
28 | QFontEngineQPF2::UInt8Type, | - | ||||||
29 | QFontEngineQPF2::StringType, | - | ||||||
30 | QFontEngineQPF2::BitFieldType | - | ||||||
31 | }; | - | ||||||
32 | template <typename T> | - | ||||||
33 | T readValue(const uchar *&data) | - | ||||||
34 | { | - | ||||||
35 | T value = qFromBigEndian<T>(data); | - | ||||||
36 | data += sizeof(T); | - | ||||||
37 | return value; | - | ||||||
38 | } | - | ||||||
39 | static inline const uchar *verifyTag(const uchar *tagPtr, const uchar *endPtr) | - | ||||||
40 | { | - | ||||||
41 | quint16 tag, length; | - | ||||||
42 | if (tagPtr + sizeof(quint16) > endPtr) { if (0) QMessageLogger(__FILE__, 115121, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 115121; dead code: return 0; } tag = qFromBigEndian<quint16>(tagPtr); if (0) QMessageLogger(__FILE__, 115121, __PRETTY_FUNCTION__).debug() << "read value" << tag << "of type " "quint16";QMessageLogger(__FILE__, 121, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 121; dead code: tagPtr += sizeof(quint16);QMessageLogger(__FILE__, 121, __PRETTY_FUNCTION__).debug() << "read value" << tag << "of type " "quint16"; | - | ||||||
43 | if (tagPtr + sizeof(quint16) > endPtr) { if (0) QMessageLogger(__FILE__, 116122, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 116122; dead code: return 0; } length = qFromBigEndian<quint16>(tagPtr); if (0) QMessageLogger(__FILE__, 116122, __PRETTY_FUNCTION__).debug() << "read value" << length << "of type " "quint16";QMessageLogger(__FILE__, 122, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 122; dead code: tagPtr += sizeof(quint16);QMessageLogger(__FILE__, 122, __PRETTY_FUNCTION__).debug() << "read value" << length << "of type " "quint16"; | - | ||||||
44 | if (tag == QFontEngineQPF2::Tag_EndOfHeader) | - | ||||||
45 | return endPtr; | - | ||||||
46 | if (tag < QFontEngineQPF2::NumTags) { | - | ||||||
47 | switch (tagTypes[tag]) { | - | ||||||
48 | case QFontEngineQPF2::BitFieldType: | - | ||||||
49 | case QFontEngineQPF2::StringType: | - | ||||||
50 | - | |||||||
51 | break; | - | ||||||
52 | case QFontEngineQPF2::UInt32Type: | - | ||||||
53 | if (!(length == sizeof(quint32))) { if (0) QMessageLogger(__FILE__, 126132, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 126132 << "with tag" << tag; dead code: return 0; };QMessageLogger(__FILE__, 132, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 132 << "with tag" << tag; | - | ||||||
54 | break; | - | ||||||
55 | case QFontEngineQPF2::FixedType: | - | ||||||
56 | if (!(length == sizeof(quint32))) { if (0) QMessageLogger(__FILE__, 129135, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 129135 << "with tag" << tag; dead code: return 0; };QMessageLogger(__FILE__, 135, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 135 << "with tag" << tag; | - | ||||||
57 | break; | - | ||||||
58 | case QFontEngineQPF2::UInt8Type: | - | ||||||
59 | if (!(length == sizeof(quint8))) { if (0) QMessageLogger(__FILE__, 132138, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint8)" " failed in line" << 132138 << "with tag" << tag; dead code: return 0; };QMessageLogger(__FILE__, 138, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint8)" " failed in line" << 138 << "with tag" << tag; | - | ||||||
60 | break; | - | ||||||
61 | } | - | ||||||
62 | - | |||||||
63 | - | |||||||
64 | - | |||||||
65 | - | |||||||
66 | - | |||||||
67 | - | |||||||
68 | } | - | ||||||
69 | return tagPtr + length; | - | ||||||
70 | } | - | ||||||
71 | - | |||||||
72 | const QFontEngineQPF2::Glyph *QFontEngineQPF2::findGlyph(glyph_t g) const | - | ||||||
73 | { | - | ||||||
74 | if (!g || g >= glyphMapEntries) | - | ||||||
75 | return 0; | - | ||||||
76 | const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset); | - | ||||||
77 | quint32 glyphPos = qFromBigEndian<quint32>(gmapPtr[g]); | - | ||||||
78 | if (glyphPos > glyphDataSize) { | - | ||||||
79 | if (glyphPos == 0xffffffff) | - | ||||||
80 | return 0; | - | ||||||
81 | - | |||||||
82 | - | |||||||
83 | - | |||||||
84 | if (glyphPos > glyphDataSize) | - | ||||||
85 | return 0; | - | ||||||
86 | } | - | ||||||
87 | return reinterpret_cast<const Glyph *>(fontData + glyphDataOffset + glyphPos); | - | ||||||
88 | } | - | ||||||
89 | - | |||||||
90 | bool QFontEngineQPF2::verifyHeader(const uchar *data, int size) | - | ||||||
91 | { | - | ||||||
92 | if (!(quintptr(data) % alignof(Header) == 0)) { if (0) QMessageLogger(__FILE__, 165171, __PRETTY_FUNCTION__).debug() << "condition " "quintptr(data) % Q_ALIGNOF(Header) == 0" " failed in line" << 165171; dead code: return 0; };QMessageLogger(__FILE__, 171, __PRETTY_FUNCTION__).debug() << "condition " "quintptr(data) % Q_ALIGNOF(Header) == 0" " failed in line" << 171; | - | ||||||
93 | if (!(size >= int(sizeof(Header)))) { if (0) QMessageLogger(__FILE__, 166172, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header))" " failed in line" << 166172; dead code: return 0; };QMessageLogger(__FILE__, 172, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header))" " failed in line" << 172; | - | ||||||
94 | const Header *header = reinterpret_cast<const Header *>(data); | - | ||||||
95 | if (header->magic[0] != 'Q' | - | ||||||
96 | || header->magic[1] != 'P' | - | ||||||
97 | || header->magic[2] != 'F' | - | ||||||
98 | || header->magic[3] != '2') | - | ||||||
99 | return false; | - | ||||||
100 | - | |||||||
101 | if (!(header->majorVersion <= CurrentMajorVersion)) { if (0) QMessageLogger(__FILE__, 174180, __PRETTY_FUNCTION__).debug() << "condition " "header->majorVersion <= CurrentMajorVersion" " failed in line" << 174180; dead code: return 0; };QMessageLogger(__FILE__, 180, __PRETTY_FUNCTION__).debug() << "condition " "header->majorVersion <= CurrentMajorVersion" " failed in line" << 180; | - | ||||||
102 | const quint16 dataSize = qFromBigEndian<quint16>(header->dataSize); | - | ||||||
103 | if (!(size >= int(sizeof(Header)) + dataSize)) { if (0) QMessageLogger(__FILE__, 176182, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header)) + dataSize" " failed in line" << 176182; dead code: return 0; };QMessageLogger(__FILE__, 182, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header)) + dataSize" " failed in line" << 182; | - | ||||||
104 | - | |||||||
105 | const uchar *tagPtr = data + sizeof(Header); | - | ||||||
106 | const uchar *tagEndPtr = tagPtr + dataSize; | - | ||||||
107 | while (tagPtr < tagEndPtr - 3) { | - | ||||||
108 | tagPtr = verifyTag(tagPtr, tagEndPtr); | - | ||||||
109 | if (!(tagPtr)) { if (0) QMessageLogger(__FILE__, 182188, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr" " failed in line" << 182188; dead code: return 0; };QMessageLogger(__FILE__, 188, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr" " failed in line" << 188; | - | ||||||
110 | } | - | ||||||
111 | - | |||||||
112 | if (!(tagPtr <= tagEndPtr)) { if (0) QMessageLogger(__FILE__, 185191, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr <= tagEndPtr" " failed in line" << 185191; dead code: return 0; };QMessageLogger(__FILE__, 191, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr <= tagEndPtr" " failed in line" << 191; | - | ||||||
113 | return true; | - | ||||||
114 | } | - | ||||||
115 | - | |||||||
116 | QVariant QFontEngineQPF2::extractHeaderField(const uchar *data, HeaderTag requestedTag) | - | ||||||
117 | { | - | ||||||
118 | const Header *header = reinterpret_cast<const Header *>(data); | - | ||||||
119 | const uchar *tagPtr = data + sizeof(Header); | - | ||||||
120 | const uchar *endPtr = tagPtr + qFromBigEndian<quint16>(header->dataSize); | - | ||||||
121 | while (tagPtr < endPtr - 3) { | - | ||||||
122 | quint16 tag = readValue<quint16>(tagPtr); | - | ||||||
123 | quint16 length = readValue<quint16>(tagPtr); | - | ||||||
124 | if (tag == requestedTag) { | - | ||||||
125 | switch (tagTypes[requestedTag]) { | - | ||||||
126 | case StringType: | - | ||||||
127 | return QVariant(QString::fromUtf8(reinterpret_cast<const char *>(tagPtr), length)); | - | ||||||
128 | case UInt32Type: | - | ||||||
129 | return QVariant(readValue<quint32>(tagPtr)); | - | ||||||
130 | case UInt8Type: | - | ||||||
131 | return QVariant(uint(*tagPtr)); | - | ||||||
132 | case FixedType: | - | ||||||
133 | return QVariant(QFixed::fromFixed(readValue<quint32>(tagPtr)).toReal()); | - | ||||||
134 | case BitFieldType: | - | ||||||
135 | return QVariant(QByteArray(reinterpret_cast<const char *>(tagPtr), length)); | - | ||||||
136 | } | - | ||||||
137 | return QVariant(); | - | ||||||
138 | } else if (tag == Tag_EndOfHeader) { | - | ||||||
139 | break; | - | ||||||
140 | } | - | ||||||
141 | tagPtr += length; | - | ||||||
142 | } | - | ||||||
143 | - | |||||||
144 | return QVariant(); | - | ||||||
145 | } | - | ||||||
146 | - | |||||||
147 | - | |||||||
148 | QFontEngineQPF2::QFontEngineQPF2(const QFontDef &def, const QByteArray &data) | - | ||||||
149 | : QFontEngine(QPF2), | - | ||||||
150 | fontData(reinterpret_cast<const uchar *>(data.constData())), dataSize(data.size()) | - | ||||||
151 | { | - | ||||||
152 | fontDef = def; | - | ||||||
153 | cache_cost = 100; | - | ||||||
154 | cmap = 0; | - | ||||||
155 | cmapOffset = 0; | - | ||||||
156 | cmapSize = 0; | - | ||||||
157 | glyphMapOffset = 0; | - | ||||||
158 | glyphMapEntries = 0; | - | ||||||
159 | glyphDataOffset = 0; | - | ||||||
160 | glyphDataSize = 0; | - | ||||||
161 | kerning_pairs_loaded = false; | - | ||||||
162 | readOnly = true; | - | ||||||
163 | - | |||||||
164 | - | |||||||
165 | - | |||||||
166 | - | |||||||
167 | - | |||||||
168 | if (!verifyHeader(fontData, dataSize)
| 0 | ||||||
169 | - | |||||||
170 | - | |||||||
171 | - | |||||||
172 | return; never executed: return; | 0 | ||||||
173 | } | - | ||||||
174 | - | |||||||
175 | const Header *header = reinterpret_cast<const Header *>(fontData); | - | ||||||
176 | - | |||||||
177 | readOnly = (header->lock == 0xffffffff); | - | ||||||
178 | - | |||||||
179 | const uchar *imgData = fontData + sizeof(Header) + qFromBigEndian<quint16>(header->dataSize); | - | ||||||
180 | const uchar *endPtr = fontData + dataSize; | - | ||||||
181 | while (imgData <= endPtr - 8
| 0 | ||||||
182 | quint16 blockTag = readValue<quint16>(imgData); | - | ||||||
183 | imgData += 2; | - | ||||||
184 | quint32 blockSize = readValue<quint32>(imgData); | - | ||||||
185 | - | |||||||
186 | if (blockTag == CMapBlock
| 0 | ||||||
187 | cmapOffset = imgData - fontData; | - | ||||||
188 | cmapSize = blockSize; | - | ||||||
189 | } never executed: else if (blockTag == GMapBlockend of block
| 0 | ||||||
190 | glyphMapOffset = imgData - fontData; | - | ||||||
191 | glyphMapEntries = blockSize / 4; | - | ||||||
192 | } never executed: else if (blockTag == GlyphBlockend of block
| 0 | ||||||
193 | glyphDataOffset = imgData - fontData; | - | ||||||
194 | glyphDataSize = blockSize; | - | ||||||
195 | } never executed: end of block | 0 | ||||||
196 | - | |||||||
197 | imgData += blockSize; | - | ||||||
198 | } never executed: end of block | 0 | ||||||
199 | - | |||||||
200 | face_id.filename = QFile::encodeName(extractHeaderField(fontData, Tag_FileName).toString()); | - | ||||||
201 | face_id.index = extractHeaderField(fontData, Tag_FileIndex).toInt(); | - | ||||||
202 | - | |||||||
203 | - | |||||||
204 | if (cmapOffset
| 0 | ||||||
205 | cmap = QFontEngine::getCMap(fontData + cmapOffset, cmapSize, &symbol, &cmapSize); | - | ||||||
206 | cmapOffset = cmap
| 0 | ||||||
207 | } never executed: end of block | 0 | ||||||
208 | - | |||||||
209 | - | |||||||
210 | if (glyphMapOffset
| 0 | ||||||
211 | const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset); | - | ||||||
212 | for (uint i = 0; i < glyphMapEntries
| 0 | ||||||
213 | quint32 glyphDataPos = qFromBigEndian<quint32>(gmapPtr[i]); | - | ||||||
214 | if (glyphDataPos == 0xffffffff
| 0 | ||||||
215 | continue; never executed: continue; | 0 | ||||||
216 | if (glyphDataPos >= glyphDataSize
| 0 | ||||||
217 | - | |||||||
218 | glyphMapOffset = 0; | - | ||||||
219 | glyphMapEntries = 0; | - | ||||||
220 | break; never executed: break; | 0 | ||||||
221 | } | - | ||||||
222 | } never executed: end of block | 0 | ||||||
223 | } never executed: end of block | 0 | ||||||
224 | } never executed: end of block | 0 | ||||||
225 | - | |||||||
226 | QFontEngineQPF2::~QFontEngineQPF2() | - | ||||||
227 | { | - | ||||||
228 | } | - | ||||||
229 | - | |||||||
230 | bool QFontEngineQPF2::getSfntTableData(uint tag, uchar *buffer, uint *length) const | - | ||||||
231 | { | - | ||||||
232 | if (tag != ( (((quint32)('c')) << 24) | (((quint32)('m')) << 16) | (((quint32)('a')) << 8) | ((quint32)('p')) ) || !cmap) | - | ||||||
233 | return false; | - | ||||||
234 | - | |||||||
235 | if (buffer && int(*length) >= cmapSize) | - | ||||||
236 | memcpy(buffer, cmap, cmapSize); | - | ||||||
237 | *length = cmapSize; | - | ||||||
238 | ((!(int(*length) > 0)) ? qt_assert("int(*length) > 0",__FILE__,319325) : qt_noop()); | - | ||||||
239 | return true; | - | ||||||
240 | } | - | ||||||
241 | - | |||||||
242 | glyph_t QFontEngineQPF2::glyphIndex(uint ucs4) const | - | ||||||
243 | { | - | ||||||
244 | glyph_t glyph = getTrueTypeGlyphIndex(cmap, cmapSize, ucs4); | - | ||||||
245 | if (glyph == 0 && symbol && ucs4 < 0x100) | - | ||||||
246 | glyph = getTrueTypeGlyphIndex(cmap, cmapSize, ucs4 + 0xf000); | - | ||||||
247 | if (!findGlyph(glyph)) | - | ||||||
248 | glyph = 0; | - | ||||||
249 | - | |||||||
250 | return glyph; | - | ||||||
251 | } | - | ||||||
252 | - | |||||||
253 | bool QFontEngineQPF2::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const | - | ||||||
254 | { | - | ||||||
255 | ((!(glyphs->numGlyphs >= *nglyphs)) ? qt_assert("glyphs->numGlyphs >= *nglyphs",__FILE__,336342) : qt_noop()); | - | ||||||
256 | if (*nglyphs < len) { | - | ||||||
257 | *nglyphs = len; | - | ||||||
258 | return false; | - | ||||||
259 | } | - | ||||||
260 | - | |||||||
261 | - | |||||||
262 | - | |||||||
263 | - | |||||||
264 | - | |||||||
265 | int glyph_pos = 0; | - | ||||||
266 | if (symbol) { | - | ||||||
267 | QStringIterator it(str, str + len); | - | ||||||
268 | while (it.hasNext()) { | - | ||||||
269 | const uint uc = it.next(); | - | ||||||
270 | glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, cmapSize, uc); | - | ||||||
271 | if(!glyphs->glyphs[glyph_pos] && uc < 0x100) | - | ||||||
272 | glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, cmapSize, uc + 0xf000); | - | ||||||
273 | ++glyph_pos; | - | ||||||
274 | } | - | ||||||
275 | } else { | - | ||||||
276 | QStringIterator it(str, str + len); | - | ||||||
277 | while (it.hasNext()) { | - | ||||||
278 | const uint uc = it.next(); | - | ||||||
279 | glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, cmapSize, uc); | - | ||||||
280 | - | |||||||
281 | - | |||||||
282 | - | |||||||
283 | - | |||||||
284 | - | |||||||
285 | - | |||||||
286 | - | |||||||
287 | ++glyph_pos; | - | ||||||
288 | } | - | ||||||
289 | } | - | ||||||
290 | - | |||||||
291 | *nglyphs = glyph_pos; | - | ||||||
292 | glyphs->numGlyphs = glyph_pos; | - | ||||||
293 | - | |||||||
294 | if (!(flags & GlyphIndicesOnly)) | - | ||||||
295 | recalcAdvances(glyphs, flags); | - | ||||||
296 | - | |||||||
297 | return true; | - | ||||||
298 | } | - | ||||||
299 | - | |||||||
300 | void QFontEngineQPF2::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags) const | - | ||||||
301 | { | - | ||||||
302 | for (int i = 0; i < glyphs->numGlyphs; ++i) { | - | ||||||
303 | const Glyph *g = findGlyph(glyphs->glyphs[i]); | - | ||||||
304 | if (!g) | - | ||||||
305 | continue; | - | ||||||
306 | glyphs->advances[i] = g->advance; | - | ||||||
307 | } | - | ||||||
308 | } | - | ||||||
309 | - | |||||||
310 | QImage QFontEngineQPF2::alphaMapForGlyph(glyph_t g) | - | ||||||
311 | { | - | ||||||
312 | const Glyph *glyph = findGlyph(g); | - | ||||||
313 | if (!glyph) | - | ||||||
314 | return QImage(); | - | ||||||
315 | - | |||||||
316 | const uchar *bits = ((const uchar *) glyph) + sizeof(Glyph); | - | ||||||
317 | - | |||||||
318 | QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Alpha8); | - | ||||||
319 | - | |||||||
320 | return image; | - | ||||||
321 | } | - | ||||||
322 | - | |||||||
323 | void QFontEngineQPF2::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) | - | ||||||
324 | { | - | ||||||
325 | addBitmapFontToPath(x, y, glyphs, path, flags); | - | ||||||
326 | } | - | ||||||
327 | - | |||||||
328 | glyph_metrics_t QFontEngineQPF2::boundingBox(const QGlyphLayout &glyphs) | - | ||||||
329 | { | - | ||||||
330 | glyph_metrics_t overall; | - | ||||||
331 | - | |||||||
332 | overall.y = -ascent(); | - | ||||||
333 | overall.height = ascent() + descent() + 1; | - | ||||||
334 | - | |||||||
335 | QFixed ymax = 0; | - | ||||||
336 | QFixed xmax = 0; | - | ||||||
337 | for (int i = 0; i < glyphs.numGlyphs; i++) { | - | ||||||
338 | const Glyph *g = findGlyph(glyphs.glyphs[i]); | - | ||||||
339 | if (!g) | - | ||||||
340 | continue; | - | ||||||
341 | - | |||||||
342 | QFixed x = overall.xoff + glyphs.offsets[i].x + g->x; | - | ||||||
343 | QFixed y = overall.yoff + glyphs.offsets[i].y + g->y; | - | ||||||
344 | overall.x = qMin(overall.x, x); | - | ||||||
345 | overall.y = qMin(overall.y, y); | - | ||||||
346 | xmax = qMax(xmax, x + g->width); | - | ||||||
347 | ymax = qMax(ymax, y + g->height); | - | ||||||
348 | overall.xoff += g->advance; | - | ||||||
349 | } | - | ||||||
350 | overall.height = qMax(overall.height, ymax - overall.y); | - | ||||||
351 | overall.width = xmax - overall.x; | - | ||||||
352 | - | |||||||
353 | return overall; | - | ||||||
354 | } | - | ||||||
355 | - | |||||||
356 | glyph_metrics_t QFontEngineQPF2::boundingBox(glyph_t glyph) | - | ||||||
357 | { | - | ||||||
358 | glyph_metrics_t overall; | - | ||||||
359 | const Glyph *g = findGlyph(glyph); | - | ||||||
360 | if (!g) | - | ||||||
361 | return overall; | - | ||||||
362 | overall.x = g->x; | - | ||||||
363 | overall.y = g->y; | - | ||||||
364 | overall.width = g->width; | - | ||||||
365 | overall.height = g->height; | - | ||||||
366 | overall.xoff = g->advance; | - | ||||||
367 | return overall; | - | ||||||
368 | } | - | ||||||
369 | - | |||||||
370 | QFixed QFontEngineQPF2::ascent() const | - | ||||||
371 | { | - | ||||||
372 | return QFixed::fromReal(extractHeaderField(fontData, Tag_Ascent).value<qreal>()); | - | ||||||
373 | } | - | ||||||
374 | - | |||||||
375 | QFixed QFontEngineQPF2::descent() const | - | ||||||
376 | { | - | ||||||
377 | return QFixed::fromReal(extractHeaderField(fontData, Tag_Descent).value<qreal>()); | - | ||||||
378 | } | - | ||||||
379 | - | |||||||
380 | QFixed QFontEngineQPF2::leading() const | - | ||||||
381 | { | - | ||||||
382 | return QFixed::fromReal(extractHeaderField(fontData, Tag_Leading).value<qreal>()); | - | ||||||
383 | } | - | ||||||
384 | - | |||||||
385 | qreal QFontEngineQPF2::maxCharWidth() const | - | ||||||
386 | { | - | ||||||
387 | return extractHeaderField(fontData, Tag_MaxCharWidth).value<qreal>(); | - | ||||||
388 | } | - | ||||||
389 | - | |||||||
390 | qreal QFontEngineQPF2::minLeftBearing() const | - | ||||||
391 | { | - | ||||||
392 | return extractHeaderField(fontData, Tag_MinLeftBearing).value<qreal>(); | - | ||||||
393 | } | - | ||||||
394 | - | |||||||
395 | qreal QFontEngineQPF2::minRightBearing() const | - | ||||||
396 | { | - | ||||||
397 | return extractHeaderField(fontData, Tag_MinRightBearing).value<qreal>(); | - | ||||||
398 | } | - | ||||||
399 | - | |||||||
400 | QFixed QFontEngineQPF2::underlinePosition() const | - | ||||||
401 | { | - | ||||||
402 | return QFixed::fromReal(extractHeaderField(fontData, Tag_UnderlinePosition).value<qreal>()); | - | ||||||
403 | } | - | ||||||
404 | - | |||||||
405 | QFixed QFontEngineQPF2::lineThickness() const | - | ||||||
406 | { | - | ||||||
407 | return QFixed::fromReal(extractHeaderField(fontData, Tag_LineThickness).value<qreal>()); | - | ||||||
408 | } | - | ||||||
409 | - | |||||||
410 | bool QFontEngineQPF2::isValid() const | - | ||||||
411 | { | - | ||||||
412 | return fontData && dataSize && cmapOffset | - | ||||||
413 | && glyphMapOffset && glyphDataOffset && glyphDataSize > 0; | - | ||||||
414 | } | - | ||||||
415 | - | |||||||
416 | void QPF2Generator::generate() | - | ||||||
417 | { | - | ||||||
418 | writeHeader(); | - | ||||||
419 | writeGMap(); | - | ||||||
420 | writeBlock(QFontEngineQPF2::GlyphBlock, QByteArray()); | - | ||||||
421 | - | |||||||
422 | dev->seek(4); | - | ||||||
423 | writeUInt32(0); | - | ||||||
424 | } | - | ||||||
425 | - | |||||||
426 | void QPF2Generator::writeHeader() | - | ||||||
427 | { | - | ||||||
428 | QFontEngineQPF2::Header header; | - | ||||||
429 | - | |||||||
430 | header.magic[0] = 'Q'; | - | ||||||
431 | header.magic[1] = 'P'; | - | ||||||
432 | header.magic[2] = 'F'; | - | ||||||
433 | header.magic[3] = '2'; | - | ||||||
434 | header.lock = 1; | - | ||||||
435 | header.majorVersion = QFontEngineQPF2::CurrentMajorVersion; | - | ||||||
436 | header.minorVersion = QFontEngineQPF2::CurrentMinorVersion; | - | ||||||
437 | header.dataSize = 0; | - | ||||||
438 | dev->write((const char *)&header, sizeof(header)); | - | ||||||
439 | - | |||||||
440 | writeTaggedString(QFontEngineQPF2::Tag_FontName, fe->fontDef.family.toUtf8()); | - | ||||||
441 | - | |||||||
442 | QFontEngine::FaceId face = fe->faceId(); | - | ||||||
443 | writeTaggedString(QFontEngineQPF2::Tag_FileName, face.filename); | - | ||||||
444 | writeTaggedUInt32(QFontEngineQPF2::Tag_FileIndex, face.index); | - | ||||||
445 | - | |||||||
446 | { | - | ||||||
447 | const QByteArray head = fe->getSfntTable(( (((quint32)('h')) << 24) | (((quint32)('e')) << 16) | (((quint32)('a')) << 8) | ((quint32)('d')) )); | - | ||||||
448 | if (head.size() >= 4
| 0 | ||||||
449 | const quint32 revision = qFromBigEndian<quint32>(reinterpret_cast<const uchar *>(head.constData()));()); | - | ||||||
450 | writeTaggedUInt32(QFontEngineQPF2::Tag_FontRevision, revision); | - | ||||||
451 | } never executed: end of block | 0 | ||||||
452 | } | - | ||||||
453 | - | |||||||
454 | writeTaggedQFixed(QFontEngineQPF2::Tag_Ascent, fe->ascent()); | - | ||||||
455 | writeTaggedQFixed(QFontEngineQPF2::Tag_Descent, fe->descent()); | - | ||||||
456 | writeTaggedQFixed(QFontEngineQPF2::Tag_Leading, fe->leading()); | - | ||||||
457 | writeTaggedQFixed(QFontEngineQPF2::Tag_XHeight, fe->xHeight()); | - | ||||||
458 | writeTaggedQFixed(QFontEngineQPF2::Tag_AverageCharWidth, fe->averageCharWidth()); | - | ||||||
459 | writeTaggedQFixed(QFontEngineQPF2::Tag_MaxCharWidth, QFixed::fromReal(fe->maxCharWidth())); | - | ||||||
460 | writeTaggedQFixed(QFontEngineQPF2::Tag_LineThickness, fe->lineThickness()); | - | ||||||
461 | writeTaggedQFixed(QFontEngineQPF2::Tag_MinLeftBearing, QFixed::fromReal(fe->minLeftBearing())); | - | ||||||
462 | writeTaggedQFixed(QFontEngineQPF2::Tag_MinRightBearing, QFixed::fromReal(fe->minRightBearing())); | - | ||||||
463 | writeTaggedQFixed(QFontEngineQPF2::Tag_UnderlinePosition, fe->underlinePosition()); | - | ||||||
464 | writeTaggedUInt8(QFontEngineQPF2::Tag_PixelSize, fe->fontDef.pixelSize); | - | ||||||
465 | writeTaggedUInt8(QFontEngineQPF2::Tag_Weight, fe->fontDef.weight); | - | ||||||
466 | writeTaggedUInt8(QFontEngineQPF2::Tag_Style, fe->fontDef.style); | - | ||||||
467 | - | |||||||
468 | writeTaggedUInt8(QFontEngineQPF2::Tag_GlyphFormat, QFontEngineQPF2::AlphamapGlyphs); | - | ||||||
469 | - | |||||||
470 | writeTaggedString(QFontEngineQPF2::Tag_EndOfHeader, QByteArray()); | - | ||||||
471 | align4(); | - | ||||||
472 | - | |||||||
473 | const quint64 size = dev->pos(); | - | ||||||
474 | header.dataSize = qToBigEndian<quint16>(size - sizeof(header)); | - | ||||||
475 | dev->seek(0); | - | ||||||
476 | dev->write((const char *)&header, sizeof(header)); | - | ||||||
477 | dev->seek(size); | - | ||||||
478 | } never executed: end of block | 0 | ||||||
479 | - | |||||||
480 | void QPF2Generator::writeGMap() | - | ||||||
481 | { | - | ||||||
482 | const quint16 glyphCount = fe->glyphCount(); | - | ||||||
483 | - | |||||||
484 | writeUInt16(QFontEngineQPF2::GMapBlock); | - | ||||||
485 | writeUInt16(0); | - | ||||||
486 | writeUInt32(glyphCount * 4); | - | ||||||
487 | - | |||||||
488 | QByteArray &buffer = dev->buffer(); | - | ||||||
489 | const int numBytes = glyphCount * sizeof(quint32); | - | ||||||
490 | qint64 pos = buffer.size(); | - | ||||||
491 | buffer.resize(pos + numBytes); | - | ||||||
492 | memset(buffer.data() + pos, 0xff, numBytes); | - | ||||||
493 | dev->seek(pos + numBytes); | - | ||||||
494 | } | - | ||||||
495 | - | |||||||
496 | void QPF2Generator::writeBlock(QFontEngineQPF2::BlockTag tag, const QByteArray &data) | - | ||||||
497 | { | - | ||||||
498 | writeUInt16(tag); | - | ||||||
499 | writeUInt16(0); | - | ||||||
500 | const int padSize = ((data.size() + 3) / 4) * 4 - data.size(); | - | ||||||
501 | writeUInt32(data.size() + padSize); | - | ||||||
502 | dev->write(data); | - | ||||||
503 | for (int i = 0; i < padSize; ++i) | - | ||||||
504 | writeUInt8(0); | - | ||||||
505 | } | - | ||||||
506 | - | |||||||
507 | void QPF2Generator::writeTaggedString(QFontEngineQPF2::HeaderTag tag, const QByteArray &string) | - | ||||||
508 | { | - | ||||||
509 | writeUInt16(tag); | - | ||||||
510 | writeUInt16(string.length()); | - | ||||||
511 | dev->write(string); | - | ||||||
512 | } | - | ||||||
513 | - | |||||||
514 | void QPF2Generator::writeTaggedUInt32(QFontEngineQPF2::HeaderTag tag, quint32 value) | - | ||||||
515 | { | - | ||||||
516 | writeUInt16(tag); | - | ||||||
517 | writeUInt16(sizeof(value)); | - | ||||||
518 | writeUInt32(value); | - | ||||||
519 | } | - | ||||||
520 | - | |||||||
521 | void QPF2Generator::writeTaggedUInt8(QFontEngineQPF2::HeaderTag tag, quint8 value) | - | ||||||
522 | { | - | ||||||
523 | writeUInt16(tag); | - | ||||||
524 | writeUInt16(sizeof(value)); | - | ||||||
525 | writeUInt8(value); | - | ||||||
526 | } | - | ||||||
527 | - | |||||||
528 | void QPF2Generator::writeTaggedQFixed(QFontEngineQPF2::HeaderTag tag, QFixed value) | - | ||||||
529 | { | - | ||||||
530 | writeUInt16(tag); | - | ||||||
531 | writeUInt16(sizeof(quint32)); | - | ||||||
532 | writeUInt32(value.value()); | - | ||||||
533 | } | - | ||||||
534 | - | |||||||
535 | - | |||||||
Switch to Source code | Preprocessed file |