Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | void qt_registerFont(const QString &familyname, const QString &stylename, | - |
8 | const QString &foundryname, int weight, | - |
9 | QFont::Style style, int stretch, bool antialiased, | - |
10 | bool scalable, int pixelSize, bool fixedPitch, | - |
11 | const QSupportedWritingSystems &writingSystems, void *hanlde); | - |
12 | | - |
13 | void qt_registerFontFamily(const QString &familyName); | - |
14 | void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias); | - |
15 | void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *handle) | - |
16 | { | - |
17 | if (dataArray.size() == 0TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
18 | return; never executed: return; | 0 |
19 | | - |
20 | const uchar *data = reinterpret_cast<const uchar *>(dataArray.constData()); | - |
21 | if (QFontEngineQPF2::verifyHeader(data, dataArray.size())TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
22 | QString fontName = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_FontName).toString(); | - |
23 | int pixelSize = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_PixelSize).toInt(); | - |
24 | QVariant weight = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_Weight); | - |
25 | QVariant style = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_Style); | - |
26 | QByteArray writingSystemBits = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_WritingSystems).toByteArray(); | - |
27 | | - |
28 | if (!fontName.isEmpty()TRUE | never evaluated | FALSE | never evaluated |
&& pixelSizeTRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
29 | QFont::Weight fontWeight = QFont::Normal; | - |
30 | if (weight.type() == QVariant::IntTRUE | never evaluated | FALSE | never evaluated |
|| weight.type() == QVariant::UIntTRUE | never evaluated | FALSE | never evaluated |
) | 0 |
31 | fontWeight = QFont::Weight(weight.toInt()); never executed: fontWeight = QFont::Weight(weight.toInt()); | 0 |
32 | | - |
33 | QFont::Style fontStyle = static_cast<QFont::Style>(style.toInt()); | - |
34 | | - |
35 | QSupportedWritingSystems writingSystems; | - |
36 | for (int i = 0; i < writingSystemBits.count()TRUE | never evaluated | FALSE | never evaluated |
; ++i) { | 0 |
37 | uchar currentByte = writingSystemBits.at(i); | - |
38 | for (int j = 0; j < 8TRUE | never evaluated | FALSE | never evaluated |
; ++j) { | 0 |
39 | if (currentByte & 1TRUE | never evaluated | FALSE | never evaluated |
) | 0 |
40 | writingSystems.setSupported(QFontDatabase::WritingSystem(i * 8 + j)); never executed: writingSystems.setSupported(QFontDatabase::WritingSystem(i * 8 + j)); | 0 |
41 | currentByte >>= 1; | - |
42 | } never executed: end of block | 0 |
43 | } never executed: end of block | 0 |
44 | QFont::Stretch stretch = QFont::Unstretched; | - |
45 | registerFont(fontName,QString(),QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,false,writingSystems,handle); | - |
46 | } never executed: end of block | 0 |
47 | } never executed: end of block else { | 0 |
48 | QMessageLogger(__FILE__, 97103, __PRETTY_FUNCTION__).debug() << ("header verification of QPF2 font failed. maybe it is corrupt?";); | - |
49 | } never executed: end of block | 0 |
50 | } | - |
51 | void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &stylename, | - |
52 | const QString &foundryname, QFont::Weight weight, | - |
53 | QFont::Style style, QFont::Stretch stretch, bool antialiased, | - |
54 | bool scalable, int pixelSize, bool fixedPitch, | - |
55 | const QSupportedWritingSystems &writingSystems, void *usrPtr) | - |
56 | { | - |
57 | if (scalable) | - |
58 | pixelSize = 0; | - |
59 | | - |
60 | qt_registerFont(familyname, stylename, foundryname, weight, style, | - |
61 | stretch, antialiased, scalable, pixelSize, | - |
62 | fixedPitch, writingSystems, usrPtr); | - |
63 | } | - |
64 | void QPlatformFontDatabase::registerFontFamily(const QString &familyName) | - |
65 | { | - |
66 | qt_registerFontFamily(familyName); | - |
67 | } | - |
68 | | - |
69 | class QWritingSystemsPrivate | - |
70 | { | - |
71 | public: | - |
72 | QWritingSystemsPrivate() | - |
73 | : ref(1) | - |
74 | , vector(QFontDatabase::WritingSystemsCount,false) | - |
75 | { | - |
76 | } | - |
77 | | - |
78 | QWritingSystemsPrivate(const QWritingSystemsPrivate *other) | - |
79 | : ref(1) | - |
80 | , vector(other->vector) | - |
81 | { | - |
82 | } | - |
83 | | - |
84 | QAtomicInt ref; | - |
85 | QVector<bool> vector; | - |
86 | }; | - |
87 | | - |
88 | | - |
89 | | - |
90 | | - |
91 | QSupportedWritingSystems::QSupportedWritingSystems() | - |
92 | { | - |
93 | d = new QWritingSystemsPrivate; | - |
94 | } | - |
95 | | - |
96 | | - |
97 | | - |
98 | | - |
99 | QSupportedWritingSystems::QSupportedWritingSystems(const QSupportedWritingSystems &other) | - |
100 | { | - |
101 | d = other.d; | - |
102 | d->ref.ref(); | - |
103 | } | - |
104 | | - |
105 | | - |
106 | | - |
107 | | - |
108 | QSupportedWritingSystems &QSupportedWritingSystems::operator=(const QSupportedWritingSystems &other) | - |
109 | { | - |
110 | if (d != other.d) { | - |
111 | other.d->ref.ref(); | - |
112 | if (!d->ref.deref()) | - |
113 | delete d; | - |
114 | d = other.d; | - |
115 | } | - |
116 | return *this; | - |
117 | } | - |
118 | | - |
119 | | - |
120 | | - |
121 | | - |
122 | QSupportedWritingSystems::~QSupportedWritingSystems() | - |
123 | { | - |
124 | if (!d->ref.deref()) | - |
125 | delete d; | - |
126 | } | - |
127 | | - |
128 | | - |
129 | | - |
130 | | - |
131 | void QSupportedWritingSystems::detach() | - |
132 | { | - |
133 | if (d->ref.load() != 1) { | - |
134 | QWritingSystemsPrivate *newd = new QWritingSystemsPrivate(d); | - |
135 | if (!d->ref.deref()) | - |
136 | delete d; | - |
137 | d = newd; | - |
138 | } | - |
139 | } | - |
140 | | - |
141 | | - |
142 | | - |
143 | | - |
144 | | - |
145 | void QSupportedWritingSystems::setSupported(QFontDatabase::WritingSystem writingSystem, bool support) | - |
146 | { | - |
147 | detach(); | - |
148 | d->vector[writingSystem] = support; | - |
149 | } | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | bool QSupportedWritingSystems::supported(QFontDatabase::WritingSystem writingSystem) const | - |
156 | { | - |
157 | return d->vector.at(writingSystem); | - |
158 | } | - |
159 | QPlatformFontDatabase::~QPlatformFontDatabase() | - |
160 | { | - |
161 | } | - |
162 | void QPlatformFontDatabase::populateFontDatabase() | - |
163 | { | - |
164 | QString fontpath = fontDir(); | - |
165 | if(!QFile::exists(fontpath)) { | - |
166 | QMessageLogger(__FILE__, 275281, __PRETTY_FUNCTION__).warning("QFontDatabase: Cannot find font directory '%s' - is Qt installed correctly?", | - |
167 | QString(QDir::toNativeSeparators(fontpath)).toLocal8Bit().constData()); | - |
168 | return; | - |
169 | } | - |
170 | | - |
171 | QDir dir(fontpath); | - |
172 | dir.setNameFilters(QStringList() << QLatin1String("*.qpf2")); | - |
173 | dir.refresh(); | - |
174 | for (int i = 0; i < int(dir.count()); ++i) { | - |
175 | const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i])); | - |
176 | QFile file(QString::fromLocal8Bit(fileName)); | - |
177 | if (file.open(QFile::ReadOnly)) { | - |
178 | const QByteArray fileData = file.readAll(); | - |
179 | QByteArray *fileDataPtr = new QByteArray(fileData); | - |
180 | registerQPF2Font(fileData, fileDataPtr); | - |
181 | } | - |
182 | } | - |
183 | } | - |
184 | void QPlatformFontDatabase::populateFamily(const QString &familyName) | - |
185 | { | - |
186 | (void)familyName;; | - |
187 | } | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | - |
193 | | - |
194 | | - |
195 | void QPlatformFontDatabase::invalidate() | - |
196 | { | - |
197 | } | - |
198 | | - |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | QFontEngineMulti *QPlatformFontDatabase::fontEngineMulti(QFontEngine *fontEngine, QChar::Script script) | - |
205 | { | - |
206 | return new QFontEngineMulti(fontEngine, script); | - |
207 | } | - |
208 | | - |
209 | | - |
210 | | - |
211 | | - |
212 | | - |
213 | QFontEngine *QPlatformFontDatabase::fontEngine(const QFontDef &fontDef, void *handle) | - |
214 | { | - |
215 | QByteArray *fileDataPtr = static_cast<QByteArray *>(handle); | - |
216 | QFontEngineQPF2 *engine = new QFontEngineQPF2(fontDef,*fileDataPtr); | - |
217 | | - |
218 | return engine; | - |
219 | } | - |
220 | | - |
221 | QFontEngine *QPlatformFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize, | - |
222 | QFont::HintingPreference hintingPreference) | - |
223 | { | - |
224 | (void)fontData;; | - |
225 | (void)pixelSize;; | - |
226 | (void)hintingPreference;; | - |
227 | QMessageLogger(__FILE__, 344350, __PRETTY_FUNCTION__).warning("This plugin does not support font engines created directly from font data"); | - |
228 | return 0; | - |
229 | } | - |
230 | QStringList QPlatformFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) | - |
231 | { | - |
232 | (void)fontData;; | - |
233 | (void)fileName;; | - |
234 | | - |
235 | QMessageLogger(__FILE__, 373379, __PRETTY_FUNCTION__).warning("This plugin does not support application fonts"); | - |
236 | return QStringList(); | - |
237 | } | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | void QPlatformFontDatabase::releaseHandle(void *handle) | - |
243 | { | - |
244 | QByteArray *fileDataPtr = static_cast<QByteArray *>(handle); | - |
245 | delete fileDataPtr; | - |
246 | } | - |
247 | | - |
248 | | - |
249 | | - |
250 | | - |
251 | QString QPlatformFontDatabase::fontDir() const | - |
252 | { | - |
253 | QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR")); | - |
254 | if (fontpath.isEmpty()) { | - |
255 | fontpath = QLibraryInfo::location(QLibraryInfo::LibrariesPath); | - |
256 | fontpath += QLatin1String("/fonts"); | - |
257 | } | - |
258 | | - |
259 | return fontpath; | - |
260 | } | - |
261 | | - |
262 | | - |
263 | | - |
264 | | - |
265 | | - |
266 | bool QPlatformFontDatabase::isPrivateFontFamily(const QString &family) const | - |
267 | { | - |
268 | (void)family;; | - |
269 | return false; | - |
270 | } | - |
271 | QFont QPlatformFontDatabase::defaultFont() const | - |
272 | { | - |
273 | return QFont(QLatin1String("Helvetica")); | - |
274 | } | - |
275 | | - |
276 | | - |
277 | | - |
278 | | - |
279 | | - |
280 | | - |
281 | | - |
282 | QString qt_resolveFontFamilyAlias(const QString &alias); | - |
283 | | - |
284 | QString QPlatformFontDatabase::resolveFontFamilyAlias(const QString &family) const | - |
285 | { | - |
286 | return qt_resolveFontFamilyAlias(family); | - |
287 | } | - |
288 | bool QPlatformFontDatabase::fontsAlwaysScalable() const | - |
289 | { | - |
290 | return false; | - |
291 | } | - |
292 | | - |
293 | | - |
294 | | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | QList<int> QPlatformFontDatabase::standardSizes() const | - |
300 | { | - |
301 | QList<int> ret; | - |
302 | static const quint8 standard[] = | - |
303 | { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; | - |
304 | static const int num_standards = int(sizeof standard / sizeof *standard); | - |
305 | ret.reserve(num_standards); | - |
306 | std::copy(standard, standard + num_standards, std::back_inserter(ret)); | - |
307 | return ret; | - |
308 | } | - |
309 | | - |
310 | QFontEngine::SubpixelAntialiasingType QPlatformFontDatabase::subpixelAntialiasingTypeHint() const | - |
311 | { | - |
312 | static int type = -1; | - |
313 | if (type == -1) { | - |
314 | if (QScreen *screen = QGuiApplication::primaryScreen()) | - |
315 | type = screen->handle()->subpixelAntialiasingTypeHint(); | - |
316 | } | - |
317 | return static_cast<QFontEngine::SubpixelAntialiasingType>(type); | - |
318 | } | - |
319 | | - |
320 | | - |
321 | | - |
322 | | - |
323 | static const quint8 requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2] = { | - |
324 | { 127, 127 }, | - |
325 | { 0, 127 }, | - |
326 | { 7, 127 }, | - |
327 | { 9, 127 }, | - |
328 | { 10, 127 }, | - |
329 | { 11, 127 }, | - |
330 | { 13, 127 }, | - |
331 | { 71, 127 }, | - |
332 | { 72, 127 }, | - |
333 | { 15, 127 }, | - |
334 | { 16, 127 }, | - |
335 | { 17, 127 }, | - |
336 | { 18, 127 }, | - |
337 | { 19, 127 }, | - |
338 | { 20, 127 }, | - |
339 | { 21, 127 }, | - |
340 | { 22, 127 }, | - |
341 | { 23, 127 }, | - |
342 | { 73, 127 }, | - |
343 | { 24, 127 }, | - |
344 | { 25, 127 }, | - |
345 | { 70, 127 }, | - |
346 | { 74, 127 }, | - |
347 | { 26, 127 }, | - |
348 | { 80, 127 }, | - |
349 | { 126, 127 }, | - |
350 | { 126, 127 }, | - |
351 | { 126, 127 }, | - |
352 | { 56, 127 }, | - |
353 | { 0, 127 }, | - |
354 | { 126, 127 }, | - |
355 | { 78, 127 }, | - |
356 | { 79, 127 }, | - |
357 | { 14, 127 }, | - |
358 | }; | - |
359 | | - |
360 | enum CsbBits { | - |
361 | Latin1CsbBit = 0, | - |
362 | CentralEuropeCsbBit = 1, | - |
363 | TurkishCsbBit = 4, | - |
364 | BalticCsbBit = 7, | - |
365 | CyrillicCsbBit = 2, | - |
366 | GreekCsbBit = 3, | - |
367 | HebrewCsbBit = 5, | - |
368 | ArabicCsbBit = 6, | - |
369 | VietnameseCsbBit = 8, | - |
370 | SimplifiedChineseCsbBit = 18, | - |
371 | TraditionalChineseCsbBit = 20, | - |
372 | ThaiCsbBit = 16, | - |
373 | JapaneseCsbBit = 17, | - |
374 | KoreanCsbBit = 19, | - |
375 | KoreanJohabCsbBit = 21, | - |
376 | SymbolCsbBit = 31 | - |
377 | }; | - |
378 | | - |
379 | | - |
380 | | - |
381 | | - |
382 | | - |
383 | | - |
384 | | - |
385 | QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]) | - |
386 | { | - |
387 | QSupportedWritingSystems writingSystems; | - |
388 | | - |
389 | bool hasScript = false; | - |
390 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { | - |
391 | int bit = requiredUnicodeBits[i][0]; | - |
392 | int index = bit/32; | - |
393 | int flag = 1 << (bit&31); | - |
394 | if (bit != 126 && (unicodeRange[index] & flag)) { | - |
395 | bit = requiredUnicodeBits[i][1]; | - |
396 | index = bit/32; | - |
397 | | - |
398 | flag = 1 << (bit&31); | - |
399 | if (bit == 127 || (unicodeRange[index] & flag)) { | - |
400 | writingSystems.setSupported(QFontDatabase::WritingSystem(i)); | - |
401 | hasScript = true; | - |
402 | | - |
403 | } | - |
404 | } | - |
405 | } | - |
406 | if (codePageRange[0] & ((1 << Latin1CsbBit) | (1 << CentralEuropeCsbBit) | (1 << TurkishCsbBit) | (1 << BalticCsbBit))) { | - |
407 | writingSystems.setSupported(QFontDatabase::Latin); | - |
408 | hasScript = true; | - |
409 | | - |
410 | } | - |
411 | if (codePageRange[0] & (1 << CyrillicCsbBit)) { | - |
412 | writingSystems.setSupported(QFontDatabase::Cyrillic); | - |
413 | hasScript = true; | - |
414 | | - |
415 | } | - |
416 | if (codePageRange[0] & (1 << GreekCsbBit)) { | - |
417 | writingSystems.setSupported(QFontDatabase::Greek); | - |
418 | hasScript = true; | - |
419 | | - |
420 | } | - |
421 | if (codePageRange[0] & (1 << HebrewCsbBit)) { | - |
422 | writingSystems.setSupported(QFontDatabase::Hebrew); | - |
423 | hasScript = true; | - |
424 | | - |
425 | } | - |
426 | if (codePageRange[0] & (1 << ArabicCsbBit)) { | - |
427 | writingSystems.setSupported(QFontDatabase::Arabic); | - |
428 | hasScript = true; | - |
429 | | - |
430 | } | - |
431 | if (codePageRange[0] & (1 << ThaiCsbBit)) { | - |
432 | writingSystems.setSupported(QFontDatabase::Thai); | - |
433 | hasScript = true; | - |
434 | | - |
435 | } | - |
436 | if (codePageRange[0] & (1 << VietnameseCsbBit)) { | - |
437 | writingSystems.setSupported(QFontDatabase::Vietnamese); | - |
438 | hasScript = true; | - |
439 | | - |
440 | } | - |
441 | if (codePageRange[0] & (1 << SimplifiedChineseCsbBit)) { | - |
442 | writingSystems.setSupported(QFontDatabase::SimplifiedChinese); | - |
443 | hasScript = true; | - |
444 | | - |
445 | } | - |
446 | if (codePageRange[0] & (1 << TraditionalChineseCsbBit)) { | - |
447 | writingSystems.setSupported(QFontDatabase::TraditionalChinese); | - |
448 | hasScript = true; | - |
449 | | - |
450 | } | - |
451 | if (codePageRange[0] & (1 << JapaneseCsbBit)) { | - |
452 | writingSystems.setSupported(QFontDatabase::Japanese); | - |
453 | hasScript = true; | - |
454 | | - |
455 | } | - |
456 | if (codePageRange[0] & ((1 << KoreanCsbBit) | (1 << KoreanJohabCsbBit))) { | - |
457 | writingSystems.setSupported(QFontDatabase::Korean); | - |
458 | hasScript = true; | - |
459 | | - |
460 | } | - |
461 | if (codePageRange[0] & (1U << SymbolCsbBit)) { | - |
462 | writingSystems = QSupportedWritingSystems(); | - |
463 | hasScript = false; | - |
464 | } | - |
465 | | - |
466 | if (!hasScript) | - |
467 | writingSystems.setSupported(QFontDatabase::Symbol); | - |
468 | | - |
469 | return writingSystems; | - |
470 | } | - |
471 | QFont::Weight QPlatformFontDatabase::weightFromInteger(int weight) | - |
472 | { | - |
473 | if (weight < 150) | - |
474 | return QFont::Thin; | - |
475 | if (weight < 250) | - |
476 | return QFont::ExtraLight; | - |
477 | if (weight < 350) | - |
478 | return QFont::Light; | - |
479 | if (weight < 450) | - |
480 | return QFont::Normal; | - |
481 | if (weight < 550) | - |
482 | return QFont::Medium; | - |
483 | if (weight < 650) | - |
484 | return QFont::DemiBold; | - |
485 | if (weight < 750) | - |
486 | return QFont::Bold; | - |
487 | if (weight < 850) | - |
488 | return QFont::ExtraBold; | - |
489 | return QFont::Black; | - |
490 | } | - |
491 | | - |
492 | | - |
493 | | - |
494 | | - |
495 | | - |
496 | | - |
497 | | - |
498 | void QPlatformFontDatabase::registerAliasToFontFamily(const QString &familyName, const QString &alias) | - |
499 | { | - |
500 | qt_registerAliasToFontFamily(familyName, alias); | - |
501 | } | - |
502 | | - |
| | |