qfontsubset.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/text/qfontsubset.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8static const unsigned short symbol_map[0x100] = {-
9 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,-
10 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,-
11 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,-
12 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,-
13 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220b,-
14 0x0028, 0x0029, 0x2217, 0x002b, 0x002c, 0x2212, 0x002e, 0x002f,-
15 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,-
16 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,-
17-
18 0x2245, 0x0391, 0x0392, 0x03a7, 0x0394, 0x0395, 0x03a6, 0x0393,-
19 0x0397, 0x0399, 0x03d1, 0x039a, 0x039b, 0x039c, 0x039d, 0x039f,-
20 0x03a0, 0x0398, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03c2, 0x03a9,-
21 0x039e, 0x03a8, 0x0396, 0x005b, 0x2234, 0x005d, 0x22a5, 0x005f,-
22 0xf8e5, 0x03b1, 0x03b2, 0x03c7, 0x03b4, 0x03b5, 0x03c6, 0x03b3,-
23 0x03b7, 0x03b9, 0x03d5, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03bf,-
24 0x03c0, 0x03b8, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03d6, 0x03c9,-
25 0x03be, 0x03c8, 0x03b6, 0x007b, 0x007c, 0x007d, 0x223c, 0x007f,-
26-
27 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,-
28 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,-
29 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,-
30 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,-
31 0x20ac, 0x03d2, 0x2023, 0x2264, 0x2044, 0x221e, 0x0192, 0x2263,-
32 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,-
33 0x00b0, 0x00b1, 0x2033, 0x2265, 0x00d7, 0x221d, 0x2202, 0x2022,-
34 0x00f7, 0x2260, 0x2261, 0x2248, 0x2026, 0xf8e6, 0xf8e7, 0x21b5,-
35-
36 0x2135, 0x2111, 0x211c, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,-
37 0x222a, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,-
38 0x2220, 0x2207, 0xf6da, 0xf6d9, 0xf6db, 0x220f, 0x221a, 0x22c5,-
39 0x00ac, 0x2227, 0x2228, 0x21d4, 0x21d0, 0x21d1, 0x21d2, 0x21d3,-
40 0x25ca, 0x2329, 0xf8e8, 0xf8e9, 0xf8ea, 0x2211, 0xf8eb, 0xf8ec,-
41 0xf8ed, 0xf8ee, 0xf8ef, 0xf8f0, 0xf8f1, 0xf8f2, 0xf8f3, 0xf8f4,-
42 0x0000, 0x232a, 0x222b, 0x2320, 0xf8f5, 0x2321, 0xf8f6, 0xf8f7,-
43 0xf8f8, 0xf8f9, 0xf8fa, 0xf8fb, 0xf8fc, 0xf8fd, 0xf8fe, 0x0000-
44};-
45-
46-
47-
48-
49-
50QByteArray QFontSubset::glyphName(unsigned short unicode, bool symbol)-
51{-
52 if (symbol
symbolDescription
TRUEnever evaluated
FALSEnever evaluated
&& unicode < 0x100
unicode < 0x100Description
TRUEnever evaluated
FALSEnever evaluated
)
0
53-
54 unicode = symbol_map[unicode];
never executed: unicode = symbol_map[unicode];
0
55-
56 const AGLEntry *r = std::lower_bound(unicode_to_agl_map, unicode_to_agl_map + unicode_to_agl_map_size, unicode);-
57 if ((
(r != unicode_..._agl_map_size)Description
TRUEnever evaluated
FALSEnever evaluated
r != unicode_to_agl_map + unicode_to_agl_map_size)
(r != unicode_..._agl_map_size)Description
TRUEnever evaluated
FALSEnever evaluated
&& !(unicode < *r)
!(unicode < *r)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
58 return
never executed: return glyph_names + r->index;
glyph_names + r->index;
never executed: return glyph_names + r->index;
0
59-
60 char buffer[8];-
61 buffer[0] = 'u';-
62 buffer[1] = 'n';-
63 buffer[2] = 'i';-
64 QPdf::toHex(unicode, buffer+3);-
65 return
never executed: return buffer;
buffer;
never executed: return buffer;
0
66}-
67-
68QByteArray QFontSubset::glyphName(unsigned int glyph, const QVector<int> &reverseMap) const-
69{-
70 uint glyphIndex = glyph_indices[glyph];-
71-
72 if (glyphIndex == 0
glyphIndex == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
73 return
never executed: return "/.notdef";
"/.notdef";
never executed: return "/.notdef";
0
74-
75 QByteArray ba;-
76 QPdf::ByteStream s(&ba);-
77 if (reverseMap[glyphIndex]
reverseMap[glyphIndex]Description
TRUEnever evaluated
FALSEnever evaluated
&& reverseMap[glyphIndex] < 0x10000
reverseMap[gly...dex] < 0x10000Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
78 s << '/' << glyphName(reverseMap[glyphIndex], false);-
79 }
never executed: end of block
else {
0
80 s << "/gl" << (int)glyphIndex;-
81 }
never executed: end of block
0
82 return
never executed: return ba;
ba;
never executed: return ba;
0
83}-
84-
85-
86QByteArray QFontSubset::widthArray() const-
87{-
88 ((!(!widths.isEmpty())) ? qt_assert("!widths.isEmpty()",__FILE__,133) : qt_noop());-
89-
90 QFontEngine::Properties properties = fontEngine->properties();-
91-
92 QByteArray width;-
93 QPdf::ByteStream s(&width);-
94 QFixed scale = QFixed(1000)/emSquare;-
95-
96 QFixed defWidth = widths[0];-
97-
98 for (int i = 0; i < nGlyphs()
i < nGlyphs()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
99 if (defWidth != widths[i]
defWidth != widths[i]Description
TRUEnever evaluated
FALSEnever evaluated
)
0
100 defWidth = 0;
never executed: defWidth = 0;
0
101 }
never executed: end of block
0
102 if (defWidth > 0
defWidth > 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
103 s << "/DW " << (defWidth*scale).toInt();-
104 }
never executed: end of block
else {
0
105 s << "/W [";-
106 for (int g = 0; g < nGlyphs()
g < nGlyphs()Description
TRUEnever evaluated
FALSEnever evaluated
;) {
0
107 QFixed w = widths[g];-
108 int start = g;-
109 int startLinear = 0;-
110 ++g;-
111 while (g < nGlyphs()
g < nGlyphs()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
112 QFixed nw = widths[g];-
113 if (nw == w
nw == wDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
114 if (!startLinear
!startLinearDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
115 startLinear = g - 1;
never executed: startLinear = g - 1;
0
116 }
never executed: end of block
else {
0
117 if (startLinear > 0
startLinear > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& g - startLinear >= 10
g - startLinear >= 10Description
TRUEnever evaluated
FALSEnever evaluated
)
0
118 break;
never executed: break;
0
119 startLinear = 0;-
120 }
never executed: end of block
0
121 w = nw;-
122 ++g;-
123 }
never executed: end of block
0
124-
125 if (g - startLinear < 10
g - startLinear < 10Description
TRUEnever evaluated
FALSEnever evaluated
)
0
126 startLinear = 0;
never executed: startLinear = 0;
0
127 int endnonlinear = startLinear
startLinearDescription
TRUEnever evaluated
FALSEnever evaluated
? startLinear : g;
0
128-
129 if (endnonlinear > start
endnonlinear > startDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
130 s << start << '[';-
131 for (int i = start; i < endnonlinear
i < endnonlinearDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
132 s << (widths[i]*scale).toInt();
never executed: s << (widths[i]*scale).toInt();
0
133 s << "]\n";-
134 }
never executed: end of block
0
135 if (startLinear
startLinearDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
136 s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << '\n';
never executed: s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << '\n';
0
137 }
never executed: end of block
0
138 s << "]\n";-
139 }
never executed: end of block
0
140 return
never executed: return width;
width;
never executed: return width;
0
141}-
142-
143static void checkRanges(QPdf::ByteStream &ts, QByteArray &ranges, int &nranges)-
144{-
145 if (++
++nranges > 100Description
TRUEnever evaluated
FALSEnever evaluated
nranges > 100
++nranges > 100Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
146 ts << nranges << "beginbfrange\n"-
147 << ranges << "endbfrange\n";-
148 ranges = QByteArray();-
149 nranges = 0;-
150 }
never executed: end of block
0
151}
never executed: end of block
0
152-
153QVector<int> QFontSubset::getReverseMap() const-
154{-
155 QVector<int> reverseMap(0x10000, 0);-
156 for (uint uc = 0; uc < 0x10000
uc < 0x10000Description
TRUEnever evaluated
FALSEnever evaluated
; ++uc) {
0
157 int idx = glyph_indices.indexOf(fontEngine->glyphIndex(uc));-
158 if (idx >= 0
idx >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& !reverseMap.at(idx)
!reverseMap.at(idx)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
159 reverseMap[idx] = uc;
never executed: reverseMap[idx] = uc;
0
160 }
never executed: end of block
0
161 return
never executed: return reverseMap;
reverseMap;
never executed: return reverseMap;
0
162}-
163-
164QByteArray QFontSubset::createToUnicodeMap() const-
165{-
166 QVector<int> reverseMap = getReverseMap();-
167-
168 QByteArray touc;-
169 QPdf::ByteStream ts(&touc);-
170 ts << "/CIDInit /ProcSet findresource begin\n"-
171 "12 dict begin\n"-
172 "begincmap\n"-
173 "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n"-
174 "/CMapName /Adobe-Identity-UCS def\n"-
175 "/CMapType 2 def\n"-
176 "1 begincodespacerange\n"-
177 "<0000> <FFFF>\n"-
178 "endcodespacerange\n";-
179-
180 int nranges = 1;-
181 QByteArray ranges = "<0000> <0000> <0000>\n";-
182 QPdf::ByteStream s(&ranges);-
183-
184 char buf[5];-
185 for (int g = 1; g < nGlyphs()
g < nGlyphs()Description
TRUEnever evaluated
FALSEnever evaluated
; ) {
0
186 int uc0 = reverseMap.at(g);-
187 if (!uc0
!uc0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
188 ++g;-
189 continue;
never executed: continue;
0
190 }-
191 int start = g;-
192 int startLinear = 0;-
193 ++g;-
194 while (g < nGlyphs()
g < nGlyphs()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
195 int uc = reverseMap[g];-
196-
197 if (!uc
!ucDescription
TRUEnever evaluated
FALSEnever evaluated
|| (
(g>>8) != (start >> 8)Description
TRUEnever evaluated
FALSEnever evaluated
g>>8) != (start >> 8)
(g>>8) != (start >> 8)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
198 break;
never executed: break;
0
199 if (uc == uc0 + 1
uc == uc0 + 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
200 if (!startLinear
!startLinearDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
201 startLinear = g - 1;
never executed: startLinear = g - 1;
0
202 }
never executed: end of block
else {
0
203 if (startLinear > 0
startLinear > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& g - startLinear >= 10
g - startLinear >= 10Description
TRUEnever evaluated
FALSEnever evaluated
)
0
204 break;
never executed: break;
0
205 startLinear = 0;-
206 }
never executed: end of block
0
207 uc0 = uc;-
208 ++g;-
209 }
never executed: end of block
0
210-
211 if (g - startLinear < 10
g - startLinear < 10Description
TRUEnever evaluated
FALSEnever evaluated
)
0
212 startLinear = 0;
never executed: startLinear = 0;
0
213 int endnonlinear = startLinear
startLinearDescription
TRUEnever evaluated
FALSEnever evaluated
? startLinear : g;
0
214-
215 if (endnonlinear > start
endnonlinear > startDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
216 s << '<' << QPdf::toHex((ushort)start, buf) << "> <";-
217 s << QPdf::toHex((ushort)(endnonlinear - 1), buf) << "> ";-
218 if (endnonlinear == start + 1
endnonlinear == start + 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
219 s << '<' << QPdf::toHex((ushort)reverseMap[start], buf) << ">\n";-
220 }
never executed: end of block
else {
0
221 s << '[';-
222 for (int i = start; i < endnonlinear
i < endnonlinearDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
223 s << '<' << QPdf::toHex((ushort)reverseMap[i], buf) << "> ";-
224 }
never executed: end of block
0
225 s << "]\n";-
226 }
never executed: end of block
0
227 checkRanges(ts, ranges, nranges);-
228 }
never executed: end of block
0
229 if (startLinear
startLinearDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
230 while (startLinear < g
startLinear < gDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
231 int len = g - startLinear;-
232 int uc_start = reverseMap[startLinear];-
233 int uc_end = uc_start + len - 1;-
234 if ((
(uc_end >> 8) ...uc_start >> 8)Description
TRUEnever evaluated
FALSEnever evaluated
uc_end >> 8) != (uc_start >> 8)
(uc_end >> 8) ...uc_start >> 8)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
235 len = 256 - (uc_start & 0xff);
never executed: len = 256 - (uc_start & 0xff);
0
236 s << '<' << QPdf::toHex((ushort)startLinear, buf) << "> <";-
237 s << QPdf::toHex((ushort)(startLinear + len - 1), buf) << "> ";-
238 s << '<' << QPdf::toHex((ushort)reverseMap[startLinear], buf) << ">\n";-
239 checkRanges(ts, ranges, nranges);-
240 startLinear += len;-
241 }
never executed: end of block
0
242 }
never executed: end of block
0
243 }
never executed: end of block
0
244 if (nranges
nrangesDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
245 ts << nranges << "beginbfrange\n"-
246 << ranges << "endbfrange\n";-
247 }
never executed: end of block
0
248 ts << "endcmap\n"-
249 "CMapName currentdict /CMap defineresource pop\n"-
250 "end\n"-
251 "end\n";-
252-
253 return
never executed: return touc;
touc;
never executed: return touc;
0
254}-
255-
256int QFontSubset::addGlyph(int index)-
257{-
258 int idx = glyph_indices.indexOf(index);-
259 if (idx < 0
idx < 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
260 idx = glyph_indices.size();-
261 glyph_indices.append(index);-
262 }
never executed: end of block
0
263 return
never executed: return idx;
idx;
never executed: return idx;
0
264}-
265-
266-
267-
268-
269-
270typedef qint16 F2DOT14;-
271typedef quint32 Tag;-
272typedef quint16 GlyphID;-
273typedef quint16 Offset;-
274-
275-
276class QTtfStream {-
277public:-
278 QTtfStream(QByteArray &ba) : data((uchar *)ba.data()) { start = data; }
never executed: end of block
0
279 QTtfStream &operator <<(quint8 v) { *data = v; ++data; return
never executed: return *this;
*this;
never executed: return *this;
}
0
280 QTtfStream &operator <<(quint16 v) { qToBigEndian(v, data); data += sizeof(v); return
never executed: return *this;
*this;
never executed: return *this;
}
0
281 QTtfStream &operator <<(quint32 v) { qToBigEndian(v, data); data += sizeof(v); return
never executed: return *this;
*this;
never executed: return *this;
}
0
282 QTtfStream &operator <<(qint8 v) { *data = quint8(v); ++data; return
never executed: return *this;
*this;
never executed: return *this;
}
0
283 QTtfStream &operator <<(qint16 v) { qToBigEndian(v, data); data += sizeof(v); return
never executed: return *this;
*this;
never executed: return *this;
}
0
284 QTtfStream &operator <<(qint32 v) { qToBigEndian(v, data); data += sizeof(v); return
never executed: return *this;
*this;
never executed: return *this;
}
0
285 QTtfStream &operator <<(qint64 v) { qToBigEndian(v, data); data += sizeof(v); return
never executed: return *this;
*this;
never executed: return *this;
}
0
286-
287 int offset() const { return
never executed: return data - start;
data - start;
never executed: return data - start;
}
0
288 void setOffset(int o) { data = start + o; }
never executed: end of block
0
289 void align4() { while (offset() & 3
offset() & 3Description
TRUEnever evaluated
FALSEnever evaluated
) { *data = '\0'; ++data; }
never executed: end of block
}
never executed: end of block
0
290private:-
291 uchar *data;-
292 uchar *start;-
293};-
294-
295struct QTtfTable {-
296 Tag tag;-
297 QByteArray data;-
298};-
299template<> class QTypeInfo<QTtfTable > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QTtfTable)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QTtfTable >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QTtfTable) }; static inline const char *name() { return "QTtfTable"; } };-
300-
301-
302struct qttf_head_table {-
303 qint32 font_revision;-
304 quint16 flags;-
305 qint64 created;-
306 qint64 modified;-
307 qint16 xMin;-
308 qint16 yMin;-
309 qint16 xMax;-
310 qint16 yMax;-
311 quint16 macStyle;-
312 qint16 indexToLocFormat;-
313};-
314template<> class QTypeInfo<qttf_head_table > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(qttf_head_table)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< qttf_head_table >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(qttf_head_table) }; static inline const char *name() { return "qttf_head_table"; } };-
315-
316-
317struct qttf_hhea_table {-
318 qint16 ascender;-
319 qint16 descender;-
320 qint16 lineGap;-
321 quint16 maxAdvanceWidth;-
322 qint16 minLeftSideBearing;-
323 qint16 minRightSideBearing;-
324 qint16 xMaxExtent;-
325 quint16 numberOfHMetrics;-
326};-
327template<> class QTypeInfo<qttf_hhea_table > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(qttf_hhea_table)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< qttf_hhea_table >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(qttf_hhea_table) }; static inline const char *name() { return "qttf_hhea_table"; } };-
328-
329-
330struct qttf_maxp_table {-
331 quint16 numGlyphs;-
332 quint16 maxPoints;-
333 quint16 maxContours;-
334 quint16 maxCompositePoints;-
335 quint16 maxCompositeContours;-
336 quint16 maxComponentElements;-
337 quint16 maxComponentDepth;-
338};-
339template<> class QTypeInfo<qttf_maxp_table > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(qttf_maxp_table)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< qttf_maxp_table >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(qttf_maxp_table) }; static inline const char *name() { return "qttf_maxp_table"; } };-
340-
341struct qttf_name_table {-
342 QString copyright;-
343 QString family;-
344 QString subfamily;-
345 QString postscript_name;-
346};-
347template<> class QTypeInfo<qttf_name_table > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(qttf_name_table)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< qttf_name_table >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(qttf_name_table) }; static inline const char *name() { return "qttf_name_table"; } };-
348-
349-
350static QTtfTable generateHead(const qttf_head_table &head);-
351static QTtfTable generateHhea(const qttf_hhea_table &hhea);-
352static QTtfTable generateMaxp(const qttf_maxp_table &maxp);-
353static QTtfTable generateName(const qttf_name_table &name);-
354-
355struct qttf_font_tables-
356{-
357 qttf_head_table head;-
358 qttf_hhea_table hhea;-
359 qttf_maxp_table maxp;-
360};-
361-
362-
363struct QTtfGlyph {-
364 quint16 index;-
365 qint16 xMin;-
366 qint16 xMax;-
367 qint16 yMin;-
368 qint16 yMax;-
369 quint16 advanceWidth;-
370 qint16 lsb;-
371 quint16 numContours;-
372 quint16 numPoints;-
373 QByteArray data;-
374};-
375template<> class QTypeInfo<QTtfGlyph > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QTtfGlyph)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QTtfGlyph >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QTtfGlyph) }; static inline const char *name() { return "QTtfGlyph"; } };-
376-
377static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem);-
378-
379static QVector<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QVector<QTtfGlyph> &_glyphs);-
380-
381static QByteArray bindFont(const QVector<QTtfTable>& _tables);-
382-
383-
384static quint32 checksum(const QByteArray &table)-
385{-
386 quint32 sum = 0;-
387 int offset = 0;-
388 const uchar *d = (const uchar *)table.constData();-
389 while (offset <= table.size()-3
offset <= table.size()-3Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
390 sum += qFromBigEndian<quint32>(d + offset);-
391 offset += 4;-
392 }
never executed: end of block
0
393 int shift = 24;-
394 quint32 x = 0;-
395 while (offset < table.size()
offset < table.size()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
396 x |= ((quint32)d[offset]) << shift;-
397 ++offset;-
398 shift -= 8;-
399 }
never executed: end of block
0
400 sum += x;-
401-
402 return
never executed: return sum;
sum;
never executed: return sum;
0
403}-
404-
405static QTtfTable generateHead(const qttf_head_table &head)-
406{-
407 const int head_size = 54;-
408 QTtfTable t;-
409 t.tag = ( (((quint32)('h')) << 24) | (((quint32)('e')) << 16) | (((quint32)('a')) << 8) | ((quint32)('d')) );-
410 t.data.resize(head_size);-
411-
412 QTtfStream s(t.data);-
413-
414-
415-
416 s << qint32(0x00010000)-
417 << head.font_revision-
418-
419 << quint32(0)-
420-
421 << quint32(0x5F0F3CF5)-
422 << quint16(0)-
423-
424-
425 << quint16(2048)-
426-
427 << head.created-
428-
429 << head.modified-
430-
431-
432-
433-
434 << head.xMin-
435 << head.yMin-
436 << head.xMax-
437 << head.yMax-
438 << head.macStyle-
439-
440 << quint16(6)-
441-
442 << qint16(0)-
443-
444-
445-
446-
447-
448 << head.indexToLocFormat-
449-
450 << qint16(0);-
451-
452 ((!(s.offset() == head_size)) ? qt_assert("s.offset() == head_size",__FILE__,516) : qt_noop());-
453 return
never executed: return t;
t;
never executed: return t;
0
454}-
455-
456-
457static QTtfTable generateHhea(const qttf_hhea_table &hhea)-
458{-
459 const int hhea_size = 36;-
460 QTtfTable t;-
461 t.tag = ( (((quint32)('h')) << 24) | (((quint32)('h')) << 16) | (((quint32)('e')) << 8) | ((quint32)('a')) );-
462 t.data.resize(hhea_size);-
463-
464 QTtfStream s(t.data);-
465-
466 s << qint32(0x00010000)-
467-
468 << hhea.ascender-
469-
470 << hhea.descender-
471-
472-
473-
474-
475 << hhea.lineGap-
476-
477 << hhea.maxAdvanceWidth-
478-
479 << hhea.minLeftSideBearing-
480-
481 << hhea.minRightSideBearing-
482-
483 << hhea.xMaxExtent-
484-
485 << qint16(1)-
486-
487 << qint16(0)-
488-
489 << qint16(0)-
490-
491 << qint16(0)-
492-
493 << qint16(0)-
494-
495 << qint16(0)-
496-
497 << qint16(0)-
498-
499 << qint16(0)-
500-
501 << hhea.numberOfHMetrics;-
502-
503 ((!(s.offset() == hhea_size)) ? qt_assert("s.offset() == hhea_size",__FILE__,567) : qt_noop());-
504 return
never executed: return t;
t;
never executed: return t;
0
505}-
506-
507-
508static QTtfTable generateMaxp(const qttf_maxp_table &maxp)-
509{-
510 const int maxp_size = 32;-
511 QTtfTable t;-
512 t.tag = ( (((quint32)('m')) << 24) | (((quint32)('a')) << 16) | (((quint32)('x')) << 8) | ((quint32)('p')) );-
513 t.data.resize(maxp_size);-
514-
515 QTtfStream s(t.data);-
516-
517-
518 s << qint32(0x00010000)-
519-
520 << maxp.numGlyphs-
521-
522 << maxp.maxPoints-
523-
524 << maxp.maxContours-
525-
526 << maxp.maxCompositePoints-
527-
528 << maxp.maxCompositeContours-
529-
530 << quint16(1)-
531-
532 << quint16(0)-
533-
534 << quint16(0)-
535-
536 << quint16(0)-
537-
538 << quint16(0)-
539-
540 << quint16(0)-
541-
542 << quint16(0)-
543-
544 << maxp.maxComponentElements-
545-
546 << maxp.maxComponentDepth;-
547-
548 ((!(s.offset() == maxp_size)) ? qt_assert("s.offset() == maxp_size",__FILE__,612) : qt_noop());-
549 return
never executed: return t;
t;
never executed: return t;
0
550}-
551-
552struct QTtfNameRecord {-
553 quint16 nameId;-
554 QString value;-
555};-
556template<> class QTypeInfo<QTtfNameRecord > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QTtfNameRecord)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QTtfNameRecord >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QTtfNameRecord) }; static inline const char *name() { return "QTtfNameRecord"; } };-
557-
558static QTtfTable generateName(const QVector<QTtfNameRecord> &name);-
559-
560static QTtfTable generateName(const qttf_name_table &name)-
561{-
562 QVector<QTtfNameRecord> list;-
563 list.reserve(5);-
564 QTtfNameRecord rec;-
565 rec.nameId = 0;-
566 rec.value = name.copyright;-
567 list.append(rec);-
568 rec.nameId = 1;-
569 rec.value = name.family;-
570 list.append(rec);-
571 rec.nameId = 2;-
572 rec.value = name.subfamily;-
573 list.append(rec);-
574 rec.nameId = 4;-
575 rec.value = name.family;-
576 if (name.subfamily != QLatin1String("Regular")
name.subfamily...ing("Regular")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
577 rec.value += QLatin1Char(' ') + name.subfamily;
never executed: rec.value += QLatin1Char(' ') + name.subfamily;
0
578 list.append(rec);-
579 rec.nameId = 6;-
580 rec.value = name.postscript_name;-
581 list.append(rec);-
582-
583 return
never executed: return generateName(list);
generateName(list);
never executed: return generateName(list);
0
584}-
585-
586-
587static QTtfTable generateName(const QVector<QTtfNameRecord> &name)-
588{-
589 const int char_size = 2;-
590-
591 QTtfTable t;-
592 t.tag = ( (((quint32)('n')) << 24) | (((quint32)('a')) << 16) | (((quint32)('m')) << 8) | ((quint32)('e')) );-
593-
594 const int name_size = 6 + 12*name.size();-
595 int string_size = 0;-
596 for (int i = 0; i < name.size()
i < name.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
597 string_size += name.at(i).value.length()*char_size;-
598 }
never executed: end of block
0
599 t.data.resize(name_size + string_size);-
600-
601 QTtfStream s(t.data);-
602-
603 s << quint16(0)-
604-
605 << quint16(name.size())-
606-
607 << quint16(name_size);-
608-
609-
610-
611 int off = 0;-
612 for (int i = 0; i < name.size()
i < name.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
613 int len = name.at(i).value.length()*char_size;-
614-
615-
616-
617 s << quint16(3)-
618 << quint16(1)-
619 << quint16(0x0409)-
620-
621 << name.at(i).nameId-
622-
623 << quint16(len)-
624-
625 << quint16(off);-
626 off += len;-
627 }
never executed: end of block
0
628 for (int i = 0; i < name.size()
i < name.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
629 const QString &n = name.at(i).value;-
630 const ushort *uc = n.utf16();-
631 for (int i = 0; i < n.length()
i < n.length()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
632 s << quint16(*uc);-
633 ++uc;-
634 }
never executed: end of block
0
635 }
never executed: end of block
0
636 return
never executed: return t;
t;
never executed: return t;
0
637}-
638-
639-
640enum Flags {-
641 OffCurve = 0,-
642 OnCurve = (1 << 0),-
643 XShortVector = (1 << 1),-
644 YShortVector = (1 << 2),-
645 Repeat = (1 << 3),-
646 XSame = (1 << 4),-
647 XShortPositive = (1 << 4),-
648 YSame = (1 << 5),-
649 YShortPositive = (1 << 5)-
650};-
651struct TTF_POINT {-
652 qint16 x;-
653 qint16 y;-
654 quint8 flags;-
655};-
656template<> class QTypeInfo<TTF_POINT > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(TTF_POINT)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< TTF_POINT >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(TTF_POINT) }; static inline const char *name() { return "TTF_POINT"; } };-
657-
658static void convertPath(const QPainterPath &path, QVector<TTF_POINT> *points, QVector<int> *endPoints, qreal ppem)-
659{-
660 int numElements = path.elementCount();-
661 for (int i = 0; i < numElements - 1
i < numElements - 1Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
662 const QPainterPath::Element &e = path.elementAt(i);-
663 TTF_POINT p;-
664 p.x = qRound(e.x * 2048. / ppem);-
665 p.y = qRound(-e.y * 2048. / ppem);-
666 p.flags = 0;-
667-
668 switch(e.type) {-
669 case
never executed: case QPainterPath::MoveToElement:
QPainterPath::MoveToElement:
never executed: case QPainterPath::MoveToElement:
0
670 if (i != 0
i != 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
671-
672 int start = endPoints->size()
endPoints->size()Description
TRUEnever evaluated
FALSEnever evaluated
? endPoints->at(endPoints->size()-1) - 1 : 0;
0
673 int end = points->size() - 1;-
674 if (points->at(end).x == points->at(start).x
points->at(end...s->at(start).xDescription
TRUEnever evaluated
FALSEnever evaluated
0
675 && points->at(end).y == points->at(start).y
points->at(end...s->at(start).yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
676 points->takeLast();
never executed: points->takeLast();
0
677 endPoints->append(points->size() - 1);-
678 }
never executed: end of block
0
679-
680 case
never executed: case QPainterPath::LineToElement:
QPainterPath::LineToElement:
never executed: case QPainterPath::LineToElement:
code before this statement never executed: case QPainterPath::LineToElement:
0
681 p.flags = OnCurve;-
682 break;
never executed: break;
0
683 case
never executed: case QPainterPath::CurveToElement:
QPainterPath::CurveToElement:
never executed: case QPainterPath::CurveToElement:
{
0
684-
685 TTF_POINT list[3*16 + 4];-
686 list[3] = points->at(points->size() - 1);-
687 list[2] = p;-
688 const QPainterPath::Element &e2 = path.elementAt(++i);-
689 list[1].x = qRound(e2.x * 2048. / ppem);-
690 list[1].y = qRound(-e2.y * 2048. / ppem);-
691 const QPainterPath::Element &e3 = path.elementAt(++i);-
692 list[0].x = qRound(e3.x * 2048. / ppem);-
693 list[0].y = qRound(-e3.y * 2048. / ppem);-
694-
695 TTF_POINT *base = list;-
696-
697 bool try_reduce = points->size() > 1
points->size() > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
698 && points->at(points->size() - 1).flags == OnCurve
points->at(poi...ags == OnCurveDescription
TRUEnever evaluated
FALSEnever evaluated
0
699 && points->at(points->size() - 2).flags == OffCurve
points->at(poi...gs == OffCurveDescription
TRUEnever evaluated
FALSEnever evaluated
;
0
700-
701 while (base >= list
base >= listDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
702 const int split_limit = 3;-
703 ((!(base - list < 3*16 + 1)) ? qt_assert("base - list < 3*16 + 1",__FILE__,775) : qt_noop());-
704-
705 int i1_x = base[1].x + ((base[1].x - base[0].x) >> 1);-
706 int i1_y = base[1].y + ((base[1].y - base[0].y) >> 1);-
707 int i2_x = base[2].x + ((base[2].x - base[3].x) >> 1);-
708 int i2_y = base[2].y + ((base[2].y - base[3].y) >> 1);-
709-
710 if (qAbs(i1_x - i2_x) <= split_limit
qAbs(i1_x - i2...<= split_limitDescription
TRUEnever evaluated
FALSEnever evaluated
&& qAbs(i1_y - i2_y) <= split_limit
qAbs(i1_y - i2...<= split_limitDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
711-
712 TTF_POINT np;-
713 np.x = (i1_x + i2_x) >> 1;-
714 np.y = (i1_y + i2_y) >> 1;-
715 if (try_reduce
try_reduceDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
716-
717 int mx = (points->at(points->size() - 2).x + base[2].x) >> 1;-
718 int my = (points->at(points->size() - 2).y + base[2].y) >> 1;-
719 if (qAbs(mx - base[3].x) <= split_limit
qAbs(mx - base...<= split_limitDescription
TRUEnever evaluated
FALSEnever evaluated
&& qAbs(my = base[3].y) <= split_limit
qAbs(my = base...<= split_limitDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
720 points->takeLast();
never executed: points->takeLast();
0
721 try_reduce = false;-
722 }
never executed: end of block
0
723 np.flags = OffCurve;-
724 points->append(np);-
725-
726 base -= 3;-
727 }
never executed: end of block
else {
0
728-
729-
730 qint16 a, b, c, d;-
731 base[6].x = base[3].x;-
732 c = base[1].x;-
733 d = base[2].x;-
734 base[1].x = a = ( base[0].x + c ) >> 1;-
735 base[5].x = b = ( base[3].x + d ) >> 1;-
736 c = ( c + d ) >> 1;-
737 base[2].x = a = ( a + c ) >> 1;-
738 base[4].x = b = ( b + c ) >> 1;-
739 base[3].x = ( a + b ) >> 1;-
740-
741 base[6].y = base[3].y;-
742 c = base[1].y;-
743 d = base[2].y;-
744 base[1].y = a = ( base[0].y + c ) >> 1;-
745 base[5].y = b = ( base[3].y + d ) >> 1;-
746 c = ( c + d ) >> 1;-
747 base[2].y = a = ( a + c ) >> 1;-
748 base[4].y = b = ( b + c ) >> 1;-
749 base[3].y = ( a + b ) >> 1;-
750 base += 3;-
751 }
never executed: end of block
0
752 }-
753 p = list[0];-
754 p.flags = OnCurve;-
755 break;
never executed: break;
0
756 }-
757 case
never executed: case QPainterPath::CurveToDataElement:
QPainterPath::CurveToDataElement:
never executed: case QPainterPath::CurveToDataElement:
0
758 ((!(false)) ? qt_assert("false",__FILE__,830) : qt_noop());-
759 break;
never executed: break;
0
760 }-
761-
762 points->append(p);-
763 }
never executed: end of block
0
764 int start = endPoints->size()
endPoints->size()Description
TRUEnever evaluated
FALSEnever evaluated
? endPoints->at(endPoints->size()-1) + 1 : 0;
0
765 int end = points->size() - 1;-
766 if (points->at(end).x == points->at(start).x
points->at(end...s->at(start).xDescription
TRUEnever evaluated
FALSEnever evaluated
0
767 && points->at(end).y == points->at(start).y
points->at(end...s->at(start).yDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
768 points->takeLast();
never executed: points->takeLast();
0
769 endPoints->append(points->size() - 1);-
770}
never executed: end of block
0
771-
772static void getBounds(const QVector<TTF_POINT> &points, qint16 *xmin, qint16 *xmax, qint16 *ymin, qint16 *ymax)-
773{-
774 *xmin = points.at(0).x;-
775 *xmax = *xmin;-
776 *ymin = points.at(0).y;-
777 *ymax = *ymin;-
778-
779 for (int i = 1; i < points.size()
i < points.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
780 *xmin = qMin(*xmin, points.at(i).x);-
781 *xmax = qMax(*xmax, points.at(i).x);-
782 *ymin = qMin(*ymin, points.at(i).y);-
783 *ymax = qMax(*ymax, points.at(i).y);-
784 }
never executed: end of block
0
785}
never executed: end of block
0
786-
787static int convertToRelative(QVector<TTF_POINT> *points)-
788{-
789-
790-
791 qint16 prev_x = 0;-
792 qint16 prev_y = 0;-
793 int point_array_size = 0;-
794 for (int i = 0; i < points->size()
i < points->size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
795 const int x = points->at(i).x;-
796 const int y = points->at(i).y;-
797 TTF_POINT rel;-
798 rel.x = x - prev_x;-
799 rel.y = y - prev_y;-
800 rel.flags = points->at(i).flags;-
801 ((!(rel.flags < 2)) ? qt_assert("rel.flags < 2",__FILE__,873) : qt_noop());-
802 if (!rel.x
!rel.xDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
803 rel.flags |= XSame;-
804 }
never executed: end of block
else if (rel.x > 0
rel.x > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& rel.x < 256
rel.x < 256Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
805 rel.flags |= XShortVector|XShortPositive;-
806 point_array_size++;-
807 }
never executed: end of block
else if (rel.x < 0
rel.x < 0Description
TRUEnever evaluated
FALSEnever evaluated
&& rel.x > -256
rel.x > -256Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
808 rel.flags |= XShortVector;-
809 rel.x = -rel.x;-
810 point_array_size++;-
811 }
never executed: end of block
else {
0
812 point_array_size += 2;-
813 }
never executed: end of block
0
814 if (!rel.y
!rel.yDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
815 rel.flags |= YSame;-
816 }
never executed: end of block
else if (rel.y > 0
rel.y > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& rel.y < 256
rel.y < 256Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
817 rel.flags |= YShortVector|YShortPositive;-
818 point_array_size++;-
819 }
never executed: end of block
else if (rel.y < 0
rel.y < 0Description
TRUEnever evaluated
FALSEnever evaluated
&& rel.y > -256
rel.y > -256Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
820 rel.flags |= YShortVector;-
821 rel.y = -rel.y;-
822 point_array_size++;-
823 }
never executed: end of block
else {
0
824 point_array_size += 2;-
825 }
never executed: end of block
0
826 (*points)[i] = rel;-
827-
828-
829-
830-
831-
832-
833-
834 prev_x = x;-
835 prev_y = y;-
836 }
never executed: end of block
0
837 return
never executed: return point_array_size;
point_array_size;
never executed: return point_array_size;
0
838}-
839-
840static void getGlyphData(QTtfGlyph *glyph, const QVector<TTF_POINT> &points, const QVector<int> &endPoints, int point_array_size)-
841{-
842 const int max_size = 5*sizeof(qint16)-
843 + endPoints.size()*sizeof(quint16)-
844 + sizeof(quint16)-
845 + points.size()*(1)-
846 + point_array_size;-
847-
848 glyph->data.resize(max_size);-
849-
850 QTtfStream s(glyph->data);-
851 s << qint16(endPoints.size())-
852 << glyph->xMin << glyph->yMin << glyph->xMax << glyph->yMax;-
853-
854 for (int i = 0; i < endPoints.size()
i < endPoints.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
855 s << quint16(endPoints.at(i));
never executed: s << quint16(endPoints.at(i));
0
856 s << quint16(0);-
857-
858-
859 for (int i = 0; i < points.size()
i < points.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
860 s << quint8(points.at(i).flags);
never executed: s << quint8(points.at(i).flags);
0
861-
862 for (int i = 0; i < points.size()
i < points.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
863 quint8 flags = points.at(i).flags;-
864 qint16 x = points.at(i).x;-
865-
866 if (flags & XShortVector
flags & XShortVectorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
867 s << quint8(x);
never executed: s << quint8(x);
0
868 else if (!(flags & XSame)
!(flags & XSame)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
869 s << qint16(x);
never executed: s << qint16(x);
0
870 }
never executed: end of block
0
871 for (int i = 0; i < points.size()
i < points.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
872 quint8 flags = points.at(i).flags;-
873 qint16 y = points.at(i).y;-
874-
875 if (flags & YShortVector
flags & YShortVectorDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
876 s << quint8(y);
never executed: s << quint8(y);
0
877 else if (!(flags & YSame)
!(flags & YSame)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
878 s << qint16(y);
never executed: s << qint16(y);
0
879 }
never executed: end of block
0
880-
881-
882 ((!(s.offset() == max_size)) ? qt_assert("s.offset() == max_size",__FILE__,954) : qt_noop());-
883-
884 glyph->numContours = endPoints.size();-
885 glyph->numPoints = points.size();-
886}
never executed: end of block
0
887-
888static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem)-
889{-
890 QVector<TTF_POINT> points;-
891 QVector<int> endPoints;-
892 QTtfGlyph glyph;-
893 glyph.index = index;-
894 glyph.advanceWidth = qRound(advance * 2048. / ppem);-
895 glyph.lsb = qRound(lsb * 2048. / ppem);-
896-
897 if (!path.elementCount()
!path.elementCount()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
898-
899 lsb = 0;-
900 glyph.xMin = glyph.xMax = glyph.yMin = glyph.yMax = 0;-
901 glyph.numContours = 0;-
902 glyph.numPoints = 0;-
903 return
never executed: return glyph;
glyph;
never executed: return glyph;
0
904 }-
905-
906 convertPath(path, &points, &endPoints, ppem);-
907 getBounds(points, &glyph.xMin, &glyph.xMax, &glyph.yMin, &glyph.yMax);-
908 int point_array_size = convertToRelative(&points);-
909 getGlyphData(&glyph, points, endPoints, point_array_size);-
910 return
never executed: return glyph;
glyph;
never executed: return glyph;
0
911}-
912-
913static bool operator <(const QTtfGlyph &g1, const QTtfGlyph &g2)-
914{-
915 return
never executed: return g1.index < g2.index;
g1.index < g2.index;
never executed: return g1.index < g2.index;
0
916}-
917-
918static QVector<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QVector<QTtfGlyph> &_glyphs)-
919{-
920 const int max_size_small = 65536*2;-
921 QVector<QTtfGlyph> glyphs = _glyphs;-
922 std::sort(glyphs.begin(), glyphs.end());-
923-
924 ((!(tables.maxp.numGlyphs == glyphs.at(glyphs.size()-1).index + 1)) ? qt_assert("tables.maxp.numGlyphs == glyphs.at(glyphs.size()-1).index + 1",__FILE__,1004) : qt_noop());-
925 int nGlyphs = tables.maxp.numGlyphs;-
926-
927 int glyf_size = 0;-
928 for (int i = 0; i < glyphs.size()
i < glyphs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
929 glyf_size += (glyphs.at(i).data.size() + 3) & ~3;
never executed: glyf_size += (glyphs.at(i).data.size() + 3) & ~3;
0
930-
931 tables.head.indexToLocFormat = glyf_size < max_size_small
glyf_size < max_size_smallDescription
TRUEnever evaluated
FALSEnever evaluated
? 0 : 1;
0
932 tables.hhea.numberOfHMetrics = nGlyphs;-
933-
934 QTtfTable glyf;-
935 glyf.tag = ( (((quint32)('g')) << 24) | (((quint32)('l')) << 16) | (((quint32)('y')) << 8) | ((quint32)('f')) );-
936-
937 QTtfTable loca;-
938 loca.tag = ( (((quint32)('l')) << 24) | (((quint32)('o')) << 16) | (((quint32)('c')) << 8) | ((quint32)('a')) );-
939 loca.data.resize(glyf_size < max_size_small ? (nGlyphs+1)*sizeof(quint16) : (nGlyphs+1)*sizeof(quint32));-
940 QTtfStream ls(loca.data);-
941-
942 QTtfTable hmtx;-
943 hmtx.tag = ( (((quint32)('h')) << 24) | (((quint32)('m')) << 16) | (((quint32)('t')) << 8) | ((quint32)('x')) );-
944 hmtx.data.resize(nGlyphs*4);-
945 QTtfStream hs(hmtx.data);-
946-
947 int pos = 0;-
948 for (int i = 0; i < nGlyphs
i < nGlyphsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
949 int gpos = glyf.data.size();-
950 quint16 advance = 0;-
951 qint16 lsb = 0;-
952-
953 if (glyphs[pos].index == i
glyphs[pos].index == iDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
954-
955-
956 glyf.data += glyphs.at(pos).data;-
957 while (glyf.data.size() & 1
glyf.data.size() & 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
958 glyf.data.append('\0');
never executed: glyf.data.append('\0');
0
959 advance = glyphs.at(pos).advanceWidth;-
960 lsb = glyphs.at(pos).lsb;-
961 ++pos;-
962 }
never executed: end of block
0
963 if (glyf_size < max_size_small
glyf_size < max_size_smallDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
964-
965 ls << quint16(gpos>>1);-
966 }
never executed: end of block
else {
0
967-
968 ls << quint32(gpos);-
969 }
never executed: end of block
0
970 hs << advance-
971 << lsb;-
972 }
never executed: end of block
0
973 if (glyf_size < max_size_small
glyf_size < max_size_smallDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
974-
975 ls << quint16(glyf.data.size()>>1);-
976 }
never executed: end of block
else {
0
977-
978 ls << quint32(glyf.data.size());-
979 }
never executed: end of block
0
980-
981 ((!(loca.data.size() == ls.offset())) ? qt_assert("loca.data.size() == ls.offset()",__FILE__,1061) : qt_noop());-
982 ((!(hmtx.data.size() == hs.offset())) ? qt_assert("hmtx.data.size() == hs.offset()",__FILE__,1062) : qt_noop());-
983-
984 QVector<QTtfTable> list;-
985 list.reserve(3);-
986 list.append(glyf);-
987 list.append(loca);-
988 list.append(hmtx);-
989 return
never executed: return list;
list;
never executed: return list;
0
990}-
991-
992static bool operator <(const QTtfTable &t1, const QTtfTable &t2)-
993{-
994 return
never executed: return t1.tag < t2.tag;
t1.tag < t2.tag;
never executed: return t1.tag < t2.tag;
0
995}-
996-
997static QByteArray bindFont(const QVector<QTtfTable>& _tables)-
998{-
999 QVector<QTtfTable> tables = _tables;-
1000-
1001 std::sort(tables.begin(), tables.end());-
1002-
1003 QByteArray font;-
1004 const int header_size = sizeof(qint32) + 4*sizeof(quint16);-
1005 const int directory_size = 4*sizeof(quint32)*tables.size();-
1006 font.resize(header_size + directory_size);-
1007-
1008 int log2 = 0;-
1009 int pow = 1;-
1010 int n = tables.size() >> 1;-
1011 while (n
nDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1012 ++log2;-
1013 pow <<= 1;-
1014 n >>= 1;-
1015 }
never executed: end of block
0
1016-
1017 quint32 head_offset = 0;-
1018 {-
1019 QTtfStream f(font);-
1020-
1021-
1022-
1023-
1024-
1025-
1026-
1027 f << qint32(0x00010000)-
1028 << quint16(tables.size())-
1029 << quint16(16*pow)-
1030 << quint16(log2)-
1031 << quint16(16*(tables.size() - pow));-
1032-
1033-
1034-
1035-
1036-
1037-
1038-
1039 quint32 table_offset = header_size + directory_size;-
1040 for (int i = 0; i < tables.size()
i < tables.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1041 const QTtfTable &t = tables.at(i);-
1042 const quint32 size = (t.data.size() + 3) & ~3;-
1043 if (t.tag == ( (((quint32)('h')) << 24) | (((quint32)('e')) << 16) | (((quint32)('a')) << 8) | ((quint32)('d')) )
t.tag == ( (((...int32)('d')) )Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1044 head_offset = table_offset;
never executed: head_offset = table_offset;
0
1045 f << t.tag-
1046 << checksum(t.data)-
1047 << table_offset-
1048 << t.data.size();-
1049 table_offset += size;-
1050-
1051-
1052 }
never executed: end of block
0
1053 }-
1054 for (int i = 0; i < tables.size()
i < tables.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1055 const QByteArray &t = tables.at(i).data;-
1056 font += t;-
1057 int s = t.size();-
1058 while (s & 3
s & 3Description
TRUEnever evaluated
FALSEnever evaluated
) { font += '\0'; ++s; }
never executed: end of block
0
1059 }
never executed: end of block
0
1060-
1061 if (!head_offset
!head_offsetDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1062 QMessageLogger(__FILE__, 1142, __PRETTY_FUNCTION__).warning("QFontSubset: Font misses 'head' table");-
1063 return
never executed: return QByteArray();
QByteArray();
never executed: return QByteArray();
0
1064 }-
1065-
1066-
1067 quint32 checksum_adjust = 0xB1B0AFBA - checksum(font);-
1068 qToBigEndian(checksum_adjust, font.data() + head_offset + 8);-
1069-
1070 return
never executed: return font;
font;
never executed: return font;
0
1071}-
1072QByteArray QFontSubset::toTruetype() const-
1073{-
1074 qttf_font_tables font;-
1075 memset(&font, 0, sizeof(qttf_font_tables));-
1076-
1077 qreal ppem = fontEngine->fontDef.pixelSize;-
1078-
1079-
1080 QFontEngine::Properties properties = fontEngine->properties();-
1081-
1082 emSquare = 2048;-
1083 widths.resize(nGlyphs());-
1084-
1085-
1086 font.head.font_revision = 0x00010000;-
1087 font.head.flags = (1 << 2) | (1 << 4);-
1088 font.head.created = 0;-
1089 font.head.modified = 0;-
1090 font.head.xMin = 32767;-
1091 font.head.xMax = (-32767 - 1);-
1092 font.head.yMin = 32767;-
1093 font.head.yMax = (-32767 - 1);-
1094 font.head.macStyle = (
(fontEngine->f...QFont::Normal)Description
TRUEnever evaluated
FALSEnever evaluated
fontEngine->fontDef.weight > QFont::Normal)
(fontEngine->f...QFont::Normal)Description
TRUEnever evaluated
FALSEnever evaluated
? 1 : 0;
0
1095 font.head.macStyle |= (
(fontEngine->f...::StyleNormal)Description
TRUEnever evaluated
FALSEnever evaluated
fontEngine->fontDef.styleHint != QFont::StyleNormal)
(fontEngine->f...::StyleNormal)Description
TRUEnever evaluated
FALSEnever evaluated
? 1 : 0;
0
1096-
1097-
1098 font.hhea.ascender = qRound(properties.ascent);-
1099 font.hhea.descender = -qRound(properties.descent);-
1100 font.hhea.lineGap = qRound(properties.leading);-
1101 font.hhea.maxAdvanceWidth = qRound(fontEngine->maxCharWidth() * 2048. / ppem);-
1102 font.hhea.minLeftSideBearing = qRound(fontEngine->minLeftBearing() * 2048. / ppem);-
1103 font.hhea.minRightSideBearing = qRound(fontEngine->minRightBearing() * 2048. / ppem);-
1104 font.hhea.xMaxExtent = (-32767 - 1);-
1105-
1106 font.maxp.numGlyphs = 0;-
1107 font.maxp.maxPoints = 0;-
1108 font.maxp.maxContours = 0;-
1109 font.maxp.maxCompositePoints = 0;-
1110 font.maxp.maxCompositeContours = 0;-
1111 font.maxp.maxComponentElements = 0;-
1112 font.maxp.maxComponentDepth = 0;-
1113 const int numGlyphs = nGlyphs();-
1114 font.maxp.numGlyphs = numGlyphs;-
1115 QVector<QTtfGlyph> glyphs;-
1116 glyphs.reserve(numGlyphs);-
1117-
1118 uint sumAdvances = 0;-
1119 for (int i = 0; i < numGlyphs
i < numGlyphsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
1120 glyph_t g = glyph_indices.at(i);-
1121 QPainterPath path;-
1122 glyph_metrics_t metric;-
1123 fontEngine->getUnscaledGlyph(g, &path, &metric);-
1124 if (noEmbed
noEmbedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1125 path = QPainterPath();-
1126 if (g == 0
g == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1127 path.addRect(QRectF(0, 0, 1000, 1000));
never executed: path.addRect(QRectF(0, 0, 1000, 1000));
0
1128 }
never executed: end of block
0
1129 QTtfGlyph glyph = generateGlyph(i, path, metric.xoff.toReal(), metric.x.toReal(), properties.emSquare.toReal());-
1130-
1131 font.head.xMin = qMin(font.head.xMin, glyph.xMin);-
1132 font.head.xMax = qMax(font.head.xMax, glyph.xMax);-
1133 font.head.yMin = qMin(font.head.yMin, glyph.yMin);-
1134 font.head.yMax = qMax(font.head.yMax, glyph.yMax);-
1135-
1136 font.hhea.xMaxExtent = qMax(font.hhea.xMaxExtent, (qint16)(glyph.lsb + glyph.xMax - glyph.xMin));-
1137-
1138 font.maxp.maxPoints = qMax(font.maxp.maxPoints, glyph.numPoints);-
1139 font.maxp.maxContours = qMax(font.maxp.maxContours, glyph.numContours);-
1140-
1141 if (glyph.xMax > glyph.xMin
glyph.xMax > glyph.xMinDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1142 sumAdvances += glyph.xMax - glyph.xMin;
never executed: sumAdvances += glyph.xMax - glyph.xMin;
0
1143-
1144-
1145 glyphs.append(glyph);-
1146 widths[i] = glyph.advanceWidth;-
1147 }
never executed: end of block
0
1148-
1149-
1150 QVector<QTtfTable> tables = generateGlyphTables(font, glyphs);-
1151 tables.append(generateHead(font.head));-
1152 tables.append(generateHhea(font.hhea));-
1153 tables.append(generateMaxp(font.maxp));-
1154-
1155 QTtfTable name_table;-
1156 name_table.tag = ( (((quint32)('n')) << 24) | (((quint32)('a')) << 16) | (((quint32)('m')) << 8) | ((quint32)('e')) );-
1157 if (!noEmbed
!noEmbedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1158 name_table.data = fontEngine->getSfntTable(name_table.tag);
never executed: name_table.data = fontEngine->getSfntTable(name_table.tag);
0
1159 if (name_table.data.isEmpty()
name_table.data.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
1160 qttf_name_table name;-
1161 if (noEmbed
noEmbedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
1162 name.copyright = QLatin1String("Fake font");
never executed: name.copyright = QLatin1String("Fake font");
0
1163 else-
1164 name.copyright = QLatin1String(properties.copyright);
never executed: name.copyright = QLatin1String(properties.copyright);
0
1165 name.family = fontEngine->fontDef.family;-
1166 name.subfamily = QLatin1String("Regular");-
1167 name.postscript_name = QLatin1String(properties.postscriptName);-
1168 name_table = generateName(name);-
1169 }
never executed: end of block
0
1170 tables.append(name_table);-
1171-
1172 if (!noEmbed
!noEmbedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
1173 QTtfTable os2;-
1174 os2.tag = ( (((quint32)('O')) << 24) | (((quint32)('S')) << 16) | (((quint32)('/')) << 8) | ((quint32)('2')) );-
1175 os2.data = fontEngine->getSfntTable(os2.tag);-
1176 if (!os2.data.isEmpty()
!os2.data.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
1177 tables.append(os2);
never executed: tables.append(os2);
0
1178 }
never executed: end of block
0
1179-
1180 return
never executed: return bindFont(tables);
bindFont(tables);
never executed: return bindFont(tables);
0
1181}-
1182-
1183-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9