Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | static QFontEngineQPA::TagType tagTypes[QFontEngineQPA::NumTags] = { | - |
10 | QFontEngineQPA::StringType, | - |
11 | QFontEngineQPA::StringType, | - |
12 | QFontEngineQPA::UInt32Type, | - |
13 | QFontEngineQPA::UInt32Type, | - |
14 | QFontEngineQPA::StringType, | - |
15 | QFontEngineQPA::FixedType, | - |
16 | QFontEngineQPA::FixedType, | - |
17 | QFontEngineQPA::FixedType, | - |
18 | QFontEngineQPA::FixedType, | - |
19 | QFontEngineQPA::FixedType, | - |
20 | QFontEngineQPA::FixedType, | - |
21 | QFontEngineQPA::FixedType, | - |
22 | QFontEngineQPA::FixedType, | - |
23 | QFontEngineQPA::FixedType, | - |
24 | QFontEngineQPA::FixedType, | - |
25 | QFontEngineQPA::UInt8Type, | - |
26 | QFontEngineQPA::UInt8Type, | - |
27 | QFontEngineQPA::UInt8Type, | - |
28 | QFontEngineQPA::UInt8Type, | - |
29 | QFontEngineQPA::StringType, | - |
30 | QFontEngineQPA::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; never executed: return value; | 0 |
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("text/qfontengine_qpa.cpp", 122, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 122; return 0; } tag = qFromBigEndian<quint16>(tagPtr); if (0) QMessageLogger("text/qfontengine_qpa.cpp", 122, __PRETTY_FUNCTION__).debug() << "read value" << tag << "of type " "quint16"; tagPtr += sizeof(quint16); never executed: QMessageLogger("text/qfontengine_qpa.cpp", 122, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 122; never evaluated: tagPtr + sizeof(quint16) > endPtr never executed: return 0; never executed: QMessageLogger("text/qfontengine_qpa.cpp", 122, __PRETTY_FUNCTION__).debug() << "read value" << tag << "of type " "quint16"; | 0 |
43 | if (tagPtr + sizeof(quint16) > endPtr) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 123, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 123; return 0; } length = qFromBigEndian<quint16>(tagPtr); if (0) QMessageLogger("text/qfontengine_qpa.cpp", 123, __PRETTY_FUNCTION__).debug() << "read value" << length << "of type " "quint16"; tagPtr += sizeof(quint16); never evaluated: tagPtr + sizeof(quint16) > endPtr never executed: QMessageLogger("text/qfontengine_qpa.cpp", 123, __PRETTY_FUNCTION__).debug() << "read verify failed in line" << 123; never executed: return 0; never executed: QMessageLogger("text/qfontengine_qpa.cpp", 123, __PRETTY_FUNCTION__).debug() << "read value" << length << "of type " "quint16"; | 0 |
44 | if (tag == QFontEngineQPA::Tag_EndOfHeader) never evaluated: tag == QFontEngineQPA::Tag_EndOfHeader | 0 |
45 | return endPtr; never executed: return endPtr; | 0 |
46 | if (tag < QFontEngineQPA::NumTags) { never evaluated: tag < QFontEngineQPA::NumTags | 0 |
47 | switch (tagTypes[tag]) { | - |
48 | case QFontEngineQPA::BitFieldType: | - |
49 | case QFontEngineQPA::StringType: | - |
50 | | - |
51 | break; | 0 |
52 | case QFontEngineQPA::UInt32Type: | - |
53 | if (!(length == sizeof(quint32))) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 133, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 133 << "with tag" << tag; return 0; }; never executed: return 0; never evaluated: !(length == sizeof(quint32)) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 133, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 133 << "with tag" << tag; | 0 |
54 | break; | 0 |
55 | case QFontEngineQPA::FixedType: | - |
56 | if (!(length == sizeof(quint32))) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 136, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 136 << "with tag" << tag; return 0; }; never executed: QMessageLogger("text/qfontengine_qpa.cpp", 136, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint32)" " failed in line" << 136 << "with tag" << tag; never executed: return 0; never evaluated: !(length == sizeof(quint32)) | 0 |
57 | break; | 0 |
58 | case QFontEngineQPA::UInt8Type: | - |
59 | if (!(length == sizeof(quint8))) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 139, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint8)" " failed in line" << 139 << "with tag" << tag; return 0; }; never evaluated: !(length == sizeof(quint8)) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 139, __PRETTY_FUNCTION__).debug() << "verifying tag condition " "length == sizeof(quint8)" " failed in line" << 139 << "with tag" << tag; never executed: return 0; | 0 |
60 | break; | 0 |
61 | } | - |
62 | | - |
63 | | - |
64 | | - |
65 | | - |
66 | | - |
67 | | - |
68 | } | 0 |
69 | return tagPtr + length; never executed: return tagPtr + length; | 0 |
70 | } | - |
71 | | - |
72 | const QFontEngineQPA::Glyph *QFontEngineQPA::findGlyph(glyph_t g) const | - |
73 | { | - |
74 | if (!g || g >= glyphMapEntries) never evaluated: g >= glyphMapEntries | 0 |
75 | return 0; never executed: return 0; | 0 |
76 | const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset); | - |
77 | quint32 glyphPos = qFromBigEndian<quint32>(gmapPtr[g]); | - |
78 | if (glyphPos > glyphDataSize) { never evaluated: glyphPos > glyphDataSize | 0 |
79 | if (glyphPos == 0xffffffff) never evaluated: glyphPos == 0xffffffff | 0 |
80 | return 0; never executed: return 0; | 0 |
81 | | - |
82 | | - |
83 | | - |
84 | if (glyphPos > glyphDataSize) never evaluated: glyphPos > glyphDataSize | 0 |
85 | return 0; never executed: return 0; | 0 |
86 | } | 0 |
87 | return reinterpret_cast<const Glyph *>(fontData + glyphDataOffset + glyphPos); never executed: return reinterpret_cast<const Glyph *>(fontData + glyphDataOffset + glyphPos); | 0 |
88 | } | - |
89 | | - |
90 | bool QFontEngineQPA::verifyHeader(const uchar *data, int size) | - |
91 | { | - |
92 | if (!(size >= int(sizeof(Header)))) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 172, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header))" " failed in line" << 172; return 0; }; never evaluated: !(size >= int(sizeof(Header))) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 172, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header))" " failed in line" << 172; never executed: return 0; | 0 |
93 | const Header *header = reinterpret_cast<const Header *>(data); | - |
94 | if (header->magic[0] != 'Q' never evaluated: header->magic[0] != 'Q' | 0 |
95 | || header->magic[1] != 'P' never evaluated: header->magic[1] != 'P' | 0 |
96 | || header->magic[2] != 'F' never evaluated: header->magic[2] != 'F' | 0 |
97 | || header->magic[3] != '2') never evaluated: header->magic[3] != '2' | 0 |
98 | return false; never executed: return false; | 0 |
99 | | - |
100 | if (!(header->majorVersion <= CurrentMajorVersion)) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 180, __PRETTY_FUNCTION__).debug() << "condition " "header->majorVersion <= CurrentMajorVersion" " failed in line" << 180; return 0; }; never evaluated: !(header->majorVersion <= CurrentMajorVersion) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 180, __PRETTY_FUNCTION__).debug() << "condition " "header->majorVersion <= CurrentMajorVersion" " failed in line" << 180; never executed: return 0; | 0 |
101 | const quint16 dataSize = qFromBigEndian<quint16>(header->dataSize); | - |
102 | if (!(size >= int(sizeof(Header)) + dataSize)) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 182, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header)) + dataSize" " failed in line" << 182; return 0; }; never evaluated: !(size >= int(sizeof(Header)) + dataSize) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 182, __PRETTY_FUNCTION__).debug() << "condition " "size >= int(sizeof(Header)) + dataSize" " failed in line" << 182; never executed: return 0; | 0 |
103 | | - |
104 | const uchar *tagPtr = data + sizeof(Header); | - |
105 | const uchar *tagEndPtr = tagPtr + dataSize; | - |
106 | while (tagPtr < tagEndPtr - 3) { never evaluated: tagPtr < tagEndPtr - 3 | 0 |
107 | tagPtr = verifyTag(tagPtr, tagEndPtr); | - |
108 | if (!(tagPtr)) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 188, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr" " failed in line" << 188; return 0; }; never evaluated: !(tagPtr) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 188, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr" " failed in line" << 188; never executed: return 0; | 0 |
109 | } | 0 |
110 | | - |
111 | if (!(tagPtr <= tagEndPtr)) { if (0) QMessageLogger("text/qfontengine_qpa.cpp", 191, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr <= tagEndPtr" " failed in line" << 191; return 0; }; never evaluated: !(tagPtr <= tagEndPtr) never executed: QMessageLogger("text/qfontengine_qpa.cpp", 191, __PRETTY_FUNCTION__).debug() << "condition " "tagPtr <= tagEndPtr" " failed in line" << 191; never executed: return 0; | 0 |
112 | return true; never executed: return true; | 0 |
113 | } | - |
114 | | - |
115 | QVariant QFontEngineQPA::extractHeaderField(const uchar *data, HeaderTag requestedTag) | - |
116 | { | - |
117 | const Header *header = reinterpret_cast<const Header *>(data); | - |
118 | const uchar *tagPtr = data + sizeof(Header); | - |
119 | const uchar *endPtr = tagPtr + qFromBigEndian<quint16>(header->dataSize); | - |
120 | while (tagPtr < endPtr - 3) { never evaluated: tagPtr < endPtr - 3 | 0 |
121 | quint16 tag = readValue<quint16>(tagPtr); | - |
122 | quint16 length = readValue<quint16>(tagPtr); | - |
123 | if (tag == requestedTag) { never evaluated: tag == requestedTag | 0 |
124 | switch (tagTypes[requestedTag]) { | - |
125 | case StringType: | - |
126 | return QVariant(QString::fromUtf8(reinterpret_cast<const char *>(tagPtr), length)); never executed: return QVariant(QString::fromUtf8(reinterpret_cast<const char *>(tagPtr), length)); | 0 |
127 | case UInt32Type: | - |
128 | return QVariant(readValue<quint32>(tagPtr)); never executed: return QVariant(readValue<quint32>(tagPtr)); | 0 |
129 | case UInt8Type: | - |
130 | return QVariant(uint(*tagPtr)); never executed: return QVariant(uint(*tagPtr)); | 0 |
131 | case FixedType: | - |
132 | return QVariant(QFixed::fromFixed(readValue<quint32>(tagPtr)).toReal()); never executed: return QVariant(QFixed::fromFixed(readValue<quint32>(tagPtr)).toReal()); | 0 |
133 | case BitFieldType: | - |
134 | return QVariant(QByteArray(reinterpret_cast<const char *>(tagPtr), length)); never executed: return QVariant(QByteArray(reinterpret_cast<const char *>(tagPtr), length)); | 0 |
135 | } | - |
136 | return QVariant(); never executed: return QVariant(); | 0 |
137 | } else if (tag == Tag_EndOfHeader) { never evaluated: tag == Tag_EndOfHeader | 0 |
138 | break; | 0 |
139 | } | - |
140 | tagPtr += length; | - |
141 | } | 0 |
142 | | - |
143 | return QVariant(); never executed: return QVariant(); | 0 |
144 | } | - |
145 | | - |
146 | | - |
147 | | - |
148 | static inline unsigned int getChar(const QChar *str, int &i, const int len) | - |
149 | { | - |
150 | uint ucs4 = str[i].unicode(); | - |
151 | if (str[i].isHighSurrogate() && i < len-1 && str[i+1].isLowSurrogate()) { never evaluated: str[i].isHighSurrogate() never evaluated: i < len-1 never evaluated: str[i+1].isLowSurrogate() | 0 |
152 | ++i; | - |
153 | ucs4 = QChar::surrogateToUcs4(ucs4, str[i].unicode()); | - |
154 | } | 0 |
155 | return ucs4; never executed: return ucs4; | 0 |
156 | } | - |
157 | | - |
158 | QFontEngineQPA::QFontEngineQPA(const QFontDef &def, const QByteArray &data) | - |
159 | : fontData(reinterpret_cast<const uchar *>(data.constData())), dataSize(data.size()) | - |
160 | { | - |
161 | fontDef = def; | - |
162 | cache_cost = 100; | - |
163 | externalCMap = 0; | - |
164 | cmapOffset = 0; | - |
165 | cmapSize = 0; | - |
166 | glyphMapOffset = 0; | - |
167 | glyphMapEntries = 0; | - |
168 | glyphDataOffset = 0; | - |
169 | glyphDataSize = 0; | - |
170 | kerning_pairs_loaded = false; | - |
171 | readOnly = true; | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | if (!verifyHeader(fontData, dataSize)) { never evaluated: !verifyHeader(fontData, dataSize) | 0 |
178 | | - |
179 | | - |
180 | | - |
181 | return; | 0 |
182 | } | - |
183 | | - |
184 | const Header *header = reinterpret_cast<const Header *>(fontData); | - |
185 | | - |
186 | readOnly = (header->lock == 0xffffffff); | - |
187 | | - |
188 | const uchar *imgData = fontData + sizeof(Header) + qFromBigEndian<quint16>(header->dataSize); | - |
189 | const uchar *endPtr = fontData + dataSize; | - |
190 | while (imgData <= endPtr - 8) { never evaluated: imgData <= endPtr - 8 | 0 |
191 | quint16 blockTag = readValue<quint16>(imgData); | - |
192 | imgData += 2; | - |
193 | quint32 blockSize = readValue<quint32>(imgData); | - |
194 | | - |
195 | if (blockTag == CMapBlock) { never evaluated: blockTag == CMapBlock | 0 |
196 | cmapOffset = imgData - fontData; | - |
197 | cmapSize = blockSize; | - |
198 | } else if (blockTag == GMapBlock) { never evaluated: blockTag == GMapBlock | 0 |
199 | glyphMapOffset = imgData - fontData; | - |
200 | glyphMapEntries = blockSize / 4; | - |
201 | } else if (blockTag == GlyphBlock) { never evaluated: blockTag == GlyphBlock | 0 |
202 | glyphDataOffset = imgData - fontData; | - |
203 | glyphDataSize = blockSize; | - |
204 | } | 0 |
205 | | - |
206 | imgData += blockSize; | - |
207 | } | 0 |
208 | | - |
209 | face_id.filename = QFile::encodeName(extractHeaderField(fontData, Tag_FileName).toString()); | - |
210 | face_id.index = extractHeaderField(fontData, Tag_FileIndex).toInt(); | - |
211 | | - |
212 | | - |
213 | if (cmapOffset) { never evaluated: cmapOffset | 0 |
214 | int tableSize = cmapSize; | - |
215 | const uchar *cmapPtr = getCMap(fontData + cmapOffset, tableSize, &symbol, &cmapSize); | - |
216 | if (cmapPtr) | 0 |
217 | cmapOffset = cmapPtr - fontData; never executed: cmapOffset = cmapPtr - fontData; | 0 |
218 | else | - |
219 | cmapOffset = 0; never executed: cmapOffset = 0; | 0 |
220 | } else if (externalCMap) { never evaluated: externalCMap | 0 |
221 | int tableSize = cmapSize; | - |
222 | externalCMap = getCMap(externalCMap, tableSize, &symbol, &cmapSize); | - |
223 | } | 0 |
224 | | - |
225 | | - |
226 | if (glyphMapOffset) { never evaluated: glyphMapOffset | 0 |
227 | const quint32 *gmapPtr = reinterpret_cast<const quint32 *>(fontData + glyphMapOffset); | - |
228 | for (uint i = 0; i < glyphMapEntries; ++i) { never evaluated: i < glyphMapEntries | 0 |
229 | quint32 glyphDataPos = qFromBigEndian<quint32>(gmapPtr[i]); | - |
230 | if (glyphDataPos == 0xffffffff) never evaluated: glyphDataPos == 0xffffffff | 0 |
231 | continue; never executed: continue; | 0 |
232 | if (glyphDataPos >= glyphDataSize) { never evaluated: glyphDataPos >= glyphDataSize | 0 |
233 | | - |
234 | glyphMapOffset = 0; | - |
235 | glyphMapEntries = 0; | - |
236 | break; | 0 |
237 | } | - |
238 | } | 0 |
239 | } | 0 |
240 | } | 0 |
241 | | - |
242 | QFontEngineQPA::~QFontEngineQPA() | - |
243 | { | - |
244 | } | - |
245 | | - |
246 | bool QFontEngineQPA::getSfntTableData(uint tag, uchar *buffer, uint *length) const | - |
247 | { | - |
248 | (void)tag;; | - |
249 | (void)buffer;; | - |
250 | *length = 0; | - |
251 | return false; never executed: return false; | 0 |
252 | } | - |
253 | | - |
254 | bool QFontEngineQPA::stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QFontEngine::ShaperFlags flags) const | - |
255 | { | - |
256 | if (*nglyphs < len) { never evaluated: *nglyphs < len | 0 |
257 | *nglyphs = len; | - |
258 | return false; never executed: return false; | 0 |
259 | } | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | const uchar *cmap = externalCMap ? externalCMap : (fontData + cmapOffset); never evaluated: externalCMap | 0 |
266 | | - |
267 | bool mirrored = flags & QFontEngine::RightToLeft; | - |
268 | int glyph_pos = 0; | - |
269 | if (symbol) { | 0 |
270 | for (int i = 0; i < len; ++i) { | 0 |
271 | unsigned int uc = getChar(str, i, len); | - |
272 | if (mirrored) never evaluated: mirrored | 0 |
273 | uc = QChar::mirroredChar(uc); never executed: uc = QChar::mirroredChar(uc); | 0 |
274 | glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc); | - |
275 | if(!glyphs->glyphs[glyph_pos] && uc < 0x100) never evaluated: !glyphs->glyphs[glyph_pos] never evaluated: uc < 0x100 | 0 |
276 | glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000); never executed: glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc + 0xf000); | 0 |
277 | ++glyph_pos; | - |
278 | } | 0 |
279 | } else { | 0 |
280 | for (int i = 0; i < len; ++i) { | 0 |
281 | unsigned int uc = getChar(str, i, len); | - |
282 | if (mirrored) never evaluated: mirrored | 0 |
283 | uc = QChar::mirroredChar(uc); never executed: uc = QChar::mirroredChar(uc); | 0 |
284 | glyphs->glyphs[glyph_pos] = getTrueTypeGlyphIndex(cmap, uc); | - |
285 | | - |
286 | | - |
287 | | - |
288 | | - |
289 | | - |
290 | | - |
291 | | - |
292 | ++glyph_pos; | - |
293 | } | 0 |
294 | } | 0 |
295 | | - |
296 | *nglyphs = glyph_pos; | - |
297 | glyphs->numGlyphs = glyph_pos; | - |
298 | | - |
299 | if (!(flags & GlyphIndicesOnly)) never evaluated: !(flags & GlyphIndicesOnly) | 0 |
300 | recalcAdvances(glyphs, flags); never executed: recalcAdvances(glyphs, flags); | 0 |
301 | | - |
302 | return true; never executed: return true; | 0 |
303 | } | - |
304 | | - |
305 | void QFontEngineQPA::recalcAdvances(QGlyphLayout *glyphs, QFontEngine::ShaperFlags) const | - |
306 | { | - |
307 | for (int i = 0; i < glyphs->numGlyphs; ++i) { never evaluated: i < glyphs->numGlyphs | 0 |
308 | const Glyph *g = findGlyph(glyphs->glyphs[i]); | - |
309 | if (!g) { | 0 |
310 | glyphs->glyphs[i] = 0; | - |
311 | continue; never executed: continue; | 0 |
312 | } | - |
313 | glyphs->advances_x[i] = g->advance; | - |
314 | glyphs->advances_y[i] = 0; | - |
315 | } | 0 |
316 | } | 0 |
317 | | - |
318 | QImage QFontEngineQPA::alphaMapForGlyph(glyph_t g) | - |
319 | { | - |
320 | const Glyph *glyph = findGlyph(g); | - |
321 | if (!glyph) | 0 |
322 | return QImage(); never executed: return QImage(); | 0 |
323 | | - |
324 | const uchar *bits = ((const uchar *) glyph) + sizeof(Glyph); | - |
325 | | - |
326 | QImage image(bits,glyph->width, glyph->height, glyph->bytesPerLine, QImage::Format_Indexed8); | - |
327 | | - |
328 | return image; never executed: return image; | 0 |
329 | } | - |
330 | | - |
331 | void QFontEngineQPA::addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags) | - |
332 | { | - |
333 | addBitmapFontToPath(x, y, glyphs, path, flags); | - |
334 | } | 0 |
335 | | - |
336 | glyph_metrics_t QFontEngineQPA::boundingBox(const QGlyphLayout &glyphs) | - |
337 | { | - |
338 | glyph_metrics_t overall; | - |
339 | | - |
340 | overall.y = -ascent(); | - |
341 | overall.height = ascent() + descent() + 1; | - |
342 | | - |
343 | QFixed ymax = 0; | - |
344 | QFixed xmax = 0; | - |
345 | for (int i = 0; i < glyphs.numGlyphs; i++) { never evaluated: i < glyphs.numGlyphs | 0 |
346 | const Glyph *g = findGlyph(glyphs.glyphs[i]); | - |
347 | if (!g) | 0 |
348 | continue; never executed: continue; | 0 |
349 | | - |
350 | QFixed x = overall.xoff + glyphs.offsets[i].x + g->x; | - |
351 | QFixed y = overall.yoff + glyphs.offsets[i].y + g->y; | - |
352 | overall.x = qMin(overall.x, x); | - |
353 | overall.y = qMin(overall.y, y); | - |
354 | xmax = qMax(xmax, x + g->width); | - |
355 | ymax = qMax(ymax, y + g->height); | - |
356 | overall.xoff += g->advance; | - |
357 | } | 0 |
358 | overall.height = qMax(overall.height, ymax - overall.y); | - |
359 | overall.width = xmax - overall.x; | - |
360 | | - |
361 | return overall; never executed: return overall; | 0 |
362 | } | - |
363 | | - |
364 | glyph_metrics_t QFontEngineQPA::boundingBox(glyph_t glyph) | - |
365 | { | - |
366 | glyph_metrics_t overall; | - |
367 | const Glyph *g = findGlyph(glyph); | - |
368 | if (!g) | 0 |
369 | return overall; never executed: return overall; | 0 |
370 | overall.x = g->x; | - |
371 | overall.y = g->y; | - |
372 | overall.width = g->width; | - |
373 | overall.height = g->height; | - |
374 | overall.xoff = g->advance; | - |
375 | return overall; never executed: return overall; | 0 |
376 | } | - |
377 | | - |
378 | QFixed QFontEngineQPA::ascent() const | - |
379 | { | - |
380 | return QFixed::fromReal(extractHeaderField(fontData, Tag_Ascent).value<qreal>()); never executed: return QFixed::fromReal(extractHeaderField(fontData, Tag_Ascent).value<qreal>()); | 0 |
381 | } | - |
382 | | - |
383 | QFixed QFontEngineQPA::descent() const | - |
384 | { | - |
385 | return QFixed::fromReal(extractHeaderField(fontData, Tag_Descent).value<qreal>()); never executed: return QFixed::fromReal(extractHeaderField(fontData, Tag_Descent).value<qreal>()); | 0 |
386 | } | - |
387 | | - |
388 | QFixed QFontEngineQPA::leading() const | - |
389 | { | - |
390 | return QFixed::fromReal(extractHeaderField(fontData, Tag_Leading).value<qreal>()); never executed: return QFixed::fromReal(extractHeaderField(fontData, Tag_Leading).value<qreal>()); | 0 |
391 | } | - |
392 | | - |
393 | qreal QFontEngineQPA::maxCharWidth() const | - |
394 | { | - |
395 | return extractHeaderField(fontData, Tag_MaxCharWidth).value<qreal>(); never executed: return extractHeaderField(fontData, Tag_MaxCharWidth).value<qreal>(); | 0 |
396 | } | - |
397 | | - |
398 | qreal QFontEngineQPA::minLeftBearing() const | - |
399 | { | - |
400 | return extractHeaderField(fontData, Tag_MinLeftBearing).value<qreal>(); never executed: return extractHeaderField(fontData, Tag_MinLeftBearing).value<qreal>(); | 0 |
401 | } | - |
402 | | - |
403 | qreal QFontEngineQPA::minRightBearing() const | - |
404 | { | - |
405 | return extractHeaderField(fontData, Tag_MinRightBearing).value<qreal>(); never executed: return extractHeaderField(fontData, Tag_MinRightBearing).value<qreal>(); | 0 |
406 | } | - |
407 | | - |
408 | QFixed QFontEngineQPA::underlinePosition() const | - |
409 | { | - |
410 | return QFixed::fromReal(extractHeaderField(fontData, Tag_UnderlinePosition).value<qreal>()); never executed: return QFixed::fromReal(extractHeaderField(fontData, Tag_UnderlinePosition).value<qreal>()); | 0 |
411 | } | - |
412 | | - |
413 | QFixed QFontEngineQPA::lineThickness() const | - |
414 | { | - |
415 | return QFixed::fromReal(extractHeaderField(fontData, Tag_LineThickness).value<qreal>()); never executed: return QFixed::fromReal(extractHeaderField(fontData, Tag_LineThickness).value<qreal>()); | 0 |
416 | } | - |
417 | | - |
418 | QFontEngine::Type QFontEngineQPA::type() const | - |
419 | { | - |
420 | return QFontEngine::QPF2; never executed: return QFontEngine::QPF2; | 0 |
421 | } | - |
422 | | - |
423 | bool QFontEngineQPA::canRender(const QChar *string, int len) | - |
424 | { | - |
425 | const uchar *cmap = externalCMap ? externalCMap : (fontData + cmapOffset); never evaluated: externalCMap | 0 |
426 | | - |
427 | if (symbol) { | 0 |
428 | for (int i = 0; i < len; ++i) { | 0 |
429 | unsigned int uc = getChar(string, i, len); | - |
430 | glyph_t g = getTrueTypeGlyphIndex(cmap, uc); | - |
431 | if(!g && uc < 0x100) never evaluated: uc < 0x100 | 0 |
432 | g = getTrueTypeGlyphIndex(cmap, uc + 0xf000); never executed: g = getTrueTypeGlyphIndex(cmap, uc + 0xf000); | 0 |
433 | if (!g) | 0 |
434 | return false; never executed: return false; | 0 |
435 | } | 0 |
436 | } else { | 0 |
437 | for (int i = 0; i < len; ++i) { | 0 |
438 | unsigned int uc = getChar(string, i, len); | - |
439 | if (!getTrueTypeGlyphIndex(cmap, uc)) never evaluated: !getTrueTypeGlyphIndex(cmap, uc) | 0 |
440 | return false; never executed: return false; | 0 |
441 | } | 0 |
442 | } | 0 |
443 | return true; never executed: return true; | 0 |
444 | } | - |
445 | | - |
446 | bool QFontEngineQPA::isValid() const | - |
447 | { | - |
448 | return fontData && dataSize && (cmapOffset || externalCMap) | 0 |
449 | && glyphMapOffset && glyphDataOffset && glyphDataSize > 0; never executed: return fontData && dataSize && (cmapOffset || externalCMap) && glyphMapOffset && glyphDataOffset && glyphDataSize > 0; | 0 |
450 | } | - |
451 | | - |
452 | void QPAGenerator::generate() | - |
453 | { | - |
454 | writeHeader(); | - |
455 | writeGMap(); | - |
456 | writeBlock(QFontEngineQPA::GlyphBlock, QByteArray()); | - |
457 | | - |
458 | dev->seek(4); | - |
459 | writeUInt32(0); | - |
460 | } | 0 |
461 | | - |
462 | void QPAGenerator::writeHeader() | - |
463 | { | - |
464 | QFontEngineQPA::Header header; | - |
465 | | - |
466 | header.magic[0] = 'Q'; | - |
467 | header.magic[1] = 'P'; | - |
468 | header.magic[2] = 'F'; | - |
469 | header.magic[3] = '2'; | - |
470 | header.lock = 1; | - |
471 | header.majorVersion = QFontEngineQPA::CurrentMajorVersion; | - |
472 | header.minorVersion = QFontEngineQPA::CurrentMinorVersion; | - |
473 | header.dataSize = 0; | - |
474 | dev->write((const char *)&header, sizeof(header)); | - |
475 | | - |
476 | writeTaggedString(QFontEngineQPA::Tag_FontName, fe->fontDef.family.toUtf8()); | - |
477 | | - |
478 | QFontEngine::FaceId face = fe->faceId(); | - |
479 | writeTaggedString(QFontEngineQPA::Tag_FileName, face.filename); | - |
480 | writeTaggedUInt32(QFontEngineQPA::Tag_FileIndex, face.index); | - |
481 | | - |
482 | { | - |
483 | uchar data[4]; | - |
484 | uint len = 4; | - |
485 | bool ok = fe->getSfntTableData(( (((quint32)('h')) << 24) | (((quint32)('e')) << 16) | (((quint32)('a')) << 8) | ((quint32)('d')) ), data, &len); | - |
486 | if (ok) { | 0 |
487 | const quint32 revision = qFromBigEndian<quint32>(data); | - |
488 | writeTaggedUInt32(QFontEngineQPA::Tag_FontRevision, revision); | - |
489 | } | 0 |
490 | } | - |
491 | | - |
492 | writeTaggedQFixed(QFontEngineQPA::Tag_Ascent, fe->ascent()); | - |
493 | writeTaggedQFixed(QFontEngineQPA::Tag_Descent, fe->descent()); | - |
494 | writeTaggedQFixed(QFontEngineQPA::Tag_Leading, fe->leading()); | - |
495 | writeTaggedQFixed(QFontEngineQPA::Tag_XHeight, fe->xHeight()); | - |
496 | writeTaggedQFixed(QFontEngineQPA::Tag_AverageCharWidth, fe->averageCharWidth()); | - |
497 | writeTaggedQFixed(QFontEngineQPA::Tag_MaxCharWidth, QFixed::fromReal(fe->maxCharWidth())); | - |
498 | writeTaggedQFixed(QFontEngineQPA::Tag_LineThickness, fe->lineThickness()); | - |
499 | writeTaggedQFixed(QFontEngineQPA::Tag_MinLeftBearing, QFixed::fromReal(fe->minLeftBearing())); | - |
500 | writeTaggedQFixed(QFontEngineQPA::Tag_MinRightBearing, QFixed::fromReal(fe->minRightBearing())); | - |
501 | writeTaggedQFixed(QFontEngineQPA::Tag_UnderlinePosition, fe->underlinePosition()); | - |
502 | writeTaggedUInt8(QFontEngineQPA::Tag_PixelSize, fe->fontDef.pixelSize); | - |
503 | writeTaggedUInt8(QFontEngineQPA::Tag_Weight, fe->fontDef.weight); | - |
504 | writeTaggedUInt8(QFontEngineQPA::Tag_Style, fe->fontDef.style); | - |
505 | | - |
506 | writeTaggedUInt8(QFontEngineQPA::Tag_GlyphFormat, QFontEngineQPA::AlphamapGlyphs); | - |
507 | | - |
508 | writeTaggedString(QFontEngineQPA::Tag_EndOfHeader, QByteArray()); | - |
509 | align4(); | - |
510 | | - |
511 | const quint64 size = dev->pos(); | - |
512 | header.dataSize = qToBigEndian<quint16>(size - sizeof(header)); | - |
513 | dev->seek(0); | - |
514 | dev->write((const char *)&header, sizeof(header)); | - |
515 | dev->seek(size); | - |
516 | } | 0 |
517 | | - |
518 | void QPAGenerator::writeGMap() | - |
519 | { | - |
520 | const quint16 glyphCount = fe->glyphCount(); | - |
521 | | - |
522 | writeUInt16(QFontEngineQPA::GMapBlock); | - |
523 | writeUInt16(0); | - |
524 | writeUInt32(glyphCount * 4); | - |
525 | | - |
526 | QByteArray &buffer = dev->buffer(); | - |
527 | const int numBytes = glyphCount * sizeof(quint32); | - |
528 | qint64 pos = buffer.size(); | - |
529 | buffer.resize(pos + numBytes); | - |
530 | memset(buffer.data() + pos, 0xff, numBytes); | - |
531 | dev->seek(pos + numBytes); | - |
532 | } | 0 |
533 | | - |
534 | void QPAGenerator::writeBlock(QFontEngineQPA::BlockTag tag, const QByteArray &data) | - |
535 | { | - |
536 | writeUInt16(tag); | - |
537 | writeUInt16(0); | - |
538 | const int padSize = ((data.size() + 3) / 4) * 4 - data.size(); | - |
539 | writeUInt32(data.size() + padSize); | - |
540 | dev->write(data); | - |
541 | for (int i = 0; i < padSize; ++i) never evaluated: i < padSize | 0 |
542 | writeUInt8(0); never executed: writeUInt8(0); | 0 |
543 | } | 0 |
544 | | - |
545 | void QPAGenerator::writeTaggedString(QFontEngineQPA::HeaderTag tag, const QByteArray &string) | - |
546 | { | - |
547 | writeUInt16(tag); | - |
548 | writeUInt16(string.length()); | - |
549 | dev->write(string); | - |
550 | } | 0 |
551 | | - |
552 | void QPAGenerator::writeTaggedUInt32(QFontEngineQPA::HeaderTag tag, quint32 value) | - |
553 | { | - |
554 | writeUInt16(tag); | - |
555 | writeUInt16(sizeof(value)); | - |
556 | writeUInt32(value); | - |
557 | } | 0 |
558 | | - |
559 | void QPAGenerator::writeTaggedUInt8(QFontEngineQPA::HeaderTag tag, quint8 value) | - |
560 | { | - |
561 | writeUInt16(tag); | - |
562 | writeUInt16(sizeof(value)); | - |
563 | writeUInt8(value); | - |
564 | } | 0 |
565 | | - |
566 | void QPAGenerator::writeTaggedQFixed(QFontEngineQPA::HeaderTag tag, QFixed value) | - |
567 | { | - |
568 | writeUInt16(tag); | - |
569 | writeUInt16(sizeof(quint32)); | - |
570 | writeUInt32(value.value()); | - |
571 | } | 0 |
572 | | - |
573 | | - |
574 | | - |
575 | | - |
576 | | - |
577 | | - |
578 | | - |
579 | QFontEngineMultiQPA::QFontEngineMultiQPA(QFontEngine *fe, int _script, const QStringList &fallbacks) | - |
580 | : QFontEngineMulti(fallbacks.size() + 1), | - |
581 | fallbackFamilies(fallbacks), script(_script) | - |
582 | , fallbacksQueried(true) | - |
583 | { | - |
584 | init(fe); | - |
585 | } | 0 |
586 | | - |
587 | QFontEngineMultiQPA::QFontEngineMultiQPA(QFontEngine *fe, int _script) | - |
588 | : QFontEngineMulti(2) | - |
589 | , script(_script) | - |
590 | , fallbacksQueried(false) | - |
591 | { | - |
592 | fallbackFamilies << QString(); | - |
593 | init(fe); | - |
594 | } executed: } Execution Count:600 | 600 |
595 | | - |
596 | void QFontEngineMultiQPA::init(QFontEngine *fe) | - |
597 | { | - |
598 | qt_noop(); | - |
599 | engines[0] = fe; | - |
600 | fe->ref.ref(); | - |
601 | fontDef = engines[0]->fontDef; | - |
602 | setObjectName(QString::fromUtf8("" "QFontEngineMultiQPA" "", sizeof("QFontEngineMultiQPA") - 1)); | - |
603 | } executed: } Execution Count:600 | 600 |
604 | | - |
605 | void QFontEngineMultiQPA::loadEngine(int at) | - |
606 | { | - |
607 | ensureFallbackFamiliesQueried(); | - |
608 | qt_noop(); | - |
609 | qt_noop(); | - |
610 | QFontDef request = fontDef; | - |
611 | request.styleStrategy |= QFont::NoFontMerging; | - |
612 | request.family = fallbackFamilies.at(at-1); | - |
613 | engines[at] = QFontDatabase::findFont(script, | - |
614 | 0, | - |
615 | request, false); | - |
616 | qt_noop(); | - |
617 | engines[at]->ref.ref(); | - |
618 | engines[at]->fontDef = request; | - |
619 | } executed: } Execution Count:9 | 9 |
620 | void QFontEngineMultiQPA::ensureFallbackFamiliesQueried() | - |
621 | { | - |
622 | if (fallbacksQueried) partially evaluated: fallbacksQueried yes Evaluation Count:249027 | no Evaluation Count:0 |
| 0-249027 |
623 | return; executed: return; Execution Count:249027 | 249027 |
624 | QStringList fallbacks = QGuiApplicationPrivate::instance()->platformIntegration()->fontDatabase()->fallbacksForFamily(engine(0)->fontDef.family, QFont::Style(engine(0)->fontDef.style) | - |
625 | , QFont::AnyStyle, QUnicodeTables::Script(script)); | - |
626 | setFallbackFamiliesList(fallbacks); | - |
627 | } | 0 |
628 | | - |
629 | void QFontEngineMultiQPA::setFallbackFamiliesList(const QStringList &fallbacks) | - |
630 | { | - |
631 | | - |
632 | QFontEngine *fe = engines[0]; | - |
633 | fallbackFamilies = fallbacks; | - |
634 | if (!fallbackFamilies.isEmpty()) { partially evaluated: !fallbackFamilies.isEmpty() yes Evaluation Count:600 | no Evaluation Count:0 |
| 0-600 |
635 | engines.fill(0, fallbackFamilies.size() + 1); | - |
636 | engines[0] = fe; | - |
637 | } else { executed: } Execution Count:600 | 600 |
638 | | - |
639 | fallbackFamilies << fe->fontDef.family; | - |
640 | engines[1] = fe; | - |
641 | fe->ref.ref(); | - |
642 | } | 0 |
643 | fallbacksQueried = true; | - |
644 | } executed: } Execution Count:600 | 600 |
645 | QFontEngine* QFontEngineMultiQPA::createMultiFontEngine(QFontEngine *fe, int script) | - |
646 | { | - |
647 | QFontEngine *engine = 0; | - |
648 | QFontCache::Key key(fe->fontDef, script, true); | - |
649 | QFontCache *fc = QFontCache::instance(); | - |
650 | | - |
651 | | - |
652 | | - |
653 | | - |
654 | | - |
655 | const bool faceIsLocal = !fe->faceId().filename.isEmpty(); | - |
656 | QFontCache::EngineCache::Iterator it = fc->engineCache.find(key), | - |
657 | end = fc->engineCache.end(); | - |
658 | while (it != end && it.key() == key) { never evaluated: it != end never evaluated: it.key() == key | 0 |
659 | QFontEngineMulti *cachedEngine = qobject_cast<QFontEngineMulti *>(it.value().data); | - |
660 | if (faceIsLocal || (cachedEngine && fe == cachedEngine->engine(0))) { never evaluated: faceIsLocal never evaluated: cachedEngine never evaluated: fe == cachedEngine->engine(0) | 0 |
661 | engine = cachedEngine; | - |
662 | fc->updateHitCountAndTimeStamp(it.value()); | - |
663 | break; | 0 |
664 | } | - |
665 | it++; | - |
666 | } | 0 |
667 | if (!engine) { | 0 |
668 | engine = QGuiApplicationPrivate::instance()->platformIntegration()->fontDatabase()->fontEngineMulti(fe, QUnicodeTables::Script(script)); | - |
669 | QFontCache::instance()->insertEngine(key, engine, !faceIsLocal); | - |
670 | } | 0 |
671 | qt_noop(); | - |
672 | return engine; never executed: return engine; | 0 |
673 | } | - |
674 | | - |
675 | | - |
676 | | - |
| | |