/src/qtbase/src/gui/text/qplatformfontdatabase.cpp
Line | Count | Source |
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 | | |
4 | | #include "qplatformfontdatabase.h" |
5 | | #include <QtGui/private/qfontengine_p.h> |
6 | | #include <QtGui/private/qfontdatabase_p.h> |
7 | | #include <QtGui/QGuiApplication> |
8 | | #include <QtGui/QScreen> |
9 | | #include <qpa/qplatformscreen.h> |
10 | | #include <QtCore/QLibraryInfo> |
11 | | #include <QtCore/QDir> |
12 | | #include <QtCore/QMetaEnum> |
13 | | #include <QtCore/qendian.h> |
14 | | |
15 | | #include <algorithm> |
16 | | #include <iterator> |
17 | | |
18 | | QT_BEGIN_NAMESPACE |
19 | | |
20 | | using namespace Qt::StringLiterals; |
21 | | |
22 | | Q_LOGGING_CATEGORY(lcQpaFonts, "qt.qpa.fonts") |
23 | | |
24 | | void qt_registerFont(const QString &familyname, const QString &stylename, |
25 | | const QString &foundryname, int weight, |
26 | | QFont::Style style, int stretch, bool antialiased, |
27 | | bool scalable, int pixelSize, bool fixedPitch, bool colorFont, |
28 | | const QSupportedWritingSystems &writingSystems, void *hanlde); |
29 | | |
30 | | void qt_registerFontFamily(const QString &familyName); |
31 | | void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias); |
32 | | bool qt_isFontFamilyPopulated(const QString &familyName); |
33 | | |
34 | | /*! |
35 | | Registers a font with the given set of attributes describing the font's |
36 | | foundry, family name, style and stretch information, pixel size, and |
37 | | supported writing systems. Additional information about whether the font |
38 | | can be scaled and antialiased can also be provided. |
39 | | |
40 | | The foundry name and font family are described by \a foundryName and |
41 | | \a familyName. The font weight (light, normal, bold, etc.), style (normal, |
42 | | oblique, italic) and stretch information (condensed, expanded, unstretched, |
43 | | etc.) are specified by \a weight, \a style and \a stretch. |
44 | | |
45 | | Some fonts can be antialiased and scaled; \a scalable and \a antialiased |
46 | | can be set to true for fonts with these attributes. The intended pixel |
47 | | size of non-scalable fonts is specified by \a pixelSize; this value will be |
48 | | ignored for scalable fonts. |
49 | | |
50 | | The writing systems supported by the font are specified by the |
51 | | \a writingSystems argument. |
52 | | |
53 | | \sa registerFontFamily() |
54 | | */ |
55 | | void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &stylename, |
56 | | const QString &foundryname, QFont::Weight weight, |
57 | | QFont::Style style, QFont::Stretch stretch, bool antialiased, |
58 | | bool scalable, int pixelSize, bool fixedPitch, bool colorFont, |
59 | | const QSupportedWritingSystems &writingSystems, void *usrPtr) |
60 | 0 | { |
61 | 0 | if (scalable) |
62 | 0 | pixelSize = 0; |
63 | |
|
64 | 0 | qt_registerFont(familyname, stylename, foundryname, weight, style, |
65 | 0 | stretch, antialiased, scalable, pixelSize, |
66 | 0 | fixedPitch, colorFont, writingSystems, usrPtr); |
67 | 0 | } |
68 | | |
69 | | /*! |
70 | | Registers a font family with the font database. The font will be |
71 | | lazily populated by a callback to populateFamily() when the font |
72 | | database determines that the family needs population. |
73 | | |
74 | | \sa populateFamily(), registerFont() |
75 | | */ |
76 | | void QPlatformFontDatabase::registerFontFamily(const QString &familyName) |
77 | 0 | { |
78 | 0 | qt_registerFontFamily(familyName); |
79 | 0 | } |
80 | | |
81 | | class QWritingSystemsPrivate |
82 | | { |
83 | | public: |
84 | | QWritingSystemsPrivate() |
85 | 0 | : ref(1) |
86 | 0 | , list(QFontDatabase::WritingSystemsCount, false) |
87 | 0 | { |
88 | 0 | } |
89 | | |
90 | | QWritingSystemsPrivate(const QWritingSystemsPrivate *other) |
91 | 0 | : ref(1) |
92 | 0 | , list(other->list) |
93 | 0 | { |
94 | 0 | } |
95 | | |
96 | | QAtomicInt ref; |
97 | | QList<bool> list; |
98 | | }; |
99 | | |
100 | | /*! |
101 | | Constructs a new object to handle supported writing systems. |
102 | | */ |
103 | | QSupportedWritingSystems::QSupportedWritingSystems() |
104 | 0 | { |
105 | 0 | d = new QWritingSystemsPrivate; |
106 | 0 | } |
107 | | |
108 | | /*! |
109 | | Constructs a copy of the \a other writing systems object. |
110 | | */ |
111 | | QSupportedWritingSystems::QSupportedWritingSystems(const QSupportedWritingSystems &other) |
112 | 0 | { |
113 | 0 | d = other.d; |
114 | 0 | d->ref.ref(); |
115 | 0 | } |
116 | | |
117 | | /*! |
118 | | Constructs a copy of the \a other writing systems object. |
119 | | */ |
120 | | QSupportedWritingSystems &QSupportedWritingSystems::operator=(const QSupportedWritingSystems &other) |
121 | 0 | { |
122 | 0 | if (d != other.d) { |
123 | 0 | other.d->ref.ref(); |
124 | 0 | if (!d->ref.deref()) |
125 | 0 | delete d; |
126 | 0 | d = other.d; |
127 | 0 | } |
128 | 0 | return *this; |
129 | 0 | } |
130 | | |
131 | | bool operator==(const QSupportedWritingSystems &lhs, const QSupportedWritingSystems &rhs) |
132 | 0 | { |
133 | 0 | return !(lhs != rhs); |
134 | 0 | } |
135 | | |
136 | | bool operator!=(const QSupportedWritingSystems &lhs, const QSupportedWritingSystems &rhs) |
137 | 0 | { |
138 | 0 | if (lhs.d == rhs.d) |
139 | 0 | return false; |
140 | | |
141 | 0 | Q_ASSERT(lhs.d->list.size() == rhs.d->list.size()); |
142 | 0 | Q_ASSERT(lhs.d->list.size() == QFontDatabase::WritingSystemsCount); |
143 | 0 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { |
144 | 0 | if (lhs.d->list.at(i) != rhs.d->list.at(i)) |
145 | 0 | return true; |
146 | 0 | } |
147 | | |
148 | 0 | return false; |
149 | 0 | } |
150 | | |
151 | | #ifndef QT_NO_DEBUG_STREAM |
152 | | QDebug operator<<(QDebug debug, const QSupportedWritingSystems &sws) |
153 | 0 | { |
154 | 0 | const QMetaObject *mo = &QFontDatabase::staticMetaObject; |
155 | 0 | QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("WritingSystem")); |
156 | |
|
157 | 0 | QDebugStateSaver saver(debug); |
158 | 0 | debug.nospace() << "QSupportedWritingSystems("; |
159 | 0 | int i = sws.d->list.indexOf(true); |
160 | 0 | while (i > 0) { |
161 | 0 | debug << me.valueToKey(i); |
162 | 0 | i = sws.d->list.indexOf(true, i + 1); |
163 | 0 | if (i > 0) |
164 | 0 | debug << ", "; |
165 | 0 | } |
166 | 0 | debug << ")"; |
167 | 0 | return debug; |
168 | 0 | } |
169 | | #endif |
170 | | |
171 | | /*! |
172 | | Destroys the supported writing systems object. |
173 | | */ |
174 | | QSupportedWritingSystems::~QSupportedWritingSystems() |
175 | 0 | { |
176 | 0 | if (!d->ref.deref()) |
177 | 0 | delete d; |
178 | 0 | } |
179 | | |
180 | | /*! |
181 | | \internal |
182 | | */ |
183 | | void QSupportedWritingSystems::detach() |
184 | 0 | { |
185 | 0 | if (d->ref.loadRelaxed() != 1) { |
186 | 0 | QWritingSystemsPrivate *newd = new QWritingSystemsPrivate(d); |
187 | 0 | if (!d->ref.deref()) |
188 | 0 | delete d; |
189 | 0 | d = newd; |
190 | 0 | } |
191 | 0 | } |
192 | | |
193 | | /*! |
194 | | Sets or clears support for the specified \a writingSystem based on the |
195 | | value given by \a support. |
196 | | */ |
197 | | void QSupportedWritingSystems::setSupported(QFontDatabase::WritingSystem writingSystem, bool support) |
198 | 0 | { |
199 | 0 | detach(); |
200 | 0 | d->list[writingSystem] = support; |
201 | 0 | } |
202 | | |
203 | | /*! |
204 | | Returns \c true if the writing system specified by \a writingSystem is |
205 | | supported; otherwise returns \c false. |
206 | | */ |
207 | | bool QSupportedWritingSystems::supported(QFontDatabase::WritingSystem writingSystem) const |
208 | 0 | { |
209 | 0 | return d->list.at(writingSystem); |
210 | 0 | } |
211 | | |
212 | | /*! |
213 | | \class QSupportedWritingSystems |
214 | | \brief The QSupportedWritingSystems class is used when registering fonts with the internal Qt |
215 | | fontdatabase. |
216 | | \ingroup painting |
217 | | \inmodule QtGui |
218 | | |
219 | | Its to provide an easy to use interface for indicating what writing systems a specific font |
220 | | supports. |
221 | | |
222 | | */ |
223 | | |
224 | | /*! |
225 | | \internal |
226 | | */ |
227 | | QPlatformFontDatabase::~QPlatformFontDatabase() |
228 | 0 | { |
229 | 0 | } |
230 | | |
231 | | /*! |
232 | | This function is called once at startup by Qt's internal font database. |
233 | | Reimplement this function in a subclass for a convenient place to initialize |
234 | | the internal font database. |
235 | | |
236 | | You may lazily populate the database by calling registerFontFamily() instead |
237 | | of registerFont(), in which case you'll get a callback to populateFamily() |
238 | | when the required family needs population. You then call registerFont() to |
239 | | finish population of the family. |
240 | | |
241 | | The default implementation does nothing. |
242 | | */ |
243 | | void QPlatformFontDatabase::populateFontDatabase() |
244 | 0 | { |
245 | 0 | } |
246 | | |
247 | | /*! |
248 | | This function is called whenever a lazily populated family, populated |
249 | | through registerFontFamily(), needs full population. |
250 | | |
251 | | You are expected to fully populate the family by calling registerFont() |
252 | | for each font that matches the family name. |
253 | | */ |
254 | | void QPlatformFontDatabase::populateFamily(const QString &familyName) |
255 | 0 | { |
256 | 0 | Q_UNUSED(familyName); |
257 | 0 | } |
258 | | |
259 | | /*! |
260 | | This function is called whenever the font database is invalidated. |
261 | | |
262 | | Reimplement this function to clear any internal data structures that |
263 | | will need to be rebuilt at the next call to populateFontDatabase(). |
264 | | */ |
265 | | void QPlatformFontDatabase::invalidate() |
266 | 0 | { |
267 | 0 | } |
268 | | |
269 | | /*! |
270 | | Returns a multi font engine in the specified \a script to encapsulate \a fontEngine with the |
271 | | option to fall back to the fonts given by \a fallbacks if \a fontEngine does not support |
272 | | a certain character. |
273 | | */ |
274 | | QFontEngineMulti *QPlatformFontDatabase::fontEngineMulti(QFontEngine *fontEngine, |
275 | | QFontDatabasePrivate::ExtendedScript script) |
276 | 0 | { |
277 | 0 | return new QFontEngineMulti(fontEngine, script); |
278 | 0 | } |
279 | | |
280 | | /*! |
281 | | Returns the font engine that can be used to render the font described by |
282 | | the font definition, \a fontDef, in the specified \a script. |
283 | | |
284 | | This function is called by QFontDatabase both for system fonts provided |
285 | | by the platform font database, as well as for application fonts added by |
286 | | the application developer. |
287 | | |
288 | | The handle is the QPlatformFontDatabase specific handle passed when |
289 | | registering the font family via QPlatformFontDatabase::registerFont. |
290 | | |
291 | | The function is called for both fonts added via a filename as well |
292 | | as fonts added from QByteArray data. Subclasses will need to handle |
293 | | both cases via its platform specific handle. |
294 | | */ |
295 | | QFontEngine *QPlatformFontDatabase::fontEngine(const QFontDef &fontDef, void *handle) |
296 | 0 | { |
297 | 0 | Q_UNUSED(fontDef); |
298 | 0 | Q_UNUSED(handle); |
299 | 0 | qWarning("This plugin does not support loading system fonts."); |
300 | 0 | return nullptr; |
301 | 0 | } |
302 | | |
303 | | /*! |
304 | | Returns the font engine that will be used to back a QRawFont, |
305 | | based on the given \fontData, \a pixelSize, and \a hintingPreference. |
306 | | |
307 | | This function is called by QRawFont, and does not play a part in |
308 | | the normal operations of QFontDatabase. |
309 | | */ |
310 | | QFontEngine *QPlatformFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize, |
311 | | QFont::HintingPreference hintingPreference) |
312 | 0 | { |
313 | 0 | Q_UNUSED(fontData); |
314 | 0 | Q_UNUSED(pixelSize); |
315 | 0 | Q_UNUSED(hintingPreference); |
316 | 0 | qWarning("This plugin does not support font engines created directly from font data"); |
317 | 0 | return nullptr; |
318 | 0 | } |
319 | | |
320 | | /*! |
321 | | Adds an application font described by the font contained supplied \a fontData |
322 | | or using the font contained in the file referenced by \a fileName. Returns |
323 | | a list of family names, or an empty list if the font could not be added. |
324 | | |
325 | | If \a applicationFont is non-null, its \c properties list should be filled |
326 | | with information from the loaded fonts. This is exposed through FontLoader in |
327 | | Qt Quick where it is needed for disambiguating fonts in the same family. When |
328 | | the function exits, the \a applicationFont should contain an entry of properties |
329 | | per font in the file, or it should be empty if no font was loaded. |
330 | | |
331 | | \note The default implementation of this function does not add an application |
332 | | font. Subclasses should reimplement this function to perform the necessary |
333 | | loading and registration of fonts. |
334 | | */ |
335 | | QStringList QPlatformFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName, QFontDatabasePrivate::ApplicationFont *applicationFont) |
336 | 0 | { |
337 | 0 | Q_UNUSED(fontData); |
338 | 0 | Q_UNUSED(fileName); |
339 | 0 | Q_UNUSED(applicationFont); |
340 | |
|
341 | 0 | if (applicationFont != nullptr) |
342 | 0 | applicationFont->properties.clear(); |
343 | |
|
344 | 0 | qWarning("This plugin does not support application fonts"); |
345 | |
|
346 | 0 | return QStringList(); |
347 | 0 | } |
348 | | |
349 | | /*! |
350 | | Releases the specified font \a handle. |
351 | | */ |
352 | | void QPlatformFontDatabase::releaseHandle(void *handle) |
353 | 0 | { |
354 | 0 | QByteArray *fileDataPtr = static_cast<QByteArray *>(handle); |
355 | 0 | delete fileDataPtr; |
356 | 0 | } |
357 | | |
358 | | /*! |
359 | | Returns the directory containing the fonts used by the database. |
360 | | */ |
361 | | QString QPlatformFontDatabase::fontDir() const |
362 | 0 | { |
363 | 0 | QString fontpath = qEnvironmentVariable("QT_QPA_FONTDIR"); |
364 | 0 | if (fontpath.isEmpty()) |
365 | 0 | fontpath = QLibraryInfo::path(QLibraryInfo::LibrariesPath) + "/fonts"_L1; |
366 | |
|
367 | 0 | return fontpath; |
368 | 0 | } |
369 | | |
370 | | /*! |
371 | | Returns true if the font family is private. For any given family name, |
372 | | the result is platform dependent. |
373 | | */ |
374 | | bool QPlatformFontDatabase::isPrivateFontFamily(const QString &family) const |
375 | 0 | { |
376 | 0 | Q_UNUSED(family); |
377 | 0 | return false; |
378 | 0 | } |
379 | | |
380 | | /*! |
381 | | Returns the default system font. |
382 | | |
383 | | \sa QGuiApplication::font() |
384 | | \since 5.0 |
385 | | */ |
386 | | |
387 | | QFont QPlatformFontDatabase::defaultFont() const |
388 | 0 | { |
389 | 0 | return QFont("Helvetica"_L1); |
390 | 0 | } |
391 | | |
392 | | |
393 | | QString qt_resolveFontFamilyAlias(const QString &alias); |
394 | | |
395 | | /*! |
396 | | Resolve alias to actual font family names. |
397 | | |
398 | | \since 5.0 |
399 | | */ |
400 | | QString QPlatformFontDatabase::resolveFontFamilyAlias(const QString &family) const |
401 | 0 | { |
402 | 0 | return qt_resolveFontFamilyAlias(family); |
403 | 0 | } |
404 | | |
405 | | /*! |
406 | | Return true if all fonts are considered scalable when using this font database. |
407 | | Defaults to false. |
408 | | |
409 | | \since 5.0 |
410 | | */ |
411 | | |
412 | | bool QPlatformFontDatabase::fontsAlwaysScalable() const |
413 | 0 | { |
414 | 0 | return false; |
415 | 0 | } |
416 | | |
417 | | /*! |
418 | | Return list of standard font sizes when using this font database. |
419 | | |
420 | | \since 5.0 |
421 | | */ |
422 | | |
423 | | QList<int> QPlatformFontDatabase::standardSizes() const |
424 | 0 | { |
425 | 0 | QList<int> ret; |
426 | 0 | static const quint8 standard[] = |
427 | 0 | { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; |
428 | 0 | static const int num_standards = int(sizeof standard / sizeof *standard); |
429 | 0 | ret.reserve(num_standards); |
430 | 0 | std::copy(standard, standard + num_standards, std::back_inserter(ret)); |
431 | 0 | return ret; |
432 | 0 | } |
433 | | |
434 | | // see the Unicode subset bitfields in the MSDN docs |
435 | | static const quint8 requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2] = { |
436 | | { 127, 127 }, // Any |
437 | | { 0, 127 }, // Latin |
438 | | { 7, 127 }, // Greek |
439 | | { 9, 127 }, // Cyrillic |
440 | | { 10, 127 }, // Armenian |
441 | | { 11, 127 }, // Hebrew |
442 | | { 13, 127 }, // Arabic |
443 | | { 71, 127 }, // Syriac |
444 | | { 72, 127 }, // Thaana |
445 | | { 15, 127 }, // Devanagari |
446 | | { 16, 127 }, // Bengali |
447 | | { 17, 127 }, // Gurmukhi |
448 | | { 18, 127 }, // Gujarati |
449 | | { 19, 127 }, // Oriya |
450 | | { 20, 127 }, // Tamil |
451 | | { 21, 127 }, // Telugu |
452 | | { 22, 127 }, // Kannada |
453 | | { 23, 127 }, // Malayalam |
454 | | { 73, 127 }, // Sinhala |
455 | | { 24, 127 }, // Thai |
456 | | { 25, 127 }, // Lao |
457 | | { 70, 127 }, // Tibetan |
458 | | { 74, 127 }, // Myanmar |
459 | | { 26, 127 }, // Georgian |
460 | | { 80, 127 }, // Khmer |
461 | | { 126, 127 }, // SimplifiedChinese |
462 | | { 126, 127 }, // TraditionalChinese |
463 | | { 126, 127 }, // Japanese |
464 | | { 56, 127 }, // Korean |
465 | | { 0, 127 }, // Vietnamese (same as latin1) |
466 | | { 126, 127 }, // Other |
467 | | { 78, 127 }, // Ogham |
468 | | { 79, 127 }, // Runic |
469 | | { 14, 127 }, // Nko |
470 | | }; |
471 | | |
472 | | enum CsbBits { |
473 | | Latin1CsbBit = 0, |
474 | | CentralEuropeCsbBit = 1, |
475 | | TurkishCsbBit = 4, |
476 | | BalticCsbBit = 7, |
477 | | CyrillicCsbBit = 2, |
478 | | GreekCsbBit = 3, |
479 | | HebrewCsbBit = 5, |
480 | | ArabicCsbBit = 6, |
481 | | VietnameseCsbBit = 8, |
482 | | SimplifiedChineseCsbBit = 18, |
483 | | TraditionalChineseCsbBit = 20, |
484 | | ThaiCsbBit = 16, |
485 | | JapaneseCsbBit = 17, |
486 | | KoreanCsbBit = 19, |
487 | | KoreanJohabCsbBit = 21, |
488 | | SymbolCsbBit = 31 |
489 | | }; |
490 | | |
491 | | /*! |
492 | | Helper function that determines the writing system support based on the contents of the OS/2 table |
493 | | in the font. |
494 | | |
495 | | \since 6.0 |
496 | | */ |
497 | | QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromOS2Table(const char *os2Table, size_t length) |
498 | 0 | { |
499 | 0 | if (length >= 86) { |
500 | 0 | quint32 unicodeRange[4] = { |
501 | 0 | qFromBigEndian<quint32>(os2Table + 42), |
502 | 0 | qFromBigEndian<quint32>(os2Table + 46), |
503 | 0 | qFromBigEndian<quint32>(os2Table + 50), |
504 | 0 | qFromBigEndian<quint32>(os2Table + 54) |
505 | 0 | }; |
506 | 0 | quint32 codePageRange[2] = { |
507 | 0 | qFromBigEndian<quint32>(os2Table + 78), |
508 | 0 | qFromBigEndian<quint32>(os2Table + 82) |
509 | 0 | }; |
510 | |
|
511 | 0 | return writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); |
512 | 0 | } |
513 | | |
514 | 0 | return QSupportedWritingSystems(); |
515 | 0 | } |
516 | | |
517 | | /*! |
518 | | Helper function that determines the writing systems support by a given |
519 | | \a unicodeRange and \a codePageRange. |
520 | | |
521 | | \since 5.1 |
522 | | */ |
523 | | QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]) |
524 | 0 | { |
525 | 0 | QSupportedWritingSystems writingSystems; |
526 | |
|
527 | 0 | bool hasScript = false; |
528 | 0 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { |
529 | 0 | int bit = requiredUnicodeBits[i][0]; |
530 | 0 | int index = bit/32; |
531 | 0 | int flag = 1 << (bit&31); |
532 | 0 | if (bit != 126 && (unicodeRange[index] & flag)) { |
533 | 0 | bit = requiredUnicodeBits[i][1]; |
534 | 0 | index = bit/32; |
535 | |
|
536 | 0 | flag = 1 << (bit&31); |
537 | 0 | if (bit == 127 || (unicodeRange[index] & flag)) { |
538 | 0 | writingSystems.setSupported(QFontDatabase::WritingSystem(i)); |
539 | 0 | hasScript = true; |
540 | | // qDebug("font %s: index=%d, flag=%8x supports script %d", familyName.latin1(), index, flag, i); |
541 | 0 | } |
542 | 0 | } |
543 | 0 | } |
544 | 0 | if (codePageRange[0] & ((1 << Latin1CsbBit) | (1 << CentralEuropeCsbBit) | (1 << TurkishCsbBit) | (1 << BalticCsbBit))) { |
545 | 0 | writingSystems.setSupported(QFontDatabase::Latin); |
546 | 0 | hasScript = true; |
547 | | //qDebug("font %s supports Latin", familyName.latin1()); |
548 | 0 | } |
549 | 0 | if (codePageRange[0] & (1 << CyrillicCsbBit)) { |
550 | 0 | writingSystems.setSupported(QFontDatabase::Cyrillic); |
551 | 0 | hasScript = true; |
552 | | //qDebug("font %s supports Cyrillic", familyName.latin1()); |
553 | 0 | } |
554 | 0 | if (codePageRange[0] & (1 << GreekCsbBit)) { |
555 | 0 | writingSystems.setSupported(QFontDatabase::Greek); |
556 | 0 | hasScript = true; |
557 | | //qDebug("font %s supports Greek", familyName.latin1()); |
558 | 0 | } |
559 | 0 | if (codePageRange[0] & (1 << HebrewCsbBit)) { |
560 | 0 | writingSystems.setSupported(QFontDatabase::Hebrew); |
561 | 0 | hasScript = true; |
562 | | //qDebug("font %s supports Hebrew", familyName.latin1()); |
563 | 0 | } |
564 | 0 | if (codePageRange[0] & (1 << ArabicCsbBit)) { |
565 | 0 | writingSystems.setSupported(QFontDatabase::Arabic); |
566 | 0 | hasScript = true; |
567 | | //qDebug("font %s supports Arabic", familyName.latin1()); |
568 | 0 | } |
569 | 0 | if (codePageRange[0] & (1 << ThaiCsbBit)) { |
570 | 0 | writingSystems.setSupported(QFontDatabase::Thai); |
571 | 0 | hasScript = true; |
572 | | //qDebug("font %s supports Thai", familyName.latin1()); |
573 | 0 | } |
574 | 0 | if (codePageRange[0] & (1 << VietnameseCsbBit)) { |
575 | 0 | writingSystems.setSupported(QFontDatabase::Vietnamese); |
576 | 0 | hasScript = true; |
577 | | //qDebug("font %s supports Vietnamese", familyName.latin1()); |
578 | 0 | } |
579 | 0 | if (codePageRange[0] & (1 << SimplifiedChineseCsbBit)) { |
580 | 0 | writingSystems.setSupported(QFontDatabase::SimplifiedChinese); |
581 | 0 | hasScript = true; |
582 | | //qDebug("font %s supports Simplified Chinese", familyName.latin1()); |
583 | 0 | } |
584 | 0 | if (codePageRange[0] & (1 << TraditionalChineseCsbBit)) { |
585 | 0 | writingSystems.setSupported(QFontDatabase::TraditionalChinese); |
586 | 0 | hasScript = true; |
587 | | //qDebug("font %s supports Traditional Chinese", familyName.latin1()); |
588 | 0 | } |
589 | 0 | if (codePageRange[0] & (1 << JapaneseCsbBit)) { |
590 | 0 | writingSystems.setSupported(QFontDatabase::Japanese); |
591 | 0 | hasScript = true; |
592 | | //qDebug("font %s supports Japanese", familyName.latin1()); |
593 | 0 | } |
594 | 0 | if (codePageRange[0] & ((1 << KoreanCsbBit) | (1 << KoreanJohabCsbBit))) { |
595 | 0 | writingSystems.setSupported(QFontDatabase::Korean); |
596 | 0 | hasScript = true; |
597 | | //qDebug("font %s supports Korean", familyName.latin1()); |
598 | 0 | } |
599 | 0 | if (codePageRange[0] & (1U << SymbolCsbBit)) { |
600 | 0 | writingSystems = QSupportedWritingSystems(); |
601 | 0 | hasScript = false; |
602 | 0 | } |
603 | |
|
604 | 0 | if (!hasScript) |
605 | 0 | writingSystems.setSupported(QFontDatabase::Symbol); |
606 | |
|
607 | 0 | return writingSystems; |
608 | 0 | } |
609 | | |
610 | | /*! |
611 | | Helper function that register the \a alias for the \a familyName. |
612 | | |
613 | | \since 5.2 |
614 | | */ |
615 | | |
616 | | void QPlatformFontDatabase::registerAliasToFontFamily(const QString &familyName, const QString &alias) |
617 | 0 | { |
618 | 0 | qt_registerAliasToFontFamily(familyName, alias); |
619 | 0 | } |
620 | | |
621 | | /*! |
622 | | Requests that the platform font database should be repopulated. |
623 | | |
624 | | This will result in invalidating the entire font database. |
625 | | |
626 | | The next time the font database is accessed it will be repopulated |
627 | | via a call to QPlatformFontDatabase::populate(). |
628 | | |
629 | | Application fonts will not be removed, and will be automatically |
630 | | populated when the font database is repopulated. |
631 | | |
632 | | \since 6.4 |
633 | | */ |
634 | | void QPlatformFontDatabase::repopulateFontDatabase() |
635 | 0 | { |
636 | 0 | QFontDatabasePrivate::instance()->invalidate(); |
637 | 0 | } |
638 | | |
639 | | /*! |
640 | | Helper function that returns true if the font family has already been registered and populated. |
641 | | |
642 | | \since 5.14 |
643 | | */ |
644 | | bool QPlatformFontDatabase::isFamilyPopulated(const QString &familyName) |
645 | 0 | { |
646 | 0 | return qt_isFontFamilyPopulated(familyName); |
647 | 0 | } |
648 | | |
649 | | /*! |
650 | | Returns true if this font database supports loading named instances from variable application |
651 | | fonts. |
652 | | |
653 | | \since 6.7 |
654 | | */ |
655 | | bool QPlatformFontDatabase::supportsVariableApplicationFonts() const |
656 | 0 | { |
657 | 0 | return false; |
658 | 0 | } |
659 | | |
660 | | /*! |
661 | | Returns true if this font database supports loading color fonts in the COLRv0 format. |
662 | | |
663 | | \since 6.9 |
664 | | */ |
665 | | bool QPlatformFontDatabase::supportsColrv0Fonts() const |
666 | 0 | { |
667 | 0 | return false; |
668 | 0 | } |
669 | | |
670 | | /*! |
671 | | \class QPlatformFontDatabase |
672 | | \since 5.0 |
673 | | \internal |
674 | | \preliminary |
675 | | \ingroup qpa |
676 | | \ingroup painting |
677 | | |
678 | | \brief The QPlatformFontDatabase class makes it possible to customize how fonts |
679 | | are discovered and how they are rendered |
680 | | |
681 | | QPlatformFontDatabase is the superclass which is intended to let platform implementations use |
682 | | native font handling. |
683 | | |
684 | | Qt has its internal font database which it uses to discover available fonts on the |
685 | | user's system. To be able to populate this database subclass this class, and |
686 | | reimplement populateFontDatabase(). |
687 | | |
688 | | Use the function registerFont() to populate the internal font database. |
689 | | |
690 | | Sometimes a specified font does not have the required glyphs; in such a case, the |
691 | | fallbackForFamily() function is called automatically to find alternative font |
692 | | families that can supply alternatives to the missing glyphs. |
693 | | |
694 | | \sa QSupportedWritingSystems |
695 | | */ |
696 | | QT_END_NAMESPACE |