Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qplatformfontdatabase.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
29 | ** | - | ||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||
31 | ** | - | ||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||
33 | - | |||||||||||||
34 | #include "qplatformfontdatabase.h" | - | ||||||||||||
35 | #include <QtGui/private/qfontengine_p.h> | - | ||||||||||||
36 | #include <QtGui/private/qfontengine_qpf2_p.h> | - | ||||||||||||
37 | #include <QtGui/QGuiApplication> | - | ||||||||||||
38 | #include <QtGui/QScreen> | - | ||||||||||||
39 | #include <qpa/qplatformscreen.h> | - | ||||||||||||
40 | #include <QtCore/QLibraryInfo> | - | ||||||||||||
41 | #include <QtCore/QDir> | - | ||||||||||||
42 | - | |||||||||||||
43 | #include <algorithm> | - | ||||||||||||
44 | #include <iterator> | - | ||||||||||||
45 | - | |||||||||||||
46 | QT_BEGIN_NAMESPACE | - | ||||||||||||
47 | - | |||||||||||||
48 | void qt_registerFont(const QString &familyname, const QString &stylename, | - | ||||||||||||
49 | const QString &foundryname, int weight, | - | ||||||||||||
50 | QFont::Style style, int stretch, bool antialiased, | - | ||||||||||||
51 | bool scalable, int pixelSize, bool fixedPitch, | - | ||||||||||||
52 | const QSupportedWritingSystems &writingSystems, void *hanlde); | - | ||||||||||||
53 | - | |||||||||||||
54 | void qt_registerFontFamily(const QString &familyName); | - | ||||||||||||
55 | void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias); | - | ||||||||||||
56 | - | |||||||||||||
57 | /*! | - | ||||||||||||
58 | \fn void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *handle) | - | ||||||||||||
59 | - | |||||||||||||
60 | Registers the pre-rendered QPF2 font contained in the given \a dataArray. | - | ||||||||||||
61 | - | |||||||||||||
62 | \sa registerFont() | - | ||||||||||||
63 | */ | - | ||||||||||||
64 | void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *handle) | - | ||||||||||||
65 | { | - | ||||||||||||
66 | if (dataArray.size() == 0)
| 0 | ||||||||||||
67 | return; never executed: return; | 0 | ||||||||||||
68 | - | |||||||||||||
69 | const uchar *data = reinterpret_cast<const uchar *>(dataArray.constData()); | - | ||||||||||||
70 | if (QFontEngineQPF2::verifyHeader(data, dataArray.size())) {
| 0 | ||||||||||||
71 | QString fontName = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_FontName).toString(); | - | ||||||||||||
72 | int pixelSize = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_PixelSize).toInt(); | - | ||||||||||||
73 | QVariant weight = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_Weight); | - | ||||||||||||
74 | QVariant style = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_Style); | - | ||||||||||||
75 | QByteArray writingSystemBits = QFontEngineQPF2::extractHeaderField(data, QFontEngineQPF2::Tag_WritingSystems).toByteArray(); | - | ||||||||||||
76 | - | |||||||||||||
77 | if (!fontName.isEmpty() && pixelSize) {
| 0 | ||||||||||||
78 | QFont::Weight fontWeight = QFont::Normal; | - | ||||||||||||
79 | if (weight.type() == QVariant::Int || weight.type() == QVariant::UInt)
| 0 | ||||||||||||
80 | fontWeight = QFont::Weight(weight.toInt()); never executed: fontWeight = QFont::Weight(weight.toInt()); | 0 | ||||||||||||
81 | - | |||||||||||||
82 | QFont::Style fontStyle = static_cast<QFont::Style>(style.toInt()); | - | ||||||||||||
83 | - | |||||||||||||
84 | QSupportedWritingSystems writingSystems; | - | ||||||||||||
85 | for (int i = 0; i < writingSystemBits.count(); ++i) {
| 0 | ||||||||||||
86 | uchar currentByte = writingSystemBits.at(i); | - | ||||||||||||
87 | for (int j = 0; j < 8; ++j) {
| 0 | ||||||||||||
88 | if (currentByte & 1)
| 0 | ||||||||||||
89 | writingSystems.setSupported(QFontDatabase::WritingSystem(i * 8 + j)); never executed: writingSystems.setSupported(QFontDatabase::WritingSystem(i * 8 + j)); | 0 | ||||||||||||
90 | currentByte >>= 1; | - | ||||||||||||
91 | } never executed: end of block | 0 | ||||||||||||
92 | } never executed: end of block | 0 | ||||||||||||
93 | QFont::Stretch stretch = QFont::Unstretched; | - | ||||||||||||
94 | registerFont(fontName,QString(),QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,false,writingSystems,handle); | - | ||||||||||||
95 | } never executed: end of block | 0 | ||||||||||||
96 | } else { never executed: end of block | 0 | ||||||||||||
97 | qDebug() << "header verification of QPF2 font failed. maybe it is corrupt?"; | - | ||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||
99 | } | - | ||||||||||||
100 | - | |||||||||||||
101 | /*! | - | ||||||||||||
102 | Registers a font with the given set of attributes describing the font's | - | ||||||||||||
103 | foundry, family name, style and stretch information, pixel size, and | - | ||||||||||||
104 | supported writing systems. Additional information about whether the font | - | ||||||||||||
105 | can be scaled and antialiased can also be provided. | - | ||||||||||||
106 | - | |||||||||||||
107 | The foundry name and font family are described by \a foundryName and | - | ||||||||||||
108 | \a familyName. The font weight (light, normal, bold, etc.), style (normal, | - | ||||||||||||
109 | oblique, italic) and stretch information (condensed, expanded, unstretched, | - | ||||||||||||
110 | etc.) are specified by \a weight, \a style and \a stretch. | - | ||||||||||||
111 | - | |||||||||||||
112 | Some fonts can be antialiased and scaled; \a scalable and \a antialiased | - | ||||||||||||
113 | can be set to true for fonts with these attributes. The intended pixel | - | ||||||||||||
114 | size of non-scalable fonts is specified by \a pixelSize; this value will be | - | ||||||||||||
115 | ignored for scalable fonts. | - | ||||||||||||
116 | - | |||||||||||||
117 | The writing systems supported by the font are specified by the | - | ||||||||||||
118 | \a writingSystems argument. | - | ||||||||||||
119 | - | |||||||||||||
120 | \sa registerQPF2Font(), registerFontFamily() | - | ||||||||||||
121 | */ | - | ||||||||||||
122 | void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &stylename, | - | ||||||||||||
123 | const QString &foundryname, QFont::Weight weight, | - | ||||||||||||
124 | QFont::Style style, QFont::Stretch stretch, bool antialiased, | - | ||||||||||||
125 | bool scalable, int pixelSize, bool fixedPitch, | - | ||||||||||||
126 | const QSupportedWritingSystems &writingSystems, void *usrPtr) | - | ||||||||||||
127 | { | - | ||||||||||||
128 | if (scalable)
| 0 | ||||||||||||
129 | pixelSize = 0; never executed: pixelSize = 0; | 0 | ||||||||||||
130 | - | |||||||||||||
131 | qt_registerFont(familyname, stylename, foundryname, weight, style, | - | ||||||||||||
132 | stretch, antialiased, scalable, pixelSize, | - | ||||||||||||
133 | fixedPitch, writingSystems, usrPtr); | - | ||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||
135 | - | |||||||||||||
136 | /*! | - | ||||||||||||
137 | Registers a font family with the font database. The font will be | - | ||||||||||||
138 | lazily populated by a callback to populateFamily() when the font | - | ||||||||||||
139 | database determines that the family needs population. | - | ||||||||||||
140 | - | |||||||||||||
141 | \sa populateFamily(), registerFont() | - | ||||||||||||
142 | */ | - | ||||||||||||
143 | void QPlatformFontDatabase::registerFontFamily(const QString &familyName) | - | ||||||||||||
144 | { | - | ||||||||||||
145 | qt_registerFontFamily(familyName); | - | ||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||
147 | - | |||||||||||||
148 | class QWritingSystemsPrivate | - | ||||||||||||
149 | { | - | ||||||||||||
150 | public: | - | ||||||||||||
151 | QWritingSystemsPrivate() | - | ||||||||||||
152 | : ref(1) | - | ||||||||||||
153 | , vector(QFontDatabase::WritingSystemsCount,false) | - | ||||||||||||
154 | { | - | ||||||||||||
155 | } never executed: end of block | 0 | ||||||||||||
156 | - | |||||||||||||
157 | QWritingSystemsPrivate(const QWritingSystemsPrivate *other) | - | ||||||||||||
158 | : ref(1) | - | ||||||||||||
159 | , vector(other->vector) | - | ||||||||||||
160 | { | - | ||||||||||||
161 | } never executed: end of block | 0 | ||||||||||||
162 | - | |||||||||||||
163 | QAtomicInt ref; | - | ||||||||||||
164 | QVector<bool> vector; | - | ||||||||||||
165 | }; | - | ||||||||||||
166 | - | |||||||||||||
167 | /*! | - | ||||||||||||
168 | Constructs a new object to handle supported writing systems. | - | ||||||||||||
169 | */ | - | ||||||||||||
170 | QSupportedWritingSystems::QSupportedWritingSystems() | - | ||||||||||||
171 | { | - | ||||||||||||
172 | d = new QWritingSystemsPrivate; | - | ||||||||||||
173 | } never executed: end of block | 0 | ||||||||||||
174 | - | |||||||||||||
175 | /*! | - | ||||||||||||
176 | Constructs a copy of the \a other writing systems object. | - | ||||||||||||
177 | */ | - | ||||||||||||
178 | QSupportedWritingSystems::QSupportedWritingSystems(const QSupportedWritingSystems &other) | - | ||||||||||||
179 | { | - | ||||||||||||
180 | d = other.d; | - | ||||||||||||
181 | d->ref.ref(); | - | ||||||||||||
182 | } never executed: end of block | 0 | ||||||||||||
183 | - | |||||||||||||
184 | /*! | - | ||||||||||||
185 | Constructs a copy of the \a other writing systems object. | - | ||||||||||||
186 | */ | - | ||||||||||||
187 | QSupportedWritingSystems &QSupportedWritingSystems::operator=(const QSupportedWritingSystems &other) | - | ||||||||||||
188 | { | - | ||||||||||||
189 | if (d != other.d) {
| 0 | ||||||||||||
190 | other.d->ref.ref(); | - | ||||||||||||
191 | if (!d->ref.deref())
| 0 | ||||||||||||
192 | delete d; never executed: delete d; | 0 | ||||||||||||
193 | d = other.d; | - | ||||||||||||
194 | } never executed: end of block | 0 | ||||||||||||
195 | return *this; never executed: return *this; | 0 | ||||||||||||
196 | } | - | ||||||||||||
197 | - | |||||||||||||
198 | /*! | - | ||||||||||||
199 | Destroys the supported writing systems object. | - | ||||||||||||
200 | */ | - | ||||||||||||
201 | QSupportedWritingSystems::~QSupportedWritingSystems() | - | ||||||||||||
202 | { | - | ||||||||||||
203 | if (!d->ref.deref())
| 0 | ||||||||||||
204 | delete d; never executed: delete d; | 0 | ||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||
206 | - | |||||||||||||
207 | /*! | - | ||||||||||||
208 | \internal | - | ||||||||||||
209 | */ | - | ||||||||||||
210 | void QSupportedWritingSystems::detach() | - | ||||||||||||
211 | { | - | ||||||||||||
212 | if (d->ref.load() != 1) {
| 0 | ||||||||||||
213 | QWritingSystemsPrivate *newd = new QWritingSystemsPrivate(d); | - | ||||||||||||
214 | if (!d->ref.deref())
| 0 | ||||||||||||
215 | delete d; never executed: delete d; | 0 | ||||||||||||
216 | d = newd; | - | ||||||||||||
217 | } never executed: end of block | 0 | ||||||||||||
218 | } never executed: end of block | 0 | ||||||||||||
219 | - | |||||||||||||
220 | /*! | - | ||||||||||||
221 | Sets or clears support for the specified \a writingSystem based on the | - | ||||||||||||
222 | value given by \a support. | - | ||||||||||||
223 | */ | - | ||||||||||||
224 | void QSupportedWritingSystems::setSupported(QFontDatabase::WritingSystem writingSystem, bool support) | - | ||||||||||||
225 | { | - | ||||||||||||
226 | detach(); | - | ||||||||||||
227 | d->vector[writingSystem] = support; | - | ||||||||||||
228 | } never executed: end of block | 0 | ||||||||||||
229 | - | |||||||||||||
230 | /*! | - | ||||||||||||
231 | Returns \c true if the writing system specified by \a writingSystem is | - | ||||||||||||
232 | supported; otherwise returns \c false. | - | ||||||||||||
233 | */ | - | ||||||||||||
234 | bool QSupportedWritingSystems::supported(QFontDatabase::WritingSystem writingSystem) const | - | ||||||||||||
235 | { | - | ||||||||||||
236 | return d->vector.at(writingSystem); never executed: return d->vector.at(writingSystem); | 0 | ||||||||||||
237 | } | - | ||||||||||||
238 | - | |||||||||||||
239 | /*! | - | ||||||||||||
240 | \class QSupportedWritingSystems | - | ||||||||||||
241 | \brief The QSupportedWritingSystems class is used when registering fonts with the internal Qt | - | ||||||||||||
242 | fontdatabase | - | ||||||||||||
243 | \ingroup painting | - | ||||||||||||
244 | \inmodule QtGui | - | ||||||||||||
245 | - | |||||||||||||
246 | Its to provide an easy to use interface for indicating what writing systems a specific font | - | ||||||||||||
247 | supports. | - | ||||||||||||
248 | - | |||||||||||||
249 | */ | - | ||||||||||||
250 | - | |||||||||||||
251 | /*! | - | ||||||||||||
252 | \internal | - | ||||||||||||
253 | */ | - | ||||||||||||
254 | QPlatformFontDatabase::~QPlatformFontDatabase() | - | ||||||||||||
255 | { | - | ||||||||||||
256 | } | - | ||||||||||||
257 | - | |||||||||||||
258 | /*! | - | ||||||||||||
259 | This function is called once at startup by Qt's internal font database. | - | ||||||||||||
260 | Reimplement this function in a subclass for a convenient place to initialize | - | ||||||||||||
261 | the internal font database. | - | ||||||||||||
262 | - | |||||||||||||
263 | You may lazily populate the database by calling registerFontFamily() instead | - | ||||||||||||
264 | of registerFont(), in which case you'll get a callback to populateFamily() | - | ||||||||||||
265 | when the required family needs population. You then call registerFont() to | - | ||||||||||||
266 | finish population of the family. | - | ||||||||||||
267 | - | |||||||||||||
268 | The default implementation looks in the fontDir() location and registers all | - | ||||||||||||
269 | QPF2 fonts. | - | ||||||||||||
270 | */ | - | ||||||||||||
271 | void QPlatformFontDatabase::populateFontDatabase() | - | ||||||||||||
272 | { | - | ||||||||||||
273 | QString fontpath = fontDir(); | - | ||||||||||||
274 | if(!QFile::exists(fontpath)) {
| 0 | ||||||||||||
275 | qWarning("QFontDatabase: Cannot find font directory '%s' - is Qt installed correctly?", | - | ||||||||||||
276 | qPrintable(QDir::toNativeSeparators(fontpath))); | - | ||||||||||||
277 | return; never executed: return; | 0 | ||||||||||||
278 | } | - | ||||||||||||
279 | - | |||||||||||||
280 | QDir dir(fontpath); | - | ||||||||||||
281 | dir.setNameFilters(QStringList() << QLatin1String("*.qpf2")); | - | ||||||||||||
282 | dir.refresh(); | - | ||||||||||||
283 | for (int i = 0; i < int(dir.count()); ++i) {
| 0 | ||||||||||||
284 | const QByteArray fileName = QFile::encodeName(dir.absoluteFilePath(dir[i])); | - | ||||||||||||
285 | QFile file(QString::fromLocal8Bit(fileName)); | - | ||||||||||||
286 | if (file.open(QFile::ReadOnly)) {
| 0 | ||||||||||||
287 | const QByteArray fileData = file.readAll(); | - | ||||||||||||
288 | QByteArray *fileDataPtr = new QByteArray(fileData); | - | ||||||||||||
289 | registerQPF2Font(fileData, fileDataPtr); | - | ||||||||||||
290 | } never executed: end of block | 0 | ||||||||||||
291 | } never executed: end of block | 0 | ||||||||||||
292 | } never executed: end of block | 0 | ||||||||||||
293 | - | |||||||||||||
294 | /*! | - | ||||||||||||
295 | This function is called whenever a lazily populated family, populated | - | ||||||||||||
296 | through registerFontFamily(), needs full population. | - | ||||||||||||
297 | - | |||||||||||||
298 | You are expected to fully populate the family by calling registerFont() | - | ||||||||||||
299 | for each font that matches the family name. | - | ||||||||||||
300 | */ | - | ||||||||||||
301 | void QPlatformFontDatabase::populateFamily(const QString &familyName) | - | ||||||||||||
302 | { | - | ||||||||||||
303 | Q_UNUSED(familyName); | - | ||||||||||||
304 | } never executed: end of block | 0 | ||||||||||||
305 | - | |||||||||||||
306 | /*! | - | ||||||||||||
307 | This function is called whenever the font database is invalidated. | - | ||||||||||||
308 | - | |||||||||||||
309 | Reimplement this function to clear any internal data structures that | - | ||||||||||||
310 | will need to be rebuilt at the next call to populateFontDatabase(). | - | ||||||||||||
311 | */ | - | ||||||||||||
312 | void QPlatformFontDatabase::invalidate() | - | ||||||||||||
313 | { | - | ||||||||||||
314 | } | - | ||||||||||||
315 | - | |||||||||||||
316 | /*! | - | ||||||||||||
317 | Returns a multi font engine in the specified \a script to encapsulate \a fontEngine with the | - | ||||||||||||
318 | option to fall back to the fonts given by \a fallbacks if \a fontEngine does not support | - | ||||||||||||
319 | a certain character. | - | ||||||||||||
320 | */ | - | ||||||||||||
321 | QFontEngineMulti *QPlatformFontDatabase::fontEngineMulti(QFontEngine *fontEngine, QChar::Script script) | - | ||||||||||||
322 | { | - | ||||||||||||
323 | return new QFontEngineMulti(fontEngine, script); never executed: return new QFontEngineMulti(fontEngine, script); | 0 | ||||||||||||
324 | } | - | ||||||||||||
325 | - | |||||||||||||
326 | /*! | - | ||||||||||||
327 | Returns the font engine that can be used to render the font described by | - | ||||||||||||
328 | the font definition, \a fontDef, in the specified \a script. | - | ||||||||||||
329 | */ | - | ||||||||||||
330 | QFontEngine *QPlatformFontDatabase::fontEngine(const QFontDef &fontDef, void *handle) | - | ||||||||||||
331 | { | - | ||||||||||||
332 | QByteArray *fileDataPtr = static_cast<QByteArray *>(handle); | - | ||||||||||||
333 | QFontEngineQPF2 *engine = new QFontEngineQPF2(fontDef,*fileDataPtr); | - | ||||||||||||
334 | //qDebug() << fontDef.pixelSize << fontDef.weight << fontDef.style << fontDef.stretch << fontDef.styleHint << fontDef.styleStrategy << fontDef.family; | - | ||||||||||||
335 | return engine; never executed: return engine; | 0 | ||||||||||||
336 | } | - | ||||||||||||
337 | - | |||||||||||||
338 | QFontEngine *QPlatformFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize, | - | ||||||||||||
339 | QFont::HintingPreference hintingPreference) | - | ||||||||||||
340 | { | - | ||||||||||||
341 | Q_UNUSED(fontData); | - | ||||||||||||
342 | Q_UNUSED(pixelSize); | - | ||||||||||||
343 | Q_UNUSED(hintingPreference); | - | ||||||||||||
344 | qWarning("This plugin does not support font engines created directly from font data"); | - | ||||||||||||
345 | return 0; never executed: return 0; | 0 | ||||||||||||
346 | } | - | ||||||||||||
347 | - | |||||||||||||
348 | /*! | - | ||||||||||||
349 | \fn QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const | - | ||||||||||||
350 | - | |||||||||||||
351 | Returns a list of alternative fonts for the specified \a family and | - | ||||||||||||
352 | \a style and \a script using the \a styleHint given. | - | ||||||||||||
353 | - | |||||||||||||
354 | Default implementation returns a list of fonts for which \a style and \a script support | - | ||||||||||||
355 | has been reported during the font database population. | - | ||||||||||||
356 | */ | - | ||||||||||||
357 | // implemented in qfontdatabase.cpp | - | ||||||||||||
358 | - | |||||||||||||
359 | /*! | - | ||||||||||||
360 | Adds an application font described by the font contained supplied \a fontData | - | ||||||||||||
361 | or using the font contained in the file referenced by \a fileName. Returns | - | ||||||||||||
362 | a list of family names, or an empty list if the font could not be added. | - | ||||||||||||
363 | - | |||||||||||||
364 | \note The default implementation of this function does not add an application | - | ||||||||||||
365 | font. Subclasses should reimplement this function to perform the necessary | - | ||||||||||||
366 | loading and registration of fonts. | - | ||||||||||||
367 | */ | - | ||||||||||||
368 | QStringList QPlatformFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) | - | ||||||||||||
369 | { | - | ||||||||||||
370 | Q_UNUSED(fontData); | - | ||||||||||||
371 | Q_UNUSED(fileName); | - | ||||||||||||
372 | - | |||||||||||||
373 | qWarning("This plugin does not support application fonts"); | - | ||||||||||||
374 | return QStringList(); never executed: return QStringList(); | 0 | ||||||||||||
375 | } | - | ||||||||||||
376 | - | |||||||||||||
377 | /*! | - | ||||||||||||
378 | Releases the specified font \a handle. | - | ||||||||||||
379 | */ | - | ||||||||||||
380 | void QPlatformFontDatabase::releaseHandle(void *handle) | - | ||||||||||||
381 | { | - | ||||||||||||
382 | QByteArray *fileDataPtr = static_cast<QByteArray *>(handle); | - | ||||||||||||
383 | delete fileDataPtr; | - | ||||||||||||
384 | } never executed: end of block | 0 | ||||||||||||
385 | - | |||||||||||||
386 | /*! | - | ||||||||||||
387 | Returns the directory containing the fonts used by the database. | - | ||||||||||||
388 | */ | - | ||||||||||||
389 | QString QPlatformFontDatabase::fontDir() const | - | ||||||||||||
390 | { | - | ||||||||||||
391 | QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR")); | - | ||||||||||||
392 | if (fontpath.isEmpty()) {
| 0 | ||||||||||||
393 | fontpath = QLibraryInfo::location(QLibraryInfo::LibrariesPath); | - | ||||||||||||
394 | fontpath += QLatin1String("/fonts"); | - | ||||||||||||
395 | } never executed: end of block | 0 | ||||||||||||
396 | - | |||||||||||||
397 | return fontpath; never executed: return fontpath; | 0 | ||||||||||||
398 | } | - | ||||||||||||
399 | - | |||||||||||||
400 | /*! | - | ||||||||||||
401 | Returns true if the font family is private. For any given family name, | - | ||||||||||||
402 | the result is platform dependent. | - | ||||||||||||
403 | */ | - | ||||||||||||
404 | bool QPlatformFontDatabase::isPrivateFontFamily(const QString &family) const | - | ||||||||||||
405 | { | - | ||||||||||||
406 | Q_UNUSED(family); | - | ||||||||||||
407 | return false; never executed: return false; | 0 | ||||||||||||
408 | } | - | ||||||||||||
409 | - | |||||||||||||
410 | /*! | - | ||||||||||||
411 | Returns the default system font. | - | ||||||||||||
412 | - | |||||||||||||
413 | \sa QGuiApplication::font() | - | ||||||||||||
414 | \since 5.0 | - | ||||||||||||
415 | */ | - | ||||||||||||
416 | - | |||||||||||||
417 | QFont QPlatformFontDatabase::defaultFont() const | - | ||||||||||||
418 | { | - | ||||||||||||
419 | return QFont(QLatin1String("Helvetica")); never executed: return QFont(QLatin1String("Helvetica")); | 0 | ||||||||||||
420 | } | - | ||||||||||||
421 | - | |||||||||||||
422 | /*! | - | ||||||||||||
423 | Resolve alias to actual font family names. | - | ||||||||||||
424 | - | |||||||||||||
425 | \since 5.0 | - | ||||||||||||
426 | */ | - | ||||||||||||
427 | - | |||||||||||||
428 | QString qt_resolveFontFamilyAlias(const QString &alias); | - | ||||||||||||
429 | - | |||||||||||||
430 | QString QPlatformFontDatabase::resolveFontFamilyAlias(const QString &family) const | - | ||||||||||||
431 | { | - | ||||||||||||
432 | return qt_resolveFontFamilyAlias(family); never executed: return qt_resolveFontFamilyAlias(family); | 0 | ||||||||||||
433 | } | - | ||||||||||||
434 | - | |||||||||||||
435 | /*! | - | ||||||||||||
436 | Return true if all fonts are considered scalable when using this font database. | - | ||||||||||||
437 | Defaults to false. | - | ||||||||||||
438 | - | |||||||||||||
439 | \since 5.0 | - | ||||||||||||
440 | */ | - | ||||||||||||
441 | - | |||||||||||||
442 | bool QPlatformFontDatabase::fontsAlwaysScalable() const | - | ||||||||||||
443 | { | - | ||||||||||||
444 | return false; never executed: return false; | 0 | ||||||||||||
445 | } | - | ||||||||||||
446 | - | |||||||||||||
447 | /*! | - | ||||||||||||
448 | Return list of standard font sizes when using this font database. | - | ||||||||||||
449 | - | |||||||||||||
450 | \since 5.0 | - | ||||||||||||
451 | */ | - | ||||||||||||
452 | - | |||||||||||||
453 | QList<int> QPlatformFontDatabase::standardSizes() const | - | ||||||||||||
454 | { | - | ||||||||||||
455 | QList<int> ret; | - | ||||||||||||
456 | static const quint8 standard[] = | - | ||||||||||||
457 | { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; | - | ||||||||||||
458 | static const int num_standards = int(sizeof standard / sizeof *standard); | - | ||||||||||||
459 | ret.reserve(num_standards); | - | ||||||||||||
460 | std::copy(standard, standard + num_standards, std::back_inserter(ret)); | - | ||||||||||||
461 | return ret; never executed: return ret; | 0 | ||||||||||||
462 | } | - | ||||||||||||
463 | - | |||||||||||||
464 | QFontEngine::SubpixelAntialiasingType QPlatformFontDatabase::subpixelAntialiasingTypeHint() const | - | ||||||||||||
465 | { | - | ||||||||||||
466 | static int type = -1; | - | ||||||||||||
467 | if (type == -1) {
| 0 | ||||||||||||
468 | if (QScreen *screen = QGuiApplication::primaryScreen())
| 0 | ||||||||||||
469 | type = screen->handle()->subpixelAntialiasingTypeHint(); never executed: type = screen->handle()->subpixelAntialiasingTypeHint(); | 0 | ||||||||||||
470 | } never executed: end of block | 0 | ||||||||||||
471 | return static_cast<QFontEngine::SubpixelAntialiasingType>(type); never executed: return static_cast<QFontEngine::SubpixelAntialiasingType>(type); | 0 | ||||||||||||
472 | } | - | ||||||||||||
473 | - | |||||||||||||
474 | // ### copied to tools/makeqpf/qpf2.cpp | - | ||||||||||||
475 | - | |||||||||||||
476 | // see the Unicode subset bitfields in the MSDN docs | - | ||||||||||||
477 | static const quint8 requiredUnicodeBits[QFontDatabase::WritingSystemsCount][2] = { | - | ||||||||||||
478 | { 127, 127 }, // Any | - | ||||||||||||
479 | { 0, 127 }, // Latin | - | ||||||||||||
480 | { 7, 127 }, // Greek | - | ||||||||||||
481 | { 9, 127 }, // Cyrillic | - | ||||||||||||
482 | { 10, 127 }, // Armenian | - | ||||||||||||
483 | { 11, 127 }, // Hebrew | - | ||||||||||||
484 | { 13, 127 }, // Arabic | - | ||||||||||||
485 | { 71, 127 }, // Syriac | - | ||||||||||||
486 | { 72, 127 }, // Thaana | - | ||||||||||||
487 | { 15, 127 }, // Devanagari | - | ||||||||||||
488 | { 16, 127 }, // Bengali | - | ||||||||||||
489 | { 17, 127 }, // Gurmukhi | - | ||||||||||||
490 | { 18, 127 }, // Gujarati | - | ||||||||||||
491 | { 19, 127 }, // Oriya | - | ||||||||||||
492 | { 20, 127 }, // Tamil | - | ||||||||||||
493 | { 21, 127 }, // Telugu | - | ||||||||||||
494 | { 22, 127 }, // Kannada | - | ||||||||||||
495 | { 23, 127 }, // Malayalam | - | ||||||||||||
496 | { 73, 127 }, // Sinhala | - | ||||||||||||
497 | { 24, 127 }, // Thai | - | ||||||||||||
498 | { 25, 127 }, // Lao | - | ||||||||||||
499 | { 70, 127 }, // Tibetan | - | ||||||||||||
500 | { 74, 127 }, // Myanmar | - | ||||||||||||
501 | { 26, 127 }, // Georgian | - | ||||||||||||
502 | { 80, 127 }, // Khmer | - | ||||||||||||
503 | { 126, 127 }, // SimplifiedChinese | - | ||||||||||||
504 | { 126, 127 }, // TraditionalChinese | - | ||||||||||||
505 | { 126, 127 }, // Japanese | - | ||||||||||||
506 | { 56, 127 }, // Korean | - | ||||||||||||
507 | { 0, 127 }, // Vietnamese (same as latin1) | - | ||||||||||||
508 | { 126, 127 }, // Other | - | ||||||||||||
509 | { 78, 127 }, // Ogham | - | ||||||||||||
510 | { 79, 127 }, // Runic | - | ||||||||||||
511 | { 14, 127 }, // Nko | - | ||||||||||||
512 | }; | - | ||||||||||||
513 | - | |||||||||||||
514 | enum { | - | ||||||||||||
515 | Latin1CsbBit = 0, | - | ||||||||||||
516 | CentralEuropeCsbBit = 1, | - | ||||||||||||
517 | TurkishCsbBit = 4, | - | ||||||||||||
518 | BalticCsbBit = 7, | - | ||||||||||||
519 | CyrillicCsbBit = 2, | - | ||||||||||||
520 | GreekCsbBit = 3, | - | ||||||||||||
521 | HebrewCsbBit = 5, | - | ||||||||||||
522 | ArabicCsbBit = 6, | - | ||||||||||||
523 | VietnameseCsbBit = 8, | - | ||||||||||||
524 | SimplifiedChineseCsbBit = 18, | - | ||||||||||||
525 | TraditionalChineseCsbBit = 20, | - | ||||||||||||
526 | ThaiCsbBit = 16, | - | ||||||||||||
527 | JapaneseCsbBit = 17, | - | ||||||||||||
528 | KoreanCsbBit = 19, | - | ||||||||||||
529 | KoreanJohabCsbBit = 21, | - | ||||||||||||
530 | SymbolCsbBit = 31 | - | ||||||||||||
531 | }; | - | ||||||||||||
532 | - | |||||||||||||
533 | /*! | - | ||||||||||||
534 | Helper function that determines the writing systems support by a given | - | ||||||||||||
535 | \a unicodeRange and \a codePageRange. | - | ||||||||||||
536 | - | |||||||||||||
537 | \since 5.1 | - | ||||||||||||
538 | */ | - | ||||||||||||
539 | QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]) | - | ||||||||||||
540 | { | - | ||||||||||||
541 | QSupportedWritingSystems writingSystems; | - | ||||||||||||
542 | - | |||||||||||||
543 | bool hasScript = false; | - | ||||||||||||
544 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
| 0 | ||||||||||||
545 | int bit = requiredUnicodeBits[i][0]; | - | ||||||||||||
546 | int index = bit/32; | - | ||||||||||||
547 | int flag = 1 << (bit&31); | - | ||||||||||||
548 | if (bit != 126 && (unicodeRange[index] & flag)) {
| 0 | ||||||||||||
549 | bit = requiredUnicodeBits[i][1]; | - | ||||||||||||
550 | index = bit/32; | - | ||||||||||||
551 | - | |||||||||||||
552 | flag = 1 << (bit&31); | - | ||||||||||||
553 | if (bit == 127 || (unicodeRange[index] & flag)) {
| 0 | ||||||||||||
554 | writingSystems.setSupported(QFontDatabase::WritingSystem(i)); | - | ||||||||||||
555 | hasScript = true; | - | ||||||||||||
556 | // qDebug("font %s: index=%d, flag=%8x supports script %d", familyName.latin1(), index, flag, i); | - | ||||||||||||
557 | } never executed: end of block | 0 | ||||||||||||
558 | } never executed: end of block | 0 | ||||||||||||
559 | } never executed: end of block | 0 | ||||||||||||
560 | if (codePageRange[0] & ((1 << Latin1CsbBit) | (1 << CentralEuropeCsbBit) | (1 << TurkishCsbBit) | (1 << BalticCsbBit))) {
| 0 | ||||||||||||
561 | writingSystems.setSupported(QFontDatabase::Latin); | - | ||||||||||||
562 | hasScript = true; | - | ||||||||||||
563 | //qDebug("font %s supports Latin", familyName.latin1()); | - | ||||||||||||
564 | } never executed: end of block | 0 | ||||||||||||
565 | if (codePageRange[0] & (1 << CyrillicCsbBit)) {
| 0 | ||||||||||||
566 | writingSystems.setSupported(QFontDatabase::Cyrillic); | - | ||||||||||||
567 | hasScript = true; | - | ||||||||||||
568 | //qDebug("font %s supports Cyrillic", familyName.latin1()); | - | ||||||||||||
569 | } never executed: end of block | 0 | ||||||||||||
570 | if (codePageRange[0] & (1 << GreekCsbBit)) {
| 0 | ||||||||||||
571 | writingSystems.setSupported(QFontDatabase::Greek); | - | ||||||||||||
572 | hasScript = true; | - | ||||||||||||
573 | //qDebug("font %s supports Greek", familyName.latin1()); | - | ||||||||||||
574 | } never executed: end of block | 0 | ||||||||||||
575 | if (codePageRange[0] & (1 << HebrewCsbBit)) {
| 0 | ||||||||||||
576 | writingSystems.setSupported(QFontDatabase::Hebrew); | - | ||||||||||||
577 | hasScript = true; | - | ||||||||||||
578 | //qDebug("font %s supports Hebrew", familyName.latin1()); | - | ||||||||||||
579 | } never executed: end of block | 0 | ||||||||||||
580 | if (codePageRange[0] & (1 << ArabicCsbBit)) {
| 0 | ||||||||||||
581 | writingSystems.setSupported(QFontDatabase::Arabic); | - | ||||||||||||
582 | hasScript = true; | - | ||||||||||||
583 | //qDebug("font %s supports Arabic", familyName.latin1()); | - | ||||||||||||
584 | } never executed: end of block | 0 | ||||||||||||
585 | if (codePageRange[0] & (1 << ThaiCsbBit)) {
| 0 | ||||||||||||
586 | writingSystems.setSupported(QFontDatabase::Thai); | - | ||||||||||||
587 | hasScript = true; | - | ||||||||||||
588 | //qDebug("font %s supports Thai", familyName.latin1()); | - | ||||||||||||
589 | } never executed: end of block | 0 | ||||||||||||
590 | if (codePageRange[0] & (1 << VietnameseCsbBit)) {
| 0 | ||||||||||||
591 | writingSystems.setSupported(QFontDatabase::Vietnamese); | - | ||||||||||||
592 | hasScript = true; | - | ||||||||||||
593 | //qDebug("font %s supports Vietnamese", familyName.latin1()); | - | ||||||||||||
594 | } never executed: end of block | 0 | ||||||||||||
595 | if (codePageRange[0] & (1 << SimplifiedChineseCsbBit)) {
| 0 | ||||||||||||
596 | writingSystems.setSupported(QFontDatabase::SimplifiedChinese); | - | ||||||||||||
597 | hasScript = true; | - | ||||||||||||
598 | //qDebug("font %s supports Simplified Chinese", familyName.latin1()); | - | ||||||||||||
599 | } never executed: end of block | 0 | ||||||||||||
600 | if (codePageRange[0] & (1 << TraditionalChineseCsbBit)) {
| 0 | ||||||||||||
601 | writingSystems.setSupported(QFontDatabase::TraditionalChinese); | - | ||||||||||||
602 | hasScript = true; | - | ||||||||||||
603 | //qDebug("font %s supports Traditional Chinese", familyName.latin1()); | - | ||||||||||||
604 | } never executed: end of block | 0 | ||||||||||||
605 | if (codePageRange[0] & (1 << JapaneseCsbBit)) {
| 0 | ||||||||||||
606 | writingSystems.setSupported(QFontDatabase::Japanese); | - | ||||||||||||
607 | hasScript = true; | - | ||||||||||||
608 | //qDebug("font %s supports Japanese", familyName.latin1()); | - | ||||||||||||
609 | } never executed: end of block | 0 | ||||||||||||
610 | if (codePageRange[0] & ((1 << KoreanCsbBit) | (1 << KoreanJohabCsbBit))) {
| 0 | ||||||||||||
611 | writingSystems.setSupported(QFontDatabase::Korean); | - | ||||||||||||
612 | hasScript = true; | - | ||||||||||||
613 | //qDebug("font %s supports Korean", familyName.latin1()); | - | ||||||||||||
614 | } never executed: end of block | 0 | ||||||||||||
615 | if (codePageRange[0] & (1U << SymbolCsbBit)) {
| 0 | ||||||||||||
616 | writingSystems = QSupportedWritingSystems(); | - | ||||||||||||
617 | hasScript = false; | - | ||||||||||||
618 | } never executed: end of block | 0 | ||||||||||||
619 | - | |||||||||||||
620 | if (!hasScript)
| 0 | ||||||||||||
621 | writingSystems.setSupported(QFontDatabase::Symbol); never executed: writingSystems.setSupported(QFontDatabase::Symbol); | 0 | ||||||||||||
622 | - | |||||||||||||
623 | return writingSystems; never executed: return writingSystems; | 0 | ||||||||||||
624 | } | - | ||||||||||||
625 | - | |||||||||||||
626 | /*! | - | ||||||||||||
627 | Helper function that returns the Qt font weight matching a given opentype integer value. | - | ||||||||||||
628 | - | |||||||||||||
629 | \since 5.5 | - | ||||||||||||
630 | */ | - | ||||||||||||
631 | - | |||||||||||||
632 | // convert 0 ~ 1000 integer to QFont::Weight | - | ||||||||||||
633 | QFont::Weight QPlatformFontDatabase::weightFromInteger(int weight) | - | ||||||||||||
634 | { | - | ||||||||||||
635 | if (weight < 150)
| 0 | ||||||||||||
636 | return QFont::Thin; never executed: return QFont::Thin; | 0 | ||||||||||||
637 | if (weight < 250)
| 0 | ||||||||||||
638 | return QFont::ExtraLight; never executed: return QFont::ExtraLight; | 0 | ||||||||||||
639 | if (weight < 350)
| 0 | ||||||||||||
640 | return QFont::Light; never executed: return QFont::Light; | 0 | ||||||||||||
641 | if (weight < 450)
| 0 | ||||||||||||
642 | return QFont::Normal; never executed: return QFont::Normal; | 0 | ||||||||||||
643 | if (weight < 550)
| 0 | ||||||||||||
644 | return QFont::Medium; never executed: return QFont::Medium; | 0 | ||||||||||||
645 | if (weight < 650)
| 0 | ||||||||||||
646 | return QFont::DemiBold; never executed: return QFont::DemiBold; | 0 | ||||||||||||
647 | if (weight < 750)
| 0 | ||||||||||||
648 | return QFont::Bold; never executed: return QFont::Bold; | 0 | ||||||||||||
649 | if (weight < 850)
| 0 | ||||||||||||
650 | return QFont::ExtraBold; never executed: return QFont::ExtraBold; | 0 | ||||||||||||
651 | return QFont::Black; never executed: return QFont::Black; | 0 | ||||||||||||
652 | } | - | ||||||||||||
653 | - | |||||||||||||
654 | /*! | - | ||||||||||||
655 | Helper function that register the \a alias for the \a familyName. | - | ||||||||||||
656 | - | |||||||||||||
657 | \since 5.2 | - | ||||||||||||
658 | */ | - | ||||||||||||
659 | - | |||||||||||||
660 | void QPlatformFontDatabase::registerAliasToFontFamily(const QString &familyName, const QString &alias) | - | ||||||||||||
661 | { | - | ||||||||||||
662 | qt_registerAliasToFontFamily(familyName, alias); | - | ||||||||||||
663 | } never executed: end of block | 0 | ||||||||||||
664 | - | |||||||||||||
665 | /*! | - | ||||||||||||
666 | \class QPlatformFontDatabase | - | ||||||||||||
667 | \since 5.0 | - | ||||||||||||
668 | \internal | - | ||||||||||||
669 | \preliminary | - | ||||||||||||
670 | \ingroup qpa | - | ||||||||||||
671 | \ingroup painting | - | ||||||||||||
672 | - | |||||||||||||
673 | \brief The QPlatformFontDatabase class makes it possible to customize how fonts | - | ||||||||||||
674 | are discovered and how they are rendered | - | ||||||||||||
675 | - | |||||||||||||
676 | QPlatformFontDatabase is the superclass which is intended to let platform implementations use | - | ||||||||||||
677 | native font handling. | - | ||||||||||||
678 | - | |||||||||||||
679 | Qt has its internal font database which it uses to discover available fonts on the | - | ||||||||||||
680 | user's system. To be able to populate this database subclass this class, and | - | ||||||||||||
681 | reimplement populateFontDatabase(). | - | ||||||||||||
682 | - | |||||||||||||
683 | Use the function registerFont() to populate the internal font database. | - | ||||||||||||
684 | - | |||||||||||||
685 | Sometimes a specified font does not have the required glyphs; in such a case, the | - | ||||||||||||
686 | fallbackForFamily() function is called automatically to find alternative font | - | ||||||||||||
687 | families that can supply alternatives to the missing glyphs. | - | ||||||||||||
688 | - | |||||||||||||
689 | \sa QSupportedWritingSystems | - | ||||||||||||
690 | */ | - | ||||||||||||
691 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |