Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfontsubset.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
6#include <qdebug.h>
7#include <qendian.h>
8#include <qpainterpath.h>
9#include "private/qpdf_p.h"
10
12
13#include <algorithm>
14
15QT_BEGIN_NAMESPACE
16
17using namespace Qt::StringLiterals;
18
19#ifndef QT_NO_PDF
20
21// This map is used for symbol fonts to get the correct glyph names for the latin range
22static const unsigned short symbol_map[0x100] = {
23 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
24 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
25 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
26 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
27 0x0020, 0x0021, 0x2200, 0x0023, 0x2203, 0x0025, 0x0026, 0x220b,
28 0x0028, 0x0029, 0x2217, 0x002b, 0x002c, 0x2212, 0x002e, 0x002f,
29 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
30 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
31
32 0x2245, 0x0391, 0x0392, 0x03a7, 0x0394, 0x0395, 0x03a6, 0x0393,
33 0x0397, 0x0399, 0x03d1, 0x039a, 0x039b, 0x039c, 0x039d, 0x039f,
34 0x03a0, 0x0398, 0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03c2, 0x03a9,
35 0x039e, 0x03a8, 0x0396, 0x005b, 0x2234, 0x005d, 0x22a5, 0x005f,
36 0xf8e5, 0x03b1, 0x03b2, 0x03c7, 0x03b4, 0x03b5, 0x03c6, 0x03b3,
37 0x03b7, 0x03b9, 0x03d5, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03bf,
38 0x03c0, 0x03b8, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03d6, 0x03c9,
39 0x03be, 0x03c8, 0x03b6, 0x007b, 0x007c, 0x007d, 0x223c, 0x007f,
40
41 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
42 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f,
43 0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
44 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f,
45 0x20ac, 0x03d2, 0x2023, 0x2264, 0x2044, 0x221e, 0x0192, 0x2263,
46 0x2666, 0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193,
47 0x00b0, 0x00b1, 0x2033, 0x2265, 0x00d7, 0x221d, 0x2202, 0x2022,
48 0x00f7, 0x2260, 0x2261, 0x2248, 0x2026, 0xf8e6, 0xf8e7, 0x21b5,
49
50 0x2135, 0x2111, 0x211c, 0x2118, 0x2297, 0x2295, 0x2205, 0x2229,
51 0x222a, 0x2283, 0x2287, 0x2284, 0x2282, 0x2286, 0x2208, 0x2209,
52 0x2220, 0x2207, 0xf6da, 0xf6d9, 0xf6db, 0x220f, 0x221a, 0x22c5,
53 0x00ac, 0x2227, 0x2228, 0x21d4, 0x21d0, 0x21d1, 0x21d2, 0x21d3,
54 0x25ca, 0x2329, 0xf8e8, 0xf8e9, 0xf8ea, 0x2211, 0xf8eb, 0xf8ec,
55 0xf8ed, 0xf8ee, 0xf8ef, 0xf8f0, 0xf8f1, 0xf8f2, 0xf8f3, 0xf8f4,
56 0x0000, 0x232a, 0x222b, 0x2320, 0xf8f5, 0x2321, 0xf8f6, 0xf8f7,
57 0xf8f8, 0xf8f9, 0xf8fa, 0xf8fb, 0xf8fc, 0xf8fd, 0xf8fe, 0x0000
58};
59
60// ---------------------------- PS/PDF helper methods -----------------------------------
61
62
63
64QByteArray QFontSubset::glyphName(unsigned short unicode, bool symbol)
65{
66 if (symbol && unicode < 0x100)
67 // map from latin1 to symbol
68 unicode = symbol_map[unicode];
69
70 const AGLEntry *r = std::lower_bound(unicode_to_agl_map, unicode_to_agl_map + unicode_to_agl_map_size, unicode);
71 if ((r != unicode_to_agl_map + unicode_to_agl_map_size) && !(unicode < *r))
72 return glyph_names + r->index;
73
74 char buffer[8];
75 buffer[0] = 'u';
76 buffer[1] = 'n';
77 buffer[2] = 'i';
78 QPdf::toHex(unicode, buffer+3);
79 return buffer;
80}
81
82QByteArray QFontSubset::widthArray() const
83{
84 Q_ASSERT(!widths.isEmpty());
85
86 QFontEngine::Properties properties = fontEngine->properties();
87
88 QByteArray width;
89 QPdf::ByteStream s(&width);
90 const qreal scale = 1000.0/emSquare.toInt();
91
92 QFixed defWidth = widths[0];
93 //qDebug("defWidth=%d, scale=%f", defWidth.toInt(), scale.toReal());
94 for (qsizetype i = 0; i < nGlyphs(); ++i) {
95 if (defWidth != widths[i])
96 defWidth = 0;
97 }
98 if (defWidth > 0) {
99 s << "/DW " << qRound(defWidth.toInt() * scale);
100 } else {
101 s << "/W [";
102 for (qsizetype g = 0; g < nGlyphs();) {
103 QFixed w = widths[g];
104 qsizetype start = g;
105 qsizetype startLinear = 0;
106 ++g;
107 while (g < nGlyphs()) {
108 QFixed nw = widths[g];
109 if (nw == w) {
110 if (!startLinear)
111 startLinear = g - 1;
112 } else {
113 if (startLinear > 0 && g - startLinear >= 10)
114 break;
115 startLinear = 0;
116 }
117 w = nw;
118 ++g;
119 }
120 // qDebug("start=%x startLinear=%x g-1=%x",start,startLinear,g-1);
121 if (g - startLinear < 10)
122 startLinear = 0;
123 qsizetype endnonlinear = startLinear ? startLinear : g;
124 // qDebug(" startLinear=%x endnonlinear=%x", startLinear,endnonlinear);
125 if (endnonlinear > start) {
126 s << start << '[';
127 for (qsizetype i = start; i < endnonlinear; ++i)
128 s << qRound(widths[i].toInt() * scale);
129 s << "]\n";
130 }
131 if (startLinear)
132 s << startLinear << g - 1 << qRound(widths[startLinear].toInt() * scale) << '\n';
133 }
134 s << "]\n";
135 }
136 return width;
137}
138
139static void checkRanges(QPdf::ByteStream &ts, QByteArray &ranges, int &nranges)
140{
141 if (++nranges > 100) {
142 ts << nranges << "beginbfrange\n"
143 << ranges << "endbfrange\n";
144 ranges = QByteArray();
145 nranges = 0;
146 }
147}
148
149QList<int> QFontSubset::getReverseMap() const
150{
151 QList<int> reverseMap(0x10000, 0);
152 for (uint uc = 0; uc < 0x10000; ++uc) {
153 auto idx = glyph_indices.indexOf(fontEngine->glyphIndex(uc));
154 if (idx >= 0 && !reverseMap.at(idx))
155 reverseMap[idx] = uc;
156 }
157 return reverseMap;
158}
159
160QByteArray QFontSubset::createToUnicodeMap() const
161{
162 QList<int> reverseMap = getReverseMap();
163
164 QByteArray touc;
165 QPdf::ByteStream ts(&touc);
166 ts << "/CIDInit /ProcSet findresource begin\n"
167 "12 dict begin\n"
168 "begincmap\n"
169 "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n"
170 "/CMapName /Adobe-Identity-UCS def\n"
171 "/CMapType 2 def\n"
172 "1 begincodespacerange\n"
173 "<0000> <FFFF>\n"
174 "endcodespacerange\n";
175
176 int nranges = 1;
177 QByteArray ranges = "<0000> <0000> <0000>\n";
178 QPdf::ByteStream s(&ranges);
179
180 char buf[5];
181 for (qsizetype g = 1; g < nGlyphs(); ) {
182 int uc0 = reverseMap.at(g);
183 if (!uc0) {
184 ++g;
185 continue;
186 }
187 qsizetype start = g;
188 qsizetype startLinear = 0;
189 ++g;
190 while (g < nGlyphs()) {
191 int uc = reverseMap[g];
192 // cmaps can't have the high byte changing within one range, so we need to break on that as well
193 if (!uc || (g>>8) != (start >> 8))
194 break;
195 if (uc == uc0 + 1) {
196 if (!startLinear)
197 startLinear = g - 1;
198 } else {
199 if (startLinear > 0 && g - startLinear >= 10)
200 break;
201 startLinear = 0;
202 }
203 uc0 = uc;
204 ++g;
205 }
206 // qDebug("start=%x startLinear=%x g-1=%x",start,startLinear,g-1);
207 if (g - startLinear < 10)
208 startLinear = 0;
209 qsizetype endnonlinear = startLinear ? startLinear : g;
210 // qDebug(" startLinear=%x endnonlinear=%x", startLinear,endnonlinear);
211 if (endnonlinear > start) {
212 s << '<' << QPdf::toHex((ushort)start, buf) << "> <";
213 s << QPdf::toHex((ushort)(endnonlinear - 1), buf) << "> ";
214 if (endnonlinear == start + 1) {
215 s << '<' << QPdf::toHex((ushort)reverseMap[start], buf) << ">\n";
216 } else {
217 s << '[';
218 for (qsizetype i = start; i < endnonlinear; ++i) {
219 s << '<' << QPdf::toHex((ushort)reverseMap[i], buf) << "> ";
220 }
221 s << "]\n";
222 }
223 checkRanges(ts, ranges, nranges);
224 }
225 if (startLinear) {
226 while (startLinear < g) {
227 qsizetype len = g - startLinear;
228 qsizetype uc_start = reverseMap[startLinear];
229 qsizetype uc_end = uc_start + len - 1;
230 if ((uc_end >> 8) != (uc_start >> 8))
231 len = 256 - (uc_start & 0xff);
232 s << '<' << QPdf::toHex((ushort)startLinear, buf) << "> <";
233 s << QPdf::toHex((ushort)(startLinear + len - 1), buf) << "> ";
234 s << '<' << QPdf::toHex((ushort)reverseMap[startLinear], buf) << ">\n";
235 checkRanges(ts, ranges, nranges);
236 startLinear += len;
237 }
238 }
239 }
240 if (nranges) {
241 ts << nranges << "beginbfrange\n"
242 << ranges << "endbfrange\n";
243 }
244 ts << "endcmap\n"
245 "CMapName currentdict /CMap defineresource pop\n"
246 "end\n"
247 "end\n";
248
249 return touc;
250}
251
252qsizetype QFontSubset::addGlyph(uint index)
253{
254 qsizetype idx = glyph_indices.indexOf(index);
255 if (idx < 0) {
256 idx = glyph_indices.size();
257 glyph_indices.append(index);
258 }
259 return idx;
260}
261
262#endif // QT_NO_PDF
263
264// ------------------------------ Truetype generation ----------------------------------------------
265
267typedef quint32 Tag;
270
271
273public:
274 QTtfStream(QByteArray &ba) : data((uchar *)ba.data()) { start = data; }
275 QTtfStream &operator <<(quint8 v) { *data = v; ++data; return *this; }
276 QTtfStream &operator <<(quint16 v) { qToBigEndian(v, data); data += sizeof(v); return *this; }
277 QTtfStream &operator <<(quint32 v) { qToBigEndian(v, data); data += sizeof(v); return *this; }
278 QTtfStream &operator <<(qint8 v) { *data = quint8(v); ++data; return *this; }
279 QTtfStream &operator <<(qint16 v) { qToBigEndian(v, data); data += sizeof(v); return *this; }
280 QTtfStream &operator <<(qint32 v) { qToBigEndian(v, data); data += sizeof(v); return *this; }
281 QTtfStream &operator <<(qint64 v) { qToBigEndian(v, data); data += sizeof(v); return *this; }
282
283 int offset() const { return data - start; }
284 void setOffset(int o) { data = start + o; }
285 void align4() { while (offset() & 3) { *data = '\0'; ++data; } }
286private:
287 uchar *data;
288 uchar *start;
289};
290
296
297
311
312
324
325
336
344
345
346static QTtfTable generateHead(const qttf_head_table &head);
347static QTtfTable generateHhea(const qttf_hhea_table &hhea);
348static QTtfTable generateMaxp(const qttf_maxp_table &maxp);
349static QTtfTable generateName(const qttf_name_table &name);
350
357
358
372
373static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem);
374// generates glyf, loca and hmtx
375static QList<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QList<QTtfGlyph> &_glyphs);
376
377static QByteArray bindFont(const QList<QTtfTable>& _tables);
378
379
380static quint32 checksum(const QByteArray &table)
381{
382 quint32 sum = 0;
383 int offset = 0;
384 const uchar *d = (const uchar *)table.constData();
385 while (offset <= table.size()-3) {
386 sum += qFromBigEndian<quint32>(d + offset);
387 offset += 4;
388 }
389 int shift = 24;
390 quint32 x = 0;
391 while (offset < table.size()) {
392 x |= ((quint32)d[offset]) << shift;
393 ++offset;
394 shift -= 8;
395 }
396 sum += x;
397
398 return sum;
399}
400
402{
403 const int head_size = 54;
404 QTtfTable t;
405 t.tag = QFont::Tag("head").value();
406 t.data.resize(head_size);
407
408 QTtfStream s(t.data);
409
410// qint32 Table version number 0x00010000 for version 1.0.
411// qint32 fontRevision Set by font manufacturer.
412 s << qint32(0x00010000)
413 << head.font_revision
414// quint32 checkSumAdjustment To compute: set it to 0, sum the entire font as quint32, then store 0xB1B0AFBA - sum.
415 << quint32(0)
416// quint32 magicNumber Set to 0x5F0F3CF5.
417 << quint32(0x5F0F3CF5)
418// quint16 flags Bit 0: Baseline for font at y=0;
419// Bit 1: Left sidebearing point at x=0;
420// Bit 2: Instructions may depend on point size;
421// Bit 3: Force ppem to integer values for all internal scaler math; may use fractional ppem sizes if this bit is clear;
422// Bit 4: Instructions may alter advance width (the advance widths might not scale linearly);
423// Bits 5-10: These should be set according to Apple's specification . However, they are not implemented in OpenType.
424// Bit 11: Font data is 'lossless,' as a result of having been compressed and decompressed with the Agfa MicroType Express engine.
425// Bit 12: Font converted (produce compatible metrics)
426// Bit 13: Font optimized for ClearType
427// Bit 14: Reserved, set to 0
428// Bit 15: Reserved, set to 0
429 << quint16(0)
430
431// quint16 unitsPerEm Valid range is from 16 to 16384. This value should be a power of 2 for fonts that have TrueType outlines.
432 << quint16(2048)
433// qint64 created Number of seconds since 12:00 midnight, January 1, 1904. 64-bit integer
434 << head.created
435// qint64 modified Number of seconds since 12:00 midnight, January 1, 1904. 64-bit integer
436 << head.modified
437// qint16 xMin For all glyph bounding boxes.
438// qint16 yMin For all glyph bounding boxes.
439// qint16 xMax For all glyph bounding boxes.
440// qint16 yMax For all glyph bounding boxes.
441 << head.xMin
442 << head.yMin
443 << head.xMax
444 << head.yMax
445// quint16 macStyle Bit 0: Bold (if set to 1);
446// Bit 1: Italic (if set to 1)
447// Bit 2: Underline (if set to 1)
448// Bit 3: Outline (if set to 1)
449// Bit 4: Shadow (if set to 1)
450// Bit 5: Condensed (if set to 1)
451// Bit 6: Extended (if set to 1)
452// Bits 7-15: Reserved (set to 0).
453 << head.macStyle
454// quint16 lowestRecPPEM Smallest readable size in pixels.
455 << quint16(6) // just a wild guess
456// qint16 fontDirectionHint 0: Fully mixed directional glyphs;
457 << qint16(0)
458// 1: Only strongly left to right;
459// 2: Like 1 but also contains neutrals;
460// -1: Only strongly right to left;
461// -2: Like -1 but also contains neutrals. 1
462// qint16 indexToLocFormat 0 for short offsets, 1 for long.
463 << head.indexToLocFormat
464// qint16 glyphDataFormat 0 for current format.
465 << qint16(0);
466
467 Q_ASSERT(s.offset() == head_size);
468 return t;
469}
470
471
473{
474 const int hhea_size = 36;
475 QTtfTable t;
476 t.tag = QFont::Tag("hhea").value();
477 t.data.resize(hhea_size);
478
479 QTtfStream s(t.data);
480// qint32 Table version number 0x00010000 for version 1.0.
481 s << qint32(0x00010000)
482// qint16 Ascender Typographic ascent. (Distance from baseline of highest ascender)
483 << hhea.ascender
484// qint16 Descender Typographic descent. (Distance from baseline of lowest descender)
485 << hhea.descender
486// qint16 LineGap Typographic line gap.
487// Negative LineGap values are treated as zero
488// in Windows 3.1, System 6, and
489// System 7.
490 << hhea.lineGap
491// quint16 advanceWidthMax Maximum advance width value in 'hmtx' table.
492 << hhea.maxAdvanceWidth
493// qint16 minLeftSideBearing Minimum left sidebearing value in 'hmtx' table.
494 << hhea.minLeftSideBearing
495// qint16 minRightSideBearing Minimum right sidebearing value; calculated as Min(aw - lsb - (xMax - xMin)).
496 << hhea.minRightSideBearing
497// qint16 xMaxExtent Max(lsb + (xMax - xMin)).
498 << hhea.xMaxExtent
499// qint16 caretSlopeRise Used to calculate the slope of the cursor (rise/run); 1 for vertical.
500 << qint16(1)
501// qint16 caretSlopeRun 0 for vertical.
502 << qint16(0)
503// qint16 caretOffset The amount by which a slanted highlight on a glyph needs to be shifted to produce the best appearance. Set to 0 for non-slanted fonts
504 << qint16(0)
505// qint16 (reserved) set to 0
506 << qint16(0)
507// qint16 (reserved) set to 0
508 << qint16(0)
509// qint16 (reserved) set to 0
510 << qint16(0)
511// qint16 (reserved) set to 0
512 << qint16(0)
513// qint16 metricDataFormat 0 for current format.
514 << qint16(0)
515// quint16 numberOfHMetrics Number of hMetric entries in 'hmtx' table
516 << hhea.numberOfHMetrics;
517
518 Q_ASSERT(s.offset() == hhea_size);
519 return t;
520}
521
522
524{
525 const int maxp_size = 32;
526 QTtfTable t;
527 t.tag = QFont::Tag("maxp").value();
528 t.data.resize(maxp_size);
529
530 QTtfStream s(t.data);
531
532// qint32 Table version number 0x00010000 for version 1.0.
533 s << qint32(0x00010000)
534// quint16 numGlyphs The number of glyphs in the font.
535 << maxp.numGlyphs
536// quint16 maxPoints Maximum points in a non-composite glyph.
537 << maxp.maxPoints
538// quint16 maxContours Maximum contours in a non-composite glyph.
539 << maxp.maxContours
540// quint16 maxCompositePoints Maximum points in a composite glyph.
541 << maxp.maxCompositePoints
542// quint16 maxCompositeContours Maximum contours in a composite glyph.
543 << maxp.maxCompositeContours
544// quint16 maxZones 1 if instructions do not use the twilight zone (Z0), or 2 if instructions do use Z0; should be set to 2 in most cases.
545 << quint16(1) // we do not embed instructions
546// quint16 maxTwilightPoints Maximum points used in Z0.
547 << quint16(0)
548// quint16 maxStorage Number of Storage Area locations.
549 << quint16(0)
550// quint16 maxFunctionDefs Number of FDEFs.
551 << quint16(0)
552// quint16 maxInstructionDefs Number of IDEFs.
553 << quint16(0)
554// quint16 maxStackElements Maximum stack depth2.
555 << quint16(0)
556// quint16 maxSizeOfInstructions Maximum byte count for glyph instructions.
557 << quint16(0)
558// quint16 maxComponentElements Maximum number of components referenced at "top level" for any composite glyph.
559 << maxp.maxComponentElements
560// quint16 maxComponentDepth Maximum levels of recursion; 1 for simple components.
561 << maxp.maxComponentDepth;
562
563 Q_ASSERT(s.offset() == maxp_size);
564 return t;
565}
566
572
573static QTtfTable generateName(const QList<QTtfNameRecord> &name);
574
576{
577 QList<QTtfNameRecord> list;
578 list.reserve(5);
579 QTtfNameRecord rec;
580 rec.nameId = 0;
581 rec.value = name.copyright;
582 list.append(rec);
583 rec.nameId = 1;
584 rec.value = name.family;
585 list.append(rec);
586 rec.nameId = 2;
587 rec.value = name.subfamily;
588 list.append(rec);
589 rec.nameId = 4;
590 rec.value = name.family;
591 if (name.subfamily != "Regular"_L1)
592 rec.value += u' ' + name.subfamily;
593 list.append(rec);
594 rec.nameId = 6;
595 rec.value = name.postscript_name;
596 list.append(rec);
597
598 return generateName(list);
599}
600
601// ####### should probably generate Macintosh/Roman name entries as well
602static QTtfTable generateName(const QList<QTtfNameRecord> &name)
603{
604 const int char_size = 2;
605
606 QTtfTable t;
607 t.tag = QFont::Tag("name").value();
608
609 const int name_size = 6 + 12*name.size();
610 int string_size = 0;
611 for (int i = 0; i < name.size(); ++i) {
612 string_size += name.at(i).value.size()*char_size;
613 }
614 t.data.resize(name_size + string_size);
615
616 QTtfStream s(t.data);
617// quint16 format Format selector (=0).
618 s << quint16(0)
619// quint16 count Number of name records.
620 << quint16(name.size())
621// quint16 stringOffset Offset to start of string storage (from start of table).
622 << quint16(name_size);
623// NameRecord nameRecord[count] The name records where count is the number of records.
624// (Variable)
625
626 int off = 0;
627 for (int i = 0; i < name.size(); ++i) {
628 int len = name.at(i).value.size()*char_size;
629// quint16 platformID Platform ID.
630// quint16 encodingID Platform-specific encoding ID.
631// quint16 languageID Language ID.
632 s << quint16(3)
633 << quint16(1)
634 << quint16(0x0409) // en_US
635// quint16 nameId Name ID.
636 << name.at(i).nameId
637// quint16 length String length (in bytes).
638 << quint16(len)
639// quint16 offset String offset from start of storage area (in bytes).
640 << quint16(off);
641 off += len;
642 }
643 for (int i = 0; i < name.size(); ++i) {
644 for (QChar ch : name.at(i).value)
645 s << quint16(ch.unicode());
646 }
647 return t;
648}
649
650
651enum Flags {
653 OnCurve = (1 << 0),
654 XShortVector = (1 << 1),
655 YShortVector = (1 << 2),
656 Repeat = (1 << 3),
657 XSame = (1 << 4),
658 XShortPositive = (1 << 4),
659 YSame = (1 << 5),
660 YShortPositive = (1 << 5)
661};
668
669static void convertPath(const QPainterPath &path, QList<TTF_POINT> *points, QList<int> *endPoints, qreal ppem)
670{
671 int numElements = path.elementCount();
672 for (int i = 0; i < numElements - 1; ++i) {
673 const QPainterPath::Element &e = path.elementAt(i);
674 TTF_POINT p;
675 p.x = qRound(e.x * 2048. / ppem);
676 p.y = qRound(-e.y * 2048. / ppem);
677 p.flags = 0;
678
679 switch(e.type) {
680 case QPainterPath::MoveToElement:
681 if (i != 0) {
682 // see if start and end points of the last contour agree
683 int start = endPoints->size() ? endPoints->at(endPoints->size()-1) - 1 : 0;
684 int end = points->size() - 1;
685 if (points->at(end).x == points->at(start).x
686 && points->at(end).y == points->at(start).y)
687 points->takeLast();
688 endPoints->append(points->size() - 1);
689 }
690 Q_FALLTHROUGH();
691 case QPainterPath::LineToElement:
692 p.flags = OnCurve;
693 break;
694 case QPainterPath::CurveToElement: {
695 // cubic bezier curve, we need to reduce to a list of quadratic curves
696 TTF_POINT list[3*16 + 4]; // we need max 16 subdivisions
697 list[3] = points->at(points->size() - 1);
698 list[2] = p;
699 const QPainterPath::Element &e2 = path.elementAt(++i);
700 list[1].x = qRound(e2.x * 2048. / ppem);
701 list[1].y = qRound(-e2.y * 2048. / ppem);
702 const QPainterPath::Element &e3 = path.elementAt(++i);
703 list[0].x = qRound(e3.x * 2048. / ppem);
704 list[0].y = qRound(-e3.y * 2048. / ppem);
705
706 TTF_POINT *base = list;
707
708 bool try_reduce = points->size() > 1
709 && points->at(points->size() - 1).flags == OnCurve
710 && points->at(points->size() - 2).flags == OffCurve;
711// qDebug("generating beziers:");
712 while (base >= list) {
713 const int split_limit = 3;
714// {
715// qDebug("iteration:");
716// TTF_POINT *x = list;
717// while (x <= base + 3) {
718// qDebug() << " " << QPoint(x->x, x->y);
719// ++x;
720// }
721// }
722 Q_ASSERT(base - list < 3*16 + 1);
723 // first see if we can easily reduce the cubic to a quadratic bezier curve
724 int i1_x = base[1].x + ((base[1].x - base[0].x) >> 1);
725 int i1_y = base[1].y + ((base[1].y - base[0].y) >> 1);
726 int i2_x = base[2].x + ((base[2].x - base[3].x) >> 1);
727 int i2_y = base[2].y + ((base[2].y - base[3].y) >> 1);
728// qDebug() << "checking: i1=" << QPoint(i1_x, i1_y) << " i2=" << QPoint(i2_x, i2_y);
729 if (qAbs(i1_x - i2_x) <= split_limit && qAbs(i1_y - i2_y) <= split_limit) {
730 // got a quadratic bezier curve
731 TTF_POINT np;
732 np.x = (i1_x + i2_x) >> 1;
733 np.y = (i1_y + i2_y) >> 1;
734 if (try_reduce) {
735 // see if we can optimize out the last onCurve point
736 int mx = (points->at(points->size() - 2).x + base[2].x) >> 1;
737 int my = (points->at(points->size() - 2).y + base[2].y) >> 1;
738 if (qAbs(mx - base[3].x) <= split_limit && qAbs(my - base[3].y) <= split_limit)
739 points->takeLast();
740 try_reduce = false;
741 }
742 np.flags = OffCurve;
743 points->append(np);
744// qDebug() << " appending offcurve point " << QPoint(np.x, np.y);
745 base -= 3;
746 } else {
747 // need to split
748// qDebug(" -> splitting");
749 qint16 a, b, c, d;
750 base[6].x = base[3].x;
751 c = base[1].x;
752 d = base[2].x;
753 base[1].x = a = ( base[0].x + c ) >> 1;
754 base[5].x = b = ( base[3].x + d ) >> 1;
755 c = ( c + d ) >> 1;
756 base[2].x = a = ( a + c ) >> 1;
757 base[4].x = b = ( b + c ) >> 1;
758 base[3].x = ( a + b ) >> 1;
759
760 base[6].y = base[3].y;
761 c = base[1].y;
762 d = base[2].y;
763 base[1].y = a = ( base[0].y + c ) >> 1;
764 base[5].y = b = ( base[3].y + d ) >> 1;
765 c = ( c + d ) >> 1;
766 base[2].y = a = ( a + c ) >> 1;
767 base[4].y = b = ( b + c ) >> 1;
768 base[3].y = ( a + b ) >> 1;
769 base += 3;
770 }
771 }
772 p = list[0];
773 p.flags = OnCurve;
774 break;
775 }
776 case QPainterPath::CurveToDataElement:
777 Q_ASSERT(false);
778 break;
779 }
780// qDebug() << " appending oncurve point " << QPoint(p.x, p.y);
781 points->append(p);
782 }
783 int start = endPoints->size() ? endPoints->at(endPoints->size()-1) + 1 : 0;
784 int end = points->size() - 1;
785 if (points->at(end).x == points->at(start).x
786 && points->at(end).y == points->at(start).y)
787 points->takeLast();
788 endPoints->append(points->size() - 1);
789}
790
791static void getBounds(const QList<TTF_POINT> &points, qint16 *xmin, qint16 *xmax, qint16 *ymin, qint16 *ymax)
792{
793 *xmin = points.at(0).x;
794 *xmax = *xmin;
795 *ymin = points.at(0).y;
796 *ymax = *ymin;
797
798 for (int i = 1; i < points.size(); ++i) {
799 *xmin = qMin(*xmin, points.at(i).x);
800 *xmax = qMax(*xmax, points.at(i).x);
801 *ymin = qMin(*ymin, points.at(i).y);
802 *ymax = qMax(*ymax, points.at(i).y);
803 }
804}
805
806static int convertToRelative(QList<TTF_POINT> *points)
807{
808 // convert points to relative and setup flags
809// qDebug("relative points:");
810 qint16 prev_x = 0;
811 qint16 prev_y = 0;
812 int point_array_size = 0;
813 for (int i = 0; i < points->size(); ++i) {
814 const int x = points->at(i).x;
815 const int y = points->at(i).y;
816 TTF_POINT rel;
817 rel.x = x - prev_x;
818 rel.y = y - prev_y;
819 rel.flags = points->at(i).flags;
820 Q_ASSERT(rel.flags < 2);
821 if (!rel.x) {
822 rel.flags |= XSame;
823 } else if (rel.x > 0 && rel.x < 256) {
824 rel.flags |= XShortVector|XShortPositive;
825 point_array_size++;
826 } else if (rel.x < 0 && rel.x > -256) {
827 rel.flags |= XShortVector;
828 rel.x = -rel.x;
829 point_array_size++;
830 } else {
831 point_array_size += 2;
832 }
833 if (!rel.y) {
834 rel.flags |= YSame;
835 } else if (rel.y > 0 && rel.y < 256) {
836 rel.flags |= YShortVector|YShortPositive;
837 point_array_size++;
838 } else if (rel.y < 0 && rel.y > -256) {
839 rel.flags |= YShortVector;
840 rel.y = -rel.y;
841 point_array_size++;
842 } else {
843 point_array_size += 2;
844 }
845 (*points)[i] = rel;
846// #define toString(x) ((rel.flags & x) ? #x : "")
847// qDebug() << " " << QPoint(rel.x, rel.y) << "flags="
848// << toString(OnCurve) << toString(XShortVector)
849// << (rel.flags & XShortVector ? toString(XShortPositive) : toString(XSame))
850// << toString(YShortVector)
851// << (rel.flags & YShortVector ? toString(YShortPositive) : toString(YSame));
852
853 prev_x = x;
854 prev_y = y;
855 }
856 return point_array_size;
857}
858
859static void getGlyphData(QTtfGlyph *glyph, const QList<TTF_POINT> &points, const QList<int> &endPoints, int point_array_size)
860{
861 const int max_size = int(5 * sizeof(qint16) // header
862 + endPoints.size() * sizeof(quint16) // end points of contours
863 + sizeof(quint16) // instruction length == 0
864 + points.size()*(1) // flags
865 + point_array_size); // coordinates
866
867 glyph->data.resize(max_size);
868
869 QTtfStream s(glyph->data);
870 s << qint16(endPoints.size())
871 << glyph->xMin << glyph->yMin << glyph->xMax << glyph->yMax;
872
873 for (int i = 0; i < endPoints.size(); ++i)
874 s << quint16(endPoints.at(i));
875 s << quint16(0); // instruction length
876
877 // emit flags
878 for (int i = 0; i < points.size(); ++i)
879 s << quint8(points.at(i).flags);
880 // emit points
881 for (int i = 0; i < points.size(); ++i) {
882 quint8 flags = points.at(i).flags;
883 qint16 x = points.at(i).x;
884
885 if (flags & XShortVector)
886 s << quint8(x);
887 else if (!(flags & XSame))
888 s << qint16(x);
889 }
890 for (int i = 0; i < points.size(); ++i) {
891 quint8 flags = points.at(i).flags;
892 qint16 y = points.at(i).y;
893
894 if (flags & YShortVector)
895 s << quint8(y);
896 else if (!(flags & YSame))
897 s << qint16(y);
898 }
899
900// qDebug() << "offset=" << s.offset() << "max_size=" << max_size << "point_array_size=" << point_array_size;
901 Q_ASSERT(s.offset() == max_size);
902
903 glyph->numContours = endPoints.size();
904 glyph->numPoints = points.size();
905}
906
907static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem)
908{
909 QList<TTF_POINT> points;
910 QList<int> endPoints;
911 QTtfGlyph glyph;
912 glyph.index = index;
913 glyph.advanceWidth = qRound(advance * 2048. / ppem);
914 glyph.lsb = qRound(lsb * 2048. / ppem);
915
916 if (path.isEmpty()) {
917 //qDebug("glyph %d is empty", index);
918 lsb = 0;
919 glyph.xMin = glyph.xMax = glyph.yMin = glyph.yMax = 0;
920 glyph.numContours = 0;
921 glyph.numPoints = 0;
922 return glyph;
923 }
924
925 convertPath(path, &points, &endPoints, ppem);
926
927// qDebug() << "number of contours=" << endPoints.size();
928// for (int i = 0; i < points.size(); ++i)
929// qDebug() << " point[" << i << "] = " << QPoint(points.at(i).x, points.at(i).y) << " flags=" << points.at(i).flags;
930// qDebug("endPoints:");
931// for (int i = 0; i < endPoints.size(); ++i)
932// qDebug() << endPoints.at(i);
933
934 getBounds(points, &glyph.xMin, &glyph.xMax, &glyph.yMin, &glyph.yMax);
935 int point_array_size = convertToRelative(&points);
936 getGlyphData(&glyph, points, endPoints, point_array_size);
937 return glyph;
938}
939
940static bool operator <(const QTtfGlyph &g1, const QTtfGlyph &g2)
941{
942 return g1.index < g2.index;
943}
944
945static QList<QTtfTable> generateGlyphTables(qttf_font_tables &tables, const QList<QTtfGlyph> &_glyphs)
946{
947 const int max_size_small = 65536*2;
948 QList<QTtfGlyph> glyphs = _glyphs;
949 std::sort(glyphs.begin(), glyphs.end());
950
951 Q_ASSERT(tables.maxp.numGlyphs == glyphs.at(glyphs.size()-1).index + 1);
952 int nGlyphs = tables.maxp.numGlyphs;
953
954 int glyf_size = 0;
955 for (int i = 0; i < glyphs.size(); ++i)
956 glyf_size += (glyphs.at(i).data.size() + 3) & ~3;
957
958 tables.head.indexToLocFormat = glyf_size < max_size_small ? 0 : 1;
959 tables.hhea.numberOfHMetrics = nGlyphs;
960
961 QTtfTable glyf;
962 glyf.tag = QFont::Tag("glyf").value();
963
964 QTtfTable loca;
965 loca.tag = QFont::Tag("loca").value();
966 loca.data.resize(glyf_size < max_size_small ? (nGlyphs+1)*sizeof(quint16) : (nGlyphs+1)*sizeof(quint32));
967 QTtfStream ls(loca.data);
968
969 QTtfTable hmtx;
970 hmtx.tag = QFont::Tag("hmtx").value();
971 hmtx.data.resize(nGlyphs*4);
972 QTtfStream hs(hmtx.data);
973
974 int pos = 0;
975 for (int i = 0; i < nGlyphs; ++i) {
976 int gpos = glyf.data.size();
977 quint16 advance = 0;
978 qint16 lsb = 0;
979
980 if (glyphs[pos].index == i) {
981 // emit glyph
982// qDebug("emitting glyph %d: size=%d", i, glyphs.at(i).data.size());
983 glyf.data += glyphs.at(pos).data;
984 while (glyf.data.size() & 1)
985 glyf.data.append('\0');
986 advance = glyphs.at(pos).advanceWidth;
987 lsb = glyphs.at(pos).lsb;
988 ++pos;
989 }
990 if (glyf_size < max_size_small) {
991 // use short loca format
992 ls << quint16(gpos>>1);
993 } else {
994 // use long loca format
995 ls << quint32(gpos);
996 }
997 hs << advance
998 << lsb;
999 }
1000 if (glyf_size < max_size_small) {
1001 // use short loca format
1002 ls << quint16(glyf.data.size()>>1);
1003 } else {
1004 // use long loca format
1005 ls << quint32(glyf.data.size());
1006 }
1007
1008 Q_ASSERT(loca.data.size() == ls.offset());
1009 Q_ASSERT(hmtx.data.size() == hs.offset());
1010
1011 QList<QTtfTable> list;
1012 list.reserve(3);
1013 list.append(glyf);
1014 list.append(loca);
1015 list.append(hmtx);
1016 return list;
1017}
1018
1019static bool operator <(const QTtfTable &t1, const QTtfTable &t2)
1020{
1021 return t1.tag < t2.tag;
1022}
1023
1024static QByteArray bindFont(const QList<QTtfTable>& _tables)
1025{
1026 QList<QTtfTable> tables = _tables;
1027
1028 std::sort(tables.begin(), tables.end());
1029
1030 QByteArray font;
1031 const int header_size = sizeof(qint32) + 4*sizeof(quint16);
1032 const int directory_size = 4*sizeof(quint32)*tables.size();
1033 font.resize(header_size + directory_size);
1034
1035 int log2 = 0;
1036 int pow = 1;
1037 int n = tables.size() >> 1;
1038 while (n) {
1039 ++log2;
1040 pow <<= 1;
1041 n >>= 1;
1042 }
1043
1044 quint32 head_offset = 0;
1045 {
1046 QTtfStream f(font);
1047// Offset Table
1048// Type Name Description
1049// qint32 sfnt version 0x00010000 for version 1.0.
1050// quint16 numTables Number of tables.
1051// quint16 searchRange (Maximum power of 2 <= numTables) x 16.
1052// quint16 entrySelector Log2(maximum power of 2 <= numTables).
1053// quint16 rangeShift NumTables x 16-searchRange.
1054 f << qint32(0x00010000)
1055 << quint16(tables.size())
1056 << quint16(16*pow)
1057 << quint16(log2)
1058 << quint16(16*(tables.size() - pow));
1059
1060// Table Directory
1061// Type Name Description
1062// quint32 tag 4 -byte identifier.
1063// quint32 checkSum CheckSum for this table.
1064// quint32 offset Offset from beginning of TrueType font file.
1065// quint32 length Length of this table.
1066 quint32 table_offset = header_size + directory_size;
1067 for (int i = 0; i < tables.size(); ++i) {
1068 const QTtfTable &t = tables.at(i);
1069 const quint32 size = (t.data.size() + 3) & ~3;
1070 if (t.tag == QFont::Tag("head").value())
1071 head_offset = table_offset;
1072 f << t.tag
1073 << checksum(t.data)
1074 << table_offset
1075 << quint32(t.data.size());
1076 table_offset += size;
1077#define TAG(x) char(t.tag >> 24) << char((t.tag >> 16) & 0xff) << char((t.tag >> 8) & 0xff) << char(t.tag & 0xff)
1078 //qDebug() << "table " << TAG(t.tag) << "has size " << t.data.size() << "stream at " << f.offset();
1079 }
1080 }
1081 for (int i = 0; i < tables.size(); ++i) {
1082 const QByteArray &t = tables.at(i).data;
1083 font += t;
1084 int s = t.size();
1085 while (s & 3) { font += '\0'; ++s; }
1086 }
1087
1088 if (!head_offset) {
1089 qWarning("QFontSubset: Font misses 'head' table");
1090 return QByteArray();
1091 }
1092
1093 // calculate the fonts checksum and qToBigEndian into 'head's checksum_adjust
1094 quint32 checksum_adjust = 0xB1B0AFBA - checksum(font);
1095 qToBigEndian(checksum_adjust, font.data() + head_offset + 8);
1096
1097 return font;
1098}
1099
1100
1101/*
1102 PDF requires the following tables:
1103
1104 head, hhea, loca, maxp, cvt , prep, glyf, hmtx, fpgm
1105
1106 This means we don't have to add a os/2, post or name table. cvt , prep and fpgm could be empty
1107 if really required.
1108*/
1109
1110QByteArray QFontSubset::toTruetype() const
1111{
1112 qttf_font_tables font;
1113 memset(&font, 0, sizeof(qttf_font_tables));
1114
1115 qreal ppem = fontEngine->fontDef.pixelSize;
1116#define TO_TTF(x) qRound(x * 2048. / ppem)
1117
1118 QFontEngine::Properties properties = fontEngine->properties();
1119 // initialize some stuff needed in createWidthArray
1120 emSquare = 2048;
1121 widths.resize(nGlyphs());
1122
1123 // head table
1124 font.head.font_revision = 0x00010000;
1125 font.head.flags = (1 << 2) | (1 << 4);
1126 font.head.created = 0; // ###
1127 font.head.modified = 0; // ###
1128 font.head.xMin = SHRT_MAX;
1129 font.head.xMax = SHRT_MIN;
1130 font.head.yMin = SHRT_MAX;
1131 font.head.yMax = SHRT_MIN;
1132 font.head.macStyle = (fontEngine->fontDef.weight > QFont::Normal) ? 1 : 0;
1133 font.head.macStyle |= (fontEngine->fontDef.styleHint != QFont::StyleNormal) ? 1 : 0;
1134
1135 // hhea table
1136 font.hhea.ascender = qRound(properties.ascent);
1137 font.hhea.descender = -qRound(properties.descent);
1138 font.hhea.lineGap = qRound(properties.leading);
1139 font.hhea.maxAdvanceWidth = TO_TTF(fontEngine->maxCharWidth());
1140 font.hhea.minLeftSideBearing = TO_TTF(fontEngine->minLeftBearing());
1141 font.hhea.minRightSideBearing = TO_TTF(fontEngine->minRightBearing());
1142 font.hhea.xMaxExtent = SHRT_MIN;
1143
1144 font.maxp.numGlyphs = 0;
1145 font.maxp.maxPoints = 0;
1146 font.maxp.maxContours = 0;
1147 font.maxp.maxCompositePoints = 0;
1148 font.maxp.maxCompositeContours = 0;
1149 font.maxp.maxComponentElements = 0;
1150 font.maxp.maxComponentDepth = 0;
1151 const qsizetype numGlyphs = nGlyphs();
1152 font.maxp.numGlyphs = quint16(numGlyphs);
1153 QList<QTtfGlyph> glyphs;
1154 glyphs.reserve(numGlyphs);
1155
1156 for (qsizetype i = 0; i < numGlyphs; ++i) {
1157 glyph_t g = glyph_indices.at(i);
1158 QPainterPath path;
1159 glyph_metrics_t metric;
1160 fontEngine->getUnscaledGlyph(g, &path, &metric);
1161 if (noEmbed) {
1162 path = QPainterPath();
1163 if (g == 0)
1164 path.addRect(QRectF(0, 0, 1000, 1000));
1165 }
1166 QTtfGlyph glyph = generateGlyph(i, path, metric.xoff.toReal(), metric.x.toReal(), properties.emSquare.toReal());
1167
1168 font.head.xMin = qMin(font.head.xMin, glyph.xMin);
1169 font.head.xMax = qMax(font.head.xMax, glyph.xMax);
1170 font.head.yMin = qMin(font.head.yMin, glyph.yMin);
1171 font.head.yMax = qMax(font.head.yMax, glyph.yMax);
1172
1173 font.hhea.xMaxExtent = qMax(font.hhea.xMaxExtent, (qint16)(glyph.lsb + glyph.xMax - glyph.xMin));
1174
1175 font.maxp.maxPoints = qMax(font.maxp.maxPoints, glyph.numPoints);
1176 font.maxp.maxContours = qMax(font.maxp.maxContours, glyph.numContours);
1177
1178// qDebug("adding glyph %d size=%d", glyph.index, glyph.data.size());
1179 glyphs.append(glyph);
1180 widths[i] = glyph.advanceWidth;
1181 }
1182
1183
1184 QList<QTtfTable> tables = generateGlyphTables(font, glyphs);
1185 tables.append(generateHead(font.head));
1186 tables.append(generateHhea(font.hhea));
1187 tables.append(generateMaxp(font.maxp));
1188 // name
1189 QTtfTable name_table;
1190 name_table.tag = QFont::Tag("name").value();
1191 if (!noEmbed)
1192 name_table.data = fontEngine->getSfntTable(name_table.tag);
1193 if (name_table.data.isEmpty()) {
1194 qttf_name_table name;
1195 if (noEmbed)
1196 name.copyright = "Fake font"_L1;
1197 else
1198 name.copyright = QLatin1StringView(properties.copyright);
1199 name.family = fontEngine->fontDef.families.constFirst();
1200 name.subfamily = "Regular"_L1; // ######
1201 name.postscript_name = QLatin1StringView(properties.postscriptName);
1202 name_table = generateName(name);
1203 }
1204 tables.append(name_table);
1205
1206 if (!noEmbed) {
1207 QTtfTable os2;
1208 os2.tag = QFont::Tag("OS/2").value();
1209 os2.data = fontEngine->getSfntTable(os2.tag);
1210 if (!os2.data.isEmpty())
1211 tables.append(os2);
1212 }
1213
1214 return bindFont(tables);
1215}
1216
1217QT_END_NAMESPACE
\inmodule QtGui
void setOffset(int o)
QTtfStream(QByteArray &ba)
int offset() const
static QTtfTable generateHhea(const qttf_hhea_table &hhea)
static bool operator<(const QTtfTable &t1, const QTtfTable &t2)
static void convertPath(const QPainterPath &path, QList< TTF_POINT > *points, QList< int > *endPoints, qreal ppem)
static bool operator<(const QTtfGlyph &g1, const QTtfGlyph &g2)
Q_DECLARE_TYPEINFO(QTtfTable, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(qttf_name_table, Q_RELOCATABLE_TYPE)
static QByteArray bindFont(const QList< QTtfTable > &_tables)
static QTtfTable generateHead(const qttf_head_table &head)
static QList< QTtfTable > generateGlyphTables(qttf_font_tables &tables, const QList< QTtfGlyph > &_glyphs)
static QTtfTable generateName(const QList< QTtfNameRecord > &name)
static const unsigned short symbol_map[0x100]
static quint32 checksum(const QByteArray &table)
Q_DECLARE_TYPEINFO(QTtfGlyph, Q_RELOCATABLE_TYPE)
static QTtfTable generateMaxp(const qttf_maxp_table &maxp)
Q_DECLARE_TYPEINFO(TTF_POINT, Q_PRIMITIVE_TYPE)
quint32 Tag
static void getGlyphData(QTtfGlyph *glyph, const QList< TTF_POINT > &points, const QList< int > &endPoints, int point_array_size)
Q_DECLARE_TYPEINFO(qttf_head_table, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(qttf_maxp_table, Q_PRIMITIVE_TYPE)
static QTtfTable generateName(const qttf_name_table &name)
qint16 F2DOT14
Q_DECLARE_TYPEINFO(QTtfNameRecord, Q_RELOCATABLE_TYPE)
Flags
@ XSame
@ Repeat
@ YShortPositive
@ XShortPositive
@ YSame
@ OffCurve
@ YShortVector
@ OnCurve
@ XShortVector
quint16 GlyphID
static void checkRanges(QPdf::ByteStream &ts, QByteArray &ranges, int &nranges)
quint16 Offset
static void getBounds(const QList< TTF_POINT > &points, qint16 *xmin, qint16 *xmax, qint16 *ymin, qint16 *ymax)
Q_DECLARE_TYPEINFO(qttf_hhea_table, Q_PRIMITIVE_TYPE)
static int convertToRelative(QList< TTF_POINT > *points)
#define TO_TTF(x)
static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem)
QByteArray data
quint16 numPoints
quint16 advanceWidth
quint16 index
quint16 numContours
QByteArray data
qttf_head_table head
qttf_maxp_table maxp
qttf_hhea_table hhea
quint16 maxAdvanceWidth
qint16 minLeftSideBearing
qint16 minRightSideBearing
quint16 numberOfHMetrics
quint16 maxCompositeContours
quint16 maxCompositePoints
quint16 maxComponentElements
quint16 maxComponentDepth
QString postscript_name