Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qfontdatabase.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qfontdatabase.h" | - | ||||||||||||
41 | #include "qdebug.h" | - | ||||||||||||
42 | #include "qalgorithms.h" | - | ||||||||||||
43 | #include "qguiapplication.h" | - | ||||||||||||
44 | #include "qvarlengtharray.h" // here or earlier - workaround for VC++6 | - | ||||||||||||
45 | #include "qthread.h" | - | ||||||||||||
46 | #include "qmutex.h" | - | ||||||||||||
47 | #include "qfile.h" | - | ||||||||||||
48 | #include "qfileinfo.h" | - | ||||||||||||
49 | #include "qfontengine_p.h" | - | ||||||||||||
50 | #include <qpa/qplatformintegration.h> | - | ||||||||||||
51 | - | |||||||||||||
52 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||
53 | #include <qpa/qplatformfontdatabase.h> | - | ||||||||||||
54 | #include <qpa/qplatformtheme.h> | - | ||||||||||||
55 | - | |||||||||||||
56 | #include <QtCore/qcache.h> | - | ||||||||||||
57 | #include <QtCore/qmath.h> | - | ||||||||||||
58 | - | |||||||||||||
59 | #include <stdlib.h> | - | ||||||||||||
60 | #include <algorithm> | - | ||||||||||||
61 | - | |||||||||||||
62 | - | |||||||||||||
63 | // #define QFONTDATABASE_DEBUG | - | ||||||||||||
64 | #ifdef QFONTDATABASE_DEBUG | - | ||||||||||||
65 | # define FD_DEBUG qDebug | - | ||||||||||||
66 | #else | - | ||||||||||||
67 | # define FD_DEBUG if (false) qDebug | - | ||||||||||||
68 | #endif | - | ||||||||||||
69 | - | |||||||||||||
70 | // #define FONT_MATCH_DEBUG | - | ||||||||||||
71 | #ifdef FONT_MATCH_DEBUG | - | ||||||||||||
72 | # define FM_DEBUG qDebug | - | ||||||||||||
73 | #else | - | ||||||||||||
74 | # define FM_DEBUG if (false) qDebug | - | ||||||||||||
75 | #endif | - | ||||||||||||
76 | - | |||||||||||||
77 | - | |||||||||||||
78 | QT_BEGIN_NAMESPACE | - | ||||||||||||
79 | - | |||||||||||||
80 | #define SMOOTH_SCALABLE 0xffff | - | ||||||||||||
81 | - | |||||||||||||
82 | #if defined(QT_BUILD_INTERNAL) | - | ||||||||||||
83 | bool qt_enable_test_font = false; | - | ||||||||||||
84 | - | |||||||||||||
85 | Q_AUTOTEST_EXPORT void qt_setQtEnableTestFont(bool value) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | qt_enable_test_font = value; | - | ||||||||||||
88 | } | - | ||||||||||||
89 | #endif | - | ||||||||||||
90 | - | |||||||||||||
91 | static int getFontWeight(const QString &weightString) | - | ||||||||||||
92 | { | - | ||||||||||||
93 | QString s = weightString.toLower(); | - | ||||||||||||
94 | - | |||||||||||||
95 | // Order here is important. We want to match the common cases first, but we | - | ||||||||||||
96 | // must also take care to acknowledge the cost of our tests. | - | ||||||||||||
97 | // | - | ||||||||||||
98 | // As a result, we test in two orders; the order of commonness, and the | - | ||||||||||||
99 | // order of "expense". | - | ||||||||||||
100 | // | - | ||||||||||||
101 | // A simple string test is the cheapest, so let's do that first. | - | ||||||||||||
102 | // Test in decreasing order of commonness | - | ||||||||||||
103 | if (s == QLatin1String("normal") || s == QLatin1String("regular")) | - | ||||||||||||
104 | return QFont::Normal; | - | ||||||||||||
105 | if (s == QLatin1String("bold")) | - | ||||||||||||
106 | return QFont::Bold; | - | ||||||||||||
107 | if (s == QLatin1String("semibold") || s == QLatin1String("semi bold") | - | ||||||||||||
108 | || s == QLatin1String("demibold") || s == QLatin1String("demi bold")) | - | ||||||||||||
109 | return QFont::DemiBold; | - | ||||||||||||
110 | if (s == QLatin1String("medium")) | - | ||||||||||||
111 | return QFont::Medium; | - | ||||||||||||
112 | if (s == QLatin1String("black")) | - | ||||||||||||
113 | return QFont::Black; | - | ||||||||||||
114 | if (s == QLatin1String("light")) | - | ||||||||||||
115 | return QFont::Light; | - | ||||||||||||
116 | if (s == QLatin1String("thin")) | - | ||||||||||||
117 | return QFont::Thin; | - | ||||||||||||
118 | const QStringRef s2 = s.midRef(2); | - | ||||||||||||
119 | if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) { | - | ||||||||||||
120 | if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light")) | - | ||||||||||||
121 | return QFont::ExtraLight; | - | ||||||||||||
122 | if (s2 == QLatin1String("trabold") || s2 == QLatin1String("tra bold")) | - | ||||||||||||
123 | return QFont::ExtraBold; | - | ||||||||||||
124 | } | - | ||||||||||||
125 | - | |||||||||||||
126 | // Next up, let's see if contains() matches: slightly more expensive, but | - | ||||||||||||
127 | // still fast enough. | - | ||||||||||||
128 | if (s.contains(QLatin1String("bold"))) { | - | ||||||||||||
129 | if (s.contains(QLatin1String("demi"))) | - | ||||||||||||
130 | return QFont::DemiBold; | - | ||||||||||||
131 | return QFont::Bold; | - | ||||||||||||
132 | } | - | ||||||||||||
133 | if (s.contains(QLatin1String("thin"))) | - | ||||||||||||
134 | return QFont::Thin; | - | ||||||||||||
135 | if (s.contains(QLatin1String("light"))) | - | ||||||||||||
136 | return QFont::Light; | - | ||||||||||||
137 | if (s.contains(QLatin1String("black"))) | - | ||||||||||||
138 | return QFont::Black; | - | ||||||||||||
139 | - | |||||||||||||
140 | // Now, we perform string translations & comparisons with those. | - | ||||||||||||
141 | // These are (very) slow compared to simple string ops, so we do these last. | - | ||||||||||||
142 | // As using translated values for such things is not very common, this should | - | ||||||||||||
143 | // not be too bad. | - | ||||||||||||
144 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
145 | return QFont::Normal; | - | ||||||||||||
146 | const QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower(); | - | ||||||||||||
147 | if (s == translatedBold) | - | ||||||||||||
148 | return QFont::Bold; | - | ||||||||||||
149 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
150 | return QFont::DemiBold; | - | ||||||||||||
151 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
152 | return QFont::Medium; | - | ||||||||||||
153 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
154 | return QFont::Black; | - | ||||||||||||
155 | const QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower(); | - | ||||||||||||
156 | if (s == translatedLight) | - | ||||||||||||
157 | return QFont::Light; | - | ||||||||||||
158 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Thin"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
159 | return QFont::Thin; | - | ||||||||||||
160 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Light"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
161 | return QFont::ExtraLight; | - | ||||||||||||
162 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Bold"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
163 | return QFont::ExtraBold; | - | ||||||||||||
164 | - | |||||||||||||
165 | // And now the contains() checks for the translated strings. | - | ||||||||||||
166 | //: The word for "Extra" as in "Extra Bold, Extra Thin" used as a pattern for string searches | - | ||||||||||||
167 | const QString translatedExtra = QCoreApplication::translate("QFontDatabase", "Extra").toLower(); | - | ||||||||||||
168 | if (s.contains(translatedBold)) { | - | ||||||||||||
169 | //: The word for "Demi" as in "Demi Bold" used as a pattern for string searches | - | ||||||||||||
170 | QString translatedDemi = QCoreApplication::translate("QFontDatabase", "Demi").toLower(); | - | ||||||||||||
171 | if (s .contains(translatedDemi)) | - | ||||||||||||
172 | return QFont::DemiBold; | - | ||||||||||||
173 | if (s.contains(translatedExtra)) | - | ||||||||||||
174 | return QFont::ExtraBold; | - | ||||||||||||
175 | return QFont::Bold; | - | ||||||||||||
176 | } | - | ||||||||||||
177 | - | |||||||||||||
178 | if (s.contains(translatedLight)) { | - | ||||||||||||
179 | if (s.contains(translatedExtra)) | - | ||||||||||||
180 | return QFont::ExtraLight; | - | ||||||||||||
181 | return QFont::Light; | - | ||||||||||||
182 | } | - | ||||||||||||
183 | return QFont::Normal; | - | ||||||||||||
184 | } | - | ||||||||||||
185 | - | |||||||||||||
186 | - | |||||||||||||
187 | struct QtFontSize | - | ||||||||||||
188 | { | - | ||||||||||||
189 | - | |||||||||||||
190 | void *handle; | - | ||||||||||||
191 | - | |||||||||||||
192 | unsigned short pixelSize : 16; | - | ||||||||||||
193 | }; | - | ||||||||||||
194 | - | |||||||||||||
195 | - | |||||||||||||
196 | - | |||||||||||||
197 | struct QtFontStyle | - | ||||||||||||
198 | { | - | ||||||||||||
199 | struct Key { | - | ||||||||||||
200 | Key(const QString &styleString); | - | ||||||||||||
201 | Key() : style(QFont::StyleNormal), | - | ||||||||||||
202 | weight(QFont::Normal), stretch(0) { } | - | ||||||||||||
203 | Key(const Key &o) : style(o.style), weight(o.weight), stretch(o.stretch) { } | - | ||||||||||||
204 | uint style : 2; | - | ||||||||||||
205 | signed int weight : 8; | - | ||||||||||||
206 | signed int stretch : 12; | - | ||||||||||||
207 | - | |||||||||||||
208 | bool operator==(const Key & other) { | - | ||||||||||||
209 | return (style == other.style && weight == other.weight && | - | ||||||||||||
210 | (stretch == 0 || other.stretch == 0 || stretch == other.stretch)); | - | ||||||||||||
211 | } | - | ||||||||||||
212 | bool operator!=(const Key &other) { | - | ||||||||||||
213 | return !operator==(other); | - | ||||||||||||
214 | } | - | ||||||||||||
215 | bool operator <(const Key &o) { | - | ||||||||||||
216 | int x = (style << 12) + (weight << 14) + stretch; | - | ||||||||||||
217 | int y = (o.style << 12) + (o.weight << 14) + o.stretch; | - | ||||||||||||
218 | return (x < y); | - | ||||||||||||
219 | } | - | ||||||||||||
220 | }; | - | ||||||||||||
221 | - | |||||||||||||
222 | QtFontStyle(const Key &k) | - | ||||||||||||
223 | : key(k), bitmapScalable(false), smoothScalable(false), | - | ||||||||||||
224 | count(0), pixelSizes(0) | - | ||||||||||||
225 | { | - | ||||||||||||
226 | } | - | ||||||||||||
227 | - | |||||||||||||
228 | ~QtFontStyle() { | - | ||||||||||||
229 | while (count) { | - | ||||||||||||
230 | // bitfield count-- in while condition does not work correctly in mwccsym2 | - | ||||||||||||
231 | count--; | - | ||||||||||||
232 | QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||
233 | if (integration) { | - | ||||||||||||
234 | integration->fontDatabase()->releaseHandle(pixelSizes[count].handle); | - | ||||||||||||
235 | } | - | ||||||||||||
236 | } | - | ||||||||||||
237 | free(pixelSizes); | - | ||||||||||||
238 | } | - | ||||||||||||
239 | - | |||||||||||||
240 | Key key; | - | ||||||||||||
241 | bool bitmapScalable : 1; | - | ||||||||||||
242 | bool smoothScalable : 1; | - | ||||||||||||
243 | signed int count : 30; | - | ||||||||||||
244 | QtFontSize *pixelSizes; | - | ||||||||||||
245 | QString styleName; | - | ||||||||||||
246 | - | |||||||||||||
247 | bool antialiased; | - | ||||||||||||
248 | - | |||||||||||||
249 | QtFontSize *pixelSize(unsigned short size, bool = false); | - | ||||||||||||
250 | }; | - | ||||||||||||
251 | - | |||||||||||||
252 | QtFontStyle::Key::Key(const QString &styleString) | - | ||||||||||||
253 | : style(QFont::StyleNormal), weight(QFont::Normal), stretch(0) | - | ||||||||||||
254 | { | - | ||||||||||||
255 | weight = getFontWeight(styleString); | - | ||||||||||||
256 | - | |||||||||||||
257 | if (!styleString.isEmpty()) { | - | ||||||||||||
258 | // First the straightforward no-translation checks, these are fast. | - | ||||||||||||
259 | if (styleString.contains(QLatin1String("Italic"))) | - | ||||||||||||
260 | style = QFont::StyleItalic; | - | ||||||||||||
261 | else if (styleString.contains(QLatin1String("Oblique"))) | - | ||||||||||||
262 | style = QFont::StyleOblique; | - | ||||||||||||
263 | - | |||||||||||||
264 | // Then the translation checks. These aren't as fast. | - | ||||||||||||
265 | else if (styleString.contains(QCoreApplication::translate("QFontDatabase", "Italic"))) | - | ||||||||||||
266 | style = QFont::StyleItalic; | - | ||||||||||||
267 | else if (styleString.contains(QCoreApplication::translate("QFontDatabase", "Oblique"))) | - | ||||||||||||
268 | style = QFont::StyleOblique; | - | ||||||||||||
269 | } | - | ||||||||||||
270 | } | - | ||||||||||||
271 | - | |||||||||||||
272 | QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add) | - | ||||||||||||
273 | { | - | ||||||||||||
274 | for (int i = 0; i < count; i++) { | - | ||||||||||||
275 | if (pixelSizes[i].pixelSize == size) | - | ||||||||||||
276 | return pixelSizes + i; | - | ||||||||||||
277 | } | - | ||||||||||||
278 | if (!add) | - | ||||||||||||
279 | return 0; | - | ||||||||||||
280 | - | |||||||||||||
281 | if (!pixelSizes) { | - | ||||||||||||
282 | // Most style have only one font size, we avoid waisting memory | - | ||||||||||||
283 | QtFontSize *newPixelSizes = (QtFontSize *)malloc(sizeof(QtFontSize)); | - | ||||||||||||
284 | Q_CHECK_PTR(newPixelSizes); | - | ||||||||||||
285 | pixelSizes = newPixelSizes; | - | ||||||||||||
286 | } else if (!(count % 8) || count == 1) { | - | ||||||||||||
287 | QtFontSize *newPixelSizes = (QtFontSize *) | - | ||||||||||||
288 | realloc(pixelSizes, | - | ||||||||||||
289 | (((count+8) >> 3) << 3) * sizeof(QtFontSize)); | - | ||||||||||||
290 | Q_CHECK_PTR(newPixelSizes); | - | ||||||||||||
291 | pixelSizes = newPixelSizes; | - | ||||||||||||
292 | } | - | ||||||||||||
293 | pixelSizes[count].pixelSize = size; | - | ||||||||||||
294 | pixelSizes[count].handle = 0; | - | ||||||||||||
295 | return pixelSizes + (count++); | - | ||||||||||||
296 | } | - | ||||||||||||
297 | - | |||||||||||||
298 | struct QtFontFoundry | - | ||||||||||||
299 | { | - | ||||||||||||
300 | QtFontFoundry(const QString &n) : name(n), count(0), styles(0) {} | - | ||||||||||||
301 | ~QtFontFoundry() { | - | ||||||||||||
302 | while (count--) | - | ||||||||||||
303 | delete styles[count]; | - | ||||||||||||
304 | free(styles); | - | ||||||||||||
305 | } | - | ||||||||||||
306 | - | |||||||||||||
307 | QString name; | - | ||||||||||||
308 | - | |||||||||||||
309 | int count; | - | ||||||||||||
310 | QtFontStyle **styles; | - | ||||||||||||
311 | QtFontStyle *style(const QtFontStyle::Key &, const QString & = QString(), bool = false); | - | ||||||||||||
312 | }; | - | ||||||||||||
313 | - | |||||||||||||
314 | QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &styleName, bool create) | - | ||||||||||||
315 | { | - | ||||||||||||
316 | int pos = 0; | - | ||||||||||||
317 | for (; pos < count; pos++) { | - | ||||||||||||
318 | bool hasStyleName = !styleName.isEmpty(); // search styleName first if available | - | ||||||||||||
319 | if (hasStyleName && !styles[pos]->styleName.isEmpty()) { | - | ||||||||||||
320 | if (styles[pos]->styleName == styleName) | - | ||||||||||||
321 | return styles[pos]; | - | ||||||||||||
322 | } else { | - | ||||||||||||
323 | if (styles[pos]->key == key) | - | ||||||||||||
324 | return styles[pos]; | - | ||||||||||||
325 | } | - | ||||||||||||
326 | } | - | ||||||||||||
327 | if (!create) | - | ||||||||||||
328 | return 0; | - | ||||||||||||
329 | - | |||||||||||||
330 | // qDebug("adding key (weight=%d, style=%d, oblique=%d stretch=%d) at %d", key.weight, key.style, key.oblique, key.stretch, pos); | - | ||||||||||||
331 | if (!(count % 8)) { | - | ||||||||||||
332 | QtFontStyle **newStyles = (QtFontStyle **) | - | ||||||||||||
333 | realloc(styles, (((count+8) >> 3) << 3) * sizeof(QtFontStyle *)); | - | ||||||||||||
334 | Q_CHECK_PTR(newStyles); | - | ||||||||||||
335 | styles = newStyles; | - | ||||||||||||
336 | } | - | ||||||||||||
337 | - | |||||||||||||
338 | QtFontStyle *style = new QtFontStyle(key); | - | ||||||||||||
339 | style->styleName = styleName; | - | ||||||||||||
340 | styles[pos] = style; | - | ||||||||||||
341 | count++; | - | ||||||||||||
342 | return styles[pos]; | - | ||||||||||||
343 | } | - | ||||||||||||
344 | - | |||||||||||||
345 | - | |||||||||||||
346 | struct QtFontFamily | - | ||||||||||||
347 | { | - | ||||||||||||
348 | enum WritingSystemStatus { | - | ||||||||||||
349 | Unknown = 0, | - | ||||||||||||
350 | Supported = 1, | - | ||||||||||||
351 | UnsupportedFT = 2, | - | ||||||||||||
352 | Unsupported = UnsupportedFT | - | ||||||||||||
353 | }; | - | ||||||||||||
354 | - | |||||||||||||
355 | QtFontFamily(const QString &n) | - | ||||||||||||
356 | : | - | ||||||||||||
357 | populated(false), | - | ||||||||||||
358 | fixedPitch(false), | - | ||||||||||||
359 | name(n), count(0), foundries(0) | - | ||||||||||||
360 | { | - | ||||||||||||
361 | memset(writingSystems, 0, sizeof(writingSystems)); | - | ||||||||||||
362 | } | - | ||||||||||||
363 | ~QtFontFamily() { | - | ||||||||||||
364 | while (count--) | - | ||||||||||||
365 | delete foundries[count]; | - | ||||||||||||
366 | free(foundries); | - | ||||||||||||
367 | } | - | ||||||||||||
368 | - | |||||||||||||
369 | bool populated : 1; | - | ||||||||||||
370 | bool fixedPitch : 1; | - | ||||||||||||
371 | - | |||||||||||||
372 | QString name; | - | ||||||||||||
373 | QStringList aliases; | - | ||||||||||||
374 | int count; | - | ||||||||||||
375 | QtFontFoundry **foundries; | - | ||||||||||||
376 | - | |||||||||||||
377 | unsigned char writingSystems[QFontDatabase::WritingSystemsCount]; | - | ||||||||||||
378 | - | |||||||||||||
379 | bool matchesFamilyName(const QString &familyName) const; | - | ||||||||||||
380 | QtFontFoundry *foundry(const QString &f, bool = false); | - | ||||||||||||
381 | - | |||||||||||||
382 | void ensurePopulated(); | - | ||||||||||||
383 | }; | - | ||||||||||||
384 | - | |||||||||||||
385 | QtFontFoundry *QtFontFamily::foundry(const QString &f, bool create) | - | ||||||||||||
386 | { | - | ||||||||||||
387 | if (f.isNull() && count == 1) | - | ||||||||||||
388 | return foundries[0]; | - | ||||||||||||
389 | - | |||||||||||||
390 | for (int i = 0; i < count; i++) { | - | ||||||||||||
391 | if (foundries[i]->name.compare(f, Qt::CaseInsensitive) == 0) | - | ||||||||||||
392 | return foundries[i]; | - | ||||||||||||
393 | } | - | ||||||||||||
394 | if (!create) | - | ||||||||||||
395 | return 0; | - | ||||||||||||
396 | - | |||||||||||||
397 | if (!(count % 8)) { | - | ||||||||||||
398 | QtFontFoundry **newFoundries = (QtFontFoundry **) | - | ||||||||||||
399 | realloc(foundries, | - | ||||||||||||
400 | (((count+8) >> 3) << 3) * sizeof(QtFontFoundry *)); | - | ||||||||||||
401 | Q_CHECK_PTR(newFoundries); | - | ||||||||||||
402 | foundries = newFoundries; | - | ||||||||||||
403 | } | - | ||||||||||||
404 | - | |||||||||||||
405 | foundries[count] = new QtFontFoundry(f); | - | ||||||||||||
406 | return foundries[count++]; | - | ||||||||||||
407 | } | - | ||||||||||||
408 | - | |||||||||||||
409 | bool QtFontFamily::matchesFamilyName(const QString &familyName) const | - | ||||||||||||
410 | { | - | ||||||||||||
411 | return name.compare(familyName, Qt::CaseInsensitive) == 0 || aliases.contains(familyName, Qt::CaseInsensitive); | - | ||||||||||||
412 | } | - | ||||||||||||
413 | - | |||||||||||||
414 | void QtFontFamily::ensurePopulated() | - | ||||||||||||
415 | { | - | ||||||||||||
416 | if (populated) | - | ||||||||||||
417 | return; | - | ||||||||||||
418 | - | |||||||||||||
419 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamily(name); | - | ||||||||||||
420 | Q_ASSERT_X(populated, Q_FUNC_INFO, qPrintable(name)); | - | ||||||||||||
421 | } | - | ||||||||||||
422 | - | |||||||||||||
423 | - | |||||||||||||
424 | struct FallbacksCacheKey { | - | ||||||||||||
425 | QString family; | - | ||||||||||||
426 | QFont::Style style; | - | ||||||||||||
427 | QFont::StyleHint styleHint; | - | ||||||||||||
428 | QChar::Script script; | - | ||||||||||||
429 | }; | - | ||||||||||||
430 | - | |||||||||||||
431 | inline bool operator==(const FallbacksCacheKey &lhs, const FallbacksCacheKey &rhs) Q_DECL_NOTHROW | - | ||||||||||||
432 | { | - | ||||||||||||
433 | return lhs.script == rhs.script && never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
434 | lhs.styleHint == rhs.styleHint && never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
435 | lhs.style == rhs.style && never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
436 | lhs.family == rhs.family; never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
437 | } | - | ||||||||||||
438 | - | |||||||||||||
439 | inline bool operator!=(const FallbacksCacheKey &lhs, const FallbacksCacheKey &rhs) Q_DECL_NOTHROW | - | ||||||||||||
440 | { | - | ||||||||||||
441 | return !operator==(lhs, rhs); never executed: return !operator==(lhs, rhs); | 0 | ||||||||||||
442 | } | - | ||||||||||||
443 | - | |||||||||||||
444 | inline uint qHash(const FallbacksCacheKey &key, uint seed = 0) Q_DECL_NOTHROW | - | ||||||||||||
445 | { | - | ||||||||||||
446 | QtPrivate::QHashCombine hash; | - | ||||||||||||
447 | seed = hash(seed, key.family); | - | ||||||||||||
448 | seed = hash(seed, int(key.style)); | - | ||||||||||||
449 | seed = hash(seed, int(key.styleHint)); | - | ||||||||||||
450 | seed = hash(seed, int(key.script)); | - | ||||||||||||
451 | return seed; never executed: return seed; | 0 | ||||||||||||
452 | } | - | ||||||||||||
453 | - | |||||||||||||
454 | - | |||||||||||||
455 | class QFontDatabasePrivate | - | ||||||||||||
456 | { | - | ||||||||||||
457 | public: | - | ||||||||||||
458 | QFontDatabasePrivate() | - | ||||||||||||
459 | : count(0), families(0), | - | ||||||||||||
460 | fallbacksCache(64), | - | ||||||||||||
461 | reregisterAppFonts(false) | - | ||||||||||||
462 | { } | - | ||||||||||||
463 | - | |||||||||||||
464 | ~QFontDatabasePrivate() { | - | ||||||||||||
465 | free(); | - | ||||||||||||
466 | } | - | ||||||||||||
467 | - | |||||||||||||
468 | enum FamilyRequestFlags { | - | ||||||||||||
469 | RequestFamily = 0, | - | ||||||||||||
470 | EnsureCreated, | - | ||||||||||||
471 | EnsurePopulated | - | ||||||||||||
472 | }; | - | ||||||||||||
473 | - | |||||||||||||
474 | QtFontFamily *family(const QString &f, FamilyRequestFlags flags = EnsurePopulated); | - | ||||||||||||
475 | void free() { | - | ||||||||||||
476 | while (count--) | - | ||||||||||||
477 | delete families[count]; | - | ||||||||||||
478 | ::free(families); | - | ||||||||||||
479 | families = 0; | - | ||||||||||||
480 | count = 0; | - | ||||||||||||
481 | // don't clear the memory fonts! | - | ||||||||||||
482 | } | - | ||||||||||||
483 | - | |||||||||||||
484 | int count; | - | ||||||||||||
485 | QtFontFamily **families; | - | ||||||||||||
486 | - | |||||||||||||
487 | QCache<FallbacksCacheKey, QStringList> fallbacksCache; | - | ||||||||||||
488 | - | |||||||||||||
489 | - | |||||||||||||
490 | struct ApplicationFont { | - | ||||||||||||
491 | QString fileName; | - | ||||||||||||
492 | QByteArray data; | - | ||||||||||||
493 | QStringList families; | - | ||||||||||||
494 | }; | - | ||||||||||||
495 | QVector<ApplicationFont> applicationFonts; | - | ||||||||||||
496 | int addAppFont(const QByteArray &fontData, const QString &fileName); | - | ||||||||||||
497 | bool reregisterAppFonts; | - | ||||||||||||
498 | bool isApplicationFont(const QString &fileName); | - | ||||||||||||
499 | - | |||||||||||||
500 | void invalidate(); | - | ||||||||||||
501 | }; | - | ||||||||||||
502 | Q_DECLARE_TYPEINFO(QFontDatabasePrivate::ApplicationFont, Q_MOVABLE_TYPE); | - | ||||||||||||
503 | - | |||||||||||||
504 | void QFontDatabasePrivate::invalidate() | - | ||||||||||||
505 | { | - | ||||||||||||
506 | QFontCache::instance()->clear(); | - | ||||||||||||
507 | - | |||||||||||||
508 | fallbacksCache.clear(); | - | ||||||||||||
509 | free(); | - | ||||||||||||
510 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->invalidate(); | - | ||||||||||||
511 | emit static_cast<QGuiApplication *>(QCoreApplication::instance())->fontDatabaseChanged(); | - | ||||||||||||
512 | } | - | ||||||||||||
513 | - | |||||||||||||
514 | QtFontFamily *QFontDatabasePrivate::family(const QString &f, FamilyRequestFlags flags) | - | ||||||||||||
515 | { | - | ||||||||||||
516 | QtFontFamily *fam = 0; | - | ||||||||||||
517 | - | |||||||||||||
518 | int low = 0; | - | ||||||||||||
519 | int high = count; | - | ||||||||||||
520 | int pos = count / 2; | - | ||||||||||||
521 | int res = 1; | - | ||||||||||||
522 | if (count) { | - | ||||||||||||
523 | while ((res = families[pos]->name.compare(f, Qt::CaseInsensitive)) && pos != low) { | - | ||||||||||||
524 | if (res > 0) | - | ||||||||||||
525 | high = pos; | - | ||||||||||||
526 | else | - | ||||||||||||
527 | low = pos; | - | ||||||||||||
528 | pos = (high + low) / 2; | - | ||||||||||||
529 | } | - | ||||||||||||
530 | if (!res) | - | ||||||||||||
531 | fam = families[pos]; | - | ||||||||||||
532 | } | - | ||||||||||||
533 | - | |||||||||||||
534 | if (!fam && (flags & EnsureCreated)) { | - | ||||||||||||
535 | if (res < 0) | - | ||||||||||||
536 | pos++; | - | ||||||||||||
537 | - | |||||||||||||
538 | // qDebug() << "adding family " << f.toLatin1() << " at " << pos << " total=" << count; | - | ||||||||||||
539 | if (!(count % 8)) { | - | ||||||||||||
540 | QtFontFamily **newFamilies = (QtFontFamily **) | - | ||||||||||||
541 | realloc(families, | - | ||||||||||||
542 | (((count+8) >> 3) << 3) * sizeof(QtFontFamily *)); | - | ||||||||||||
543 | Q_CHECK_PTR(newFamilies); | - | ||||||||||||
544 | families = newFamilies; | - | ||||||||||||
545 | } | - | ||||||||||||
546 | - | |||||||||||||
547 | QtFontFamily *family = new QtFontFamily(f); | - | ||||||||||||
548 | memmove(families + pos + 1, families + pos, (count-pos)*sizeof(QtFontFamily *)); | - | ||||||||||||
549 | families[pos] = family; | - | ||||||||||||
550 | count++; | - | ||||||||||||
551 | - | |||||||||||||
552 | fam = families[pos]; | - | ||||||||||||
553 | } | - | ||||||||||||
554 | - | |||||||||||||
555 | if (fam && (flags & EnsurePopulated)) | - | ||||||||||||
556 | fam->ensurePopulated(); | - | ||||||||||||
557 | - | |||||||||||||
558 | return fam; | - | ||||||||||||
559 | } | - | ||||||||||||
560 | - | |||||||||||||
561 | - | |||||||||||||
562 | - | |||||||||||||
563 | static const int scriptForWritingSystem[] = { | - | ||||||||||||
564 | QChar::Script_Common, // Any | - | ||||||||||||
565 | QChar::Script_Latin, // Latin | - | ||||||||||||
566 | QChar::Script_Greek, // Greek | - | ||||||||||||
567 | QChar::Script_Cyrillic, // Cyrillic | - | ||||||||||||
568 | QChar::Script_Armenian, // Armenian | - | ||||||||||||
569 | QChar::Script_Hebrew, // Hebrew | - | ||||||||||||
570 | QChar::Script_Arabic, // Arabic | - | ||||||||||||
571 | QChar::Script_Syriac, // Syriac | - | ||||||||||||
572 | QChar::Script_Thaana, // Thaana | - | ||||||||||||
573 | QChar::Script_Devanagari, // Devanagari | - | ||||||||||||
574 | QChar::Script_Bengali, // Bengali | - | ||||||||||||
575 | QChar::Script_Gurmukhi, // Gurmukhi | - | ||||||||||||
576 | QChar::Script_Gujarati, // Gujarati | - | ||||||||||||
577 | QChar::Script_Oriya, // Oriya | - | ||||||||||||
578 | QChar::Script_Tamil, // Tamil | - | ||||||||||||
579 | QChar::Script_Telugu, // Telugu | - | ||||||||||||
580 | QChar::Script_Kannada, // Kannada | - | ||||||||||||
581 | QChar::Script_Malayalam, // Malayalam | - | ||||||||||||
582 | QChar::Script_Sinhala, // Sinhala | - | ||||||||||||
583 | QChar::Script_Thai, // Thai | - | ||||||||||||
584 | QChar::Script_Lao, // Lao | - | ||||||||||||
585 | QChar::Script_Tibetan, // Tibetan | - | ||||||||||||
586 | QChar::Script_Myanmar, // Myanmar | - | ||||||||||||
587 | QChar::Script_Georgian, // Georgian | - | ||||||||||||
588 | QChar::Script_Khmer, // Khmer | - | ||||||||||||
589 | QChar::Script_Han, // SimplifiedChinese | - | ||||||||||||
590 | QChar::Script_Han, // TraditionalChinese | - | ||||||||||||
591 | QChar::Script_Han, // Japanese | - | ||||||||||||
592 | QChar::Script_Hangul, // Korean | - | ||||||||||||
593 | QChar::Script_Latin, // Vietnamese | - | ||||||||||||
594 | QChar::Script_Common, // Symbol | - | ||||||||||||
595 | QChar::Script_Ogham, // Ogham | - | ||||||||||||
596 | QChar::Script_Runic, // Runic | - | ||||||||||||
597 | QChar::Script_Nko // Nko | - | ||||||||||||
598 | }; | - | ||||||||||||
599 | - | |||||||||||||
600 | Q_STATIC_ASSERT(sizeof(scriptForWritingSystem) / sizeof(scriptForWritingSystem[0]) == QFontDatabase::WritingSystemsCount); | - | ||||||||||||
601 | - | |||||||||||||
602 | Q_GUI_EXPORT int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem) | - | ||||||||||||
603 | { | - | ||||||||||||
604 | return scriptForWritingSystem[writingSystem]; | - | ||||||||||||
605 | } | - | ||||||||||||
606 | - | |||||||||||||
607 | - | |||||||||||||
608 | - | |||||||||||||
609 | - | |||||||||||||
610 | /*! | - | ||||||||||||
611 | \internal | - | ||||||||||||
612 | - | |||||||||||||
613 | This makes sense of the font family name: | - | ||||||||||||
614 | - | |||||||||||||
615 | if the family name contains a '[' and a ']', then we take the text | - | ||||||||||||
616 | between the square brackets as the foundry, and the text before the | - | ||||||||||||
617 | square brackets as the family (ie. "Arial [Monotype]") | - | ||||||||||||
618 | */ | - | ||||||||||||
619 | static void parseFontName(const QString &name, QString &foundry, QString &family) | - | ||||||||||||
620 | { | - | ||||||||||||
621 | int i = name.indexOf(QLatin1Char('[')); | - | ||||||||||||
622 | int li = name.lastIndexOf(QLatin1Char(']')); | - | ||||||||||||
623 | if (i >= 0 && li >= 0 && i < li) { | - | ||||||||||||
624 | foundry = name.mid(i + 1, li - i - 1); | - | ||||||||||||
625 | if (i > 0 && name[i - 1] == QLatin1Char(' ')) | - | ||||||||||||
626 | i--; | - | ||||||||||||
627 | family = name.left(i); | - | ||||||||||||
628 | } else { | - | ||||||||||||
629 | foundry.clear(); | - | ||||||||||||
630 | family = name; | - | ||||||||||||
631 | } | - | ||||||||||||
632 | - | |||||||||||||
633 | // capitalize the family/foundry names | - | ||||||||||||
634 | bool space = true; | - | ||||||||||||
635 | QChar *s = family.data(); | - | ||||||||||||
636 | int len = family.length(); | - | ||||||||||||
637 | while(len--) { | - | ||||||||||||
638 | if (space) *s = s->toUpper(); | - | ||||||||||||
639 | space = s->isSpace(); | - | ||||||||||||
640 | ++s; | - | ||||||||||||
641 | } | - | ||||||||||||
642 | - | |||||||||||||
643 | space = true; | - | ||||||||||||
644 | s = foundry.data(); | - | ||||||||||||
645 | len = foundry.length(); | - | ||||||||||||
646 | while(len--) { | - | ||||||||||||
647 | if (space) *s = s->toUpper(); | - | ||||||||||||
648 | space = s->isSpace(); | - | ||||||||||||
649 | ++s; | - | ||||||||||||
650 | } | - | ||||||||||||
651 | } | - | ||||||||||||
652 | - | |||||||||||||
653 | - | |||||||||||||
654 | struct QtFontDesc | - | ||||||||||||
655 | { | - | ||||||||||||
656 | inline QtFontDesc() : family(0), foundry(0), style(0), size(0) {} | - | ||||||||||||
657 | QtFontFamily *family; | - | ||||||||||||
658 | QtFontFoundry *foundry; | - | ||||||||||||
659 | QtFontStyle *style; | - | ||||||||||||
660 | QtFontSize *size; | - | ||||||||||||
661 | }; | - | ||||||||||||
662 | - | |||||||||||||
663 | static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDef *fontDef, bool multi) | - | ||||||||||||
664 | { | - | ||||||||||||
665 | fontDef->family = desc.family->name; | - | ||||||||||||
666 | if (! desc.foundry->name.isEmpty() && desc.family->count > 1) { | - | ||||||||||||
667 | fontDef->family += QString::fromLatin1(" ["); | - | ||||||||||||
668 | fontDef->family += desc.foundry->name; | - | ||||||||||||
669 | fontDef->family += QLatin1Char(']'); | - | ||||||||||||
670 | } | - | ||||||||||||
671 | - | |||||||||||||
672 | if (desc.style->smoothScalable | - | ||||||||||||
673 | || QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable() | - | ||||||||||||
674 | || (desc.style->bitmapScalable && (request.styleStrategy & QFont::PreferMatch))) { | - | ||||||||||||
675 | fontDef->pixelSize = request.pixelSize; | - | ||||||||||||
676 | } else { | - | ||||||||||||
677 | fontDef->pixelSize = desc.size->pixelSize; | - | ||||||||||||
678 | } | - | ||||||||||||
679 | fontDef->pointSize = request.pointSize; | - | ||||||||||||
680 | - | |||||||||||||
681 | fontDef->styleHint = request.styleHint; | - | ||||||||||||
682 | fontDef->styleStrategy = request.styleStrategy; | - | ||||||||||||
683 | - | |||||||||||||
684 | if (!multi) | - | ||||||||||||
685 | fontDef->weight = desc.style->key.weight; | - | ||||||||||||
686 | if (!multi) | - | ||||||||||||
687 | fontDef->style = desc.style->key.style; | - | ||||||||||||
688 | fontDef->fixedPitch = desc.family->fixedPitch; | - | ||||||||||||
689 | fontDef->stretch = desc.style->key.stretch; | - | ||||||||||||
690 | fontDef->ignorePitch = false; | - | ||||||||||||
691 | } | - | ||||||||||||
692 | - | |||||||||||||
693 | static QStringList familyList(const QFontDef &req) | - | ||||||||||||
694 | { | - | ||||||||||||
695 | // list of families to try | - | ||||||||||||
696 | QStringList family_list; | - | ||||||||||||
697 | if (req.family.isEmpty())
| 0 | ||||||||||||
698 | return family_list; never executed: return family_list; | 0 | ||||||||||||
699 | - | |||||||||||||
700 | QStringListconst auto list = req.family.splitsplitRef(QLatin1Char(',')); | - | ||||||||||||
701 | const int numFamilies = list.size(); | - | ||||||||||||
702 | family_list.reserve(numFamilies); | - | ||||||||||||
703 | for (int i = 0; i < numFamilies; ++i) {
| 0 | ||||||||||||
704 | QStringQStringRef str = list.at(i).trimmed(); | - | ||||||||||||
705 | if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"')))
| 0 | ||||||||||||
706 | || (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\''))))
| 0 | ||||||||||||
707 | str = str.mid(1, str.length() - 2); never executed: str = str.mid(1, str.length() - 2); | 0 | ||||||||||||
708 | family_list << str;.toString(); | - | ||||||||||||
709 | } never executed: end of block | 0 | ||||||||||||
710 | - | |||||||||||||
711 | // append the substitute list for each family in family_list | - | ||||||||||||
712 | QStringList subs_list;
| 0 | ||||||||||||
QStringList::ConstIterator it
| ||||||||||||||
713 | subs_listfamily_list += QFont::substitutes(*it); never executed: family_list += QFont::substitutes(family_list.at(i)); | 0 | ||||||||||||
713 | ( never executed: family_list += QFont::substitutes(family_list.at(i)); never executed: family_list+= subs_list;.at(i));family_list += QFont::substitutes(family_list.at(i)); never executed: family_list += QFont::substitutes(family_list.at(i)); | 0 | ||||||||||||
714 | - | |||||||||||||
715 | return family_list; never executed: return family_list; | 0 | ||||||||||||
716 | } | - | ||||||||||||
717 | - | |||||||||||||
718 | Q_GLOBAL_STATIC(QFontDatabasePrivate, privateDb) | - | ||||||||||||
719 | Q_GLOBAL_STATIC_WITH_ARGS(QMutex, fontDatabaseMutex, (QMutex::Recursive)) | - | ||||||||||||
720 | - | |||||||||||||
721 | // used in qguiapplication.cpp | - | ||||||||||||
722 | void qt_cleanupFontDatabase() | - | ||||||||||||
723 | { | - | ||||||||||||
724 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
725 | if (db) { | - | ||||||||||||
726 | db->fallbacksCache.clear(); | - | ||||||||||||
727 | db->free(); | - | ||||||||||||
728 | } | - | ||||||||||||
729 | } | - | ||||||||||||
730 | - | |||||||||||||
731 | // used in qfontengine_x11.cpp | - | ||||||||||||
732 | QMutex *qt_fontdatabase_mutex() | - | ||||||||||||
733 | { | - | ||||||||||||
734 | return fontDatabaseMutex(); | - | ||||||||||||
735 | } | - | ||||||||||||
736 | - | |||||||||||||
737 | - | |||||||||||||
738 | void qt_registerFont(const QString &familyName, const QString &stylename, | - | ||||||||||||
739 | const QString &foundryname, int weight, | - | ||||||||||||
740 | QFont::Style style, int stretch, bool antialiased, | - | ||||||||||||
741 | bool scalable, int pixelSize, bool fixedPitch, | - | ||||||||||||
742 | const QSupportedWritingSystems &writingSystems, void *handle) | - | ||||||||||||
743 | { | - | ||||||||||||
744 | QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||
745 | // qDebug() << "Adding font" << familyName << weight << style << pixelSize << antialiased; | - | ||||||||||||
746 | QtFontStyle::Key styleKey; | - | ||||||||||||
747 | styleKey.style = style; | - | ||||||||||||
748 | styleKey.weight = weight; | - | ||||||||||||
749 | styleKey.stretch = stretch; | - | ||||||||||||
750 | QtFontFamily *f = d->family(familyName, QFontDatabasePrivate::EnsureCreated); | - | ||||||||||||
751 | f->fixedPitch = fixedPitch; | - | ||||||||||||
752 | - | |||||||||||||
753 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { | - | ||||||||||||
754 | if (writingSystems.supported(QFontDatabase::WritingSystem(i))) | - | ||||||||||||
755 | f->writingSystems[i] = QtFontFamily::Supported; | - | ||||||||||||
756 | } | - | ||||||||||||
757 | - | |||||||||||||
758 | QtFontFoundry *foundry = f->foundry(foundryname, true); | - | ||||||||||||
759 | QtFontStyle *fontStyle = foundry->style(styleKey, stylename, true); | - | ||||||||||||
760 | fontStyle->smoothScalable = scalable; | - | ||||||||||||
761 | fontStyle->antialiased = antialiased; | - | ||||||||||||
762 | QtFontSize *size = fontStyle->pixelSize(pixelSize ? pixelSize : SMOOTH_SCALABLE, true); | - | ||||||||||||
763 | if (size->handle) { | - | ||||||||||||
764 | QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||
765 | if (integration) | - | ||||||||||||
766 | integration->fontDatabase()->releaseHandle(size->handle); | - | ||||||||||||
767 | } | - | ||||||||||||
768 | size->handle = handle; | - | ||||||||||||
769 | f->populated = true; | - | ||||||||||||
770 | } | - | ||||||||||||
771 | - | |||||||||||||
772 | void qt_registerFontFamily(const QString &familyName) | - | ||||||||||||
773 | { | - | ||||||||||||
774 | // Create uninitialized/unpopulated family | - | ||||||||||||
775 | privateDb()->family(familyName, QFontDatabasePrivate::EnsureCreated); | - | ||||||||||||
776 | } | - | ||||||||||||
777 | - | |||||||||||||
778 | void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias) | - | ||||||||||||
779 | { | - | ||||||||||||
780 | if (alias.isEmpty()) | - | ||||||||||||
781 | return; | - | ||||||||||||
782 | - | |||||||||||||
783 | QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||
784 | QtFontFamily *f = d->family(familyName, QFontDatabasePrivate::RequestFamily); | - | ||||||||||||
785 | if (!f) | - | ||||||||||||
786 | return; | - | ||||||||||||
787 | - | |||||||||||||
788 | if (f->aliases.contains(alias, Qt::CaseInsensitive)) | - | ||||||||||||
789 | return; | - | ||||||||||||
790 | - | |||||||||||||
791 | f->aliases.push_back(alias); | - | ||||||||||||
792 | } | - | ||||||||||||
793 | - | |||||||||||||
794 | QString qt_resolveFontFamilyAlias(const QString &alias) | - | ||||||||||||
795 | { | - | ||||||||||||
796 | if (!alias.isEmpty()) { | - | ||||||||||||
797 | const QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||
798 | for (int i = 0; i < d->count; ++i) | - | ||||||||||||
799 | if (d->families[i]->matchesFamilyName(alias)) | - | ||||||||||||
800 | return d->families[i]->name; | - | ||||||||||||
801 | } | - | ||||||||||||
802 | return alias; | - | ||||||||||||
803 | } | - | ||||||||||||
804 | - | |||||||||||||
805 | QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const | - | ||||||||||||
806 | { | - | ||||||||||||
807 | Q_UNUSED(family); | - | ||||||||||||
808 | Q_UNUSED(styleHint); | - | ||||||||||||
809 | - | |||||||||||||
810 | QStringList preferredFallbacks; | - | ||||||||||||
811 | QStringList otherFallbacks; | - | ||||||||||||
812 | - | |||||||||||||
813 | size_t writingSystem = std::find(scriptForWritingSystem, | - | ||||||||||||
814 | scriptForWritingSystem + QFontDatabase::WritingSystemsCount, | - | ||||||||||||
815 | script) - scriptForWritingSystem; | - | ||||||||||||
816 | if (writingSystem >= QFontDatabase::WritingSystemsCount) | - | ||||||||||||
817 | writingSystem = QFontDatabase::Any; | - | ||||||||||||
818 | - | |||||||||||||
819 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
820 | for (int i = 0; i < db->count; ++i) { | - | ||||||||||||
821 | QtFontFamily *f = db->families[i]; | - | ||||||||||||
822 | - | |||||||||||||
823 | f->ensurePopulated(); | - | ||||||||||||
824 | - | |||||||||||||
825 | if (writingSystem > QFontDatabase::Any && f->writingSystems[writingSystem] != QtFontFamily::Supported) | - | ||||||||||||
826 | continue; | - | ||||||||||||
827 | - | |||||||||||||
828 | for (int j = 0; j < f->count; ++j) { | - | ||||||||||||
829 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
830 | - | |||||||||||||
831 | for (int k = 0; k < foundry->count; ++k) { | - | ||||||||||||
832 | QString name = foundry->name.isEmpty() | - | ||||||||||||
833 | ? f->name | - | ||||||||||||
834 | : f->name + QLatin1String(" [") + foundry->name + QLatin1Char(']'); | - | ||||||||||||
835 | if (style == foundry->styles[k]->key.style) | - | ||||||||||||
836 | preferredFallbacks.append(name); | - | ||||||||||||
837 | else | - | ||||||||||||
838 | otherFallbacks.append(name); | - | ||||||||||||
839 | } | - | ||||||||||||
840 | } | - | ||||||||||||
841 | } | - | ||||||||||||
842 | - | |||||||||||||
843 | return preferredFallbacks + otherFallbacks; | - | ||||||||||||
844 | } | - | ||||||||||||
845 | - | |||||||||||||
846 | static void initializeDb(); | - | ||||||||||||
847 | - | |||||||||||||
848 | static QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) | - | ||||||||||||
849 | { | - | ||||||||||||
850 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
851 | if (!db->count) | - | ||||||||||||
852 | initializeDb(); | - | ||||||||||||
853 | - | |||||||||||||
854 | const FallbacksCacheKey cacheKey = { family, style, styleHint, script }; | - | ||||||||||||
855 | - | |||||||||||||
856 | if (const QStringList *fallbacks = db->fallbacksCache.object(cacheKey)) | - | ||||||||||||
857 | return *fallbacks; | - | ||||||||||||
858 | - | |||||||||||||
859 | // make sure that the db has all fallback families | - | ||||||||||||
860 | QStringList retList = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(family,style,styleHint,script); | - | ||||||||||||
861 | - | |||||||||||||
862 | QStringList::iterator i; | - | ||||||||||||
863 | for (i = retList.begin(); i != retList.end(); ++i) { | - | ||||||||||||
864 | bool contains = false; | - | ||||||||||||
865 | for (int j = 0; j < db->count; j++) { | - | ||||||||||||
866 | if (db->families[j]->matchesFamilyName(*i)) { | - | ||||||||||||
867 | contains = true; | - | ||||||||||||
868 | break; | - | ||||||||||||
869 | } | - | ||||||||||||
870 | } | - | ||||||||||||
871 | if (!contains) { | - | ||||||||||||
872 | i = retList.erase(i); | - | ||||||||||||
873 | --i; | - | ||||||||||||
874 | } | - | ||||||||||||
875 | } | - | ||||||||||||
876 | - | |||||||||||||
877 | db->fallbacksCache.insert(cacheKey, new QStringList(retList)); | - | ||||||||||||
878 | - | |||||||||||||
879 | return retList; | - | ||||||||||||
880 | } | - | ||||||||||||
881 | - | |||||||||||||
882 | QStringList qt_fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) | - | ||||||||||||
883 | { | - | ||||||||||||
884 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
885 | return fallbacksForFamily(family, style, styleHint, script); | - | ||||||||||||
886 | } | - | ||||||||||||
887 | - | |||||||||||||
888 | static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt); | - | ||||||||||||
889 | - | |||||||||||||
890 | static void initializeDb() | - | ||||||||||||
891 | { | - | ||||||||||||
892 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
893 | - | |||||||||||||
894 | // init by asking for the platformfontdb for the first time or after invalidation | - | ||||||||||||
895 | if (!db->count) | - | ||||||||||||
896 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); | - | ||||||||||||
897 | - | |||||||||||||
898 | if (db->reregisterAppFonts) { | - | ||||||||||||
899 | for (int i = 0; i < db->applicationFonts.count(); i++) { | - | ||||||||||||
900 | if (!db->applicationFonts.at(i).families.isEmpty()) | - | ||||||||||||
901 | registerFont(&db->applicationFonts[i]); | - | ||||||||||||
902 | } | - | ||||||||||||
903 | db->reregisterAppFonts = false; | - | ||||||||||||
904 | } | - | ||||||||||||
905 | } | - | ||||||||||||
906 | - | |||||||||||||
907 | static inline void load(const QString & = QString(), int = -1) | - | ||||||||||||
908 | { | - | ||||||||||||
909 | // Only initialize the database if it has been cleared or not initialized yet | - | ||||||||||||
910 | if (!privateDb()->count) | - | ||||||||||||
911 | initializeDb(); | - | ||||||||||||
912 | } | - | ||||||||||||
913 | - | |||||||||||||
914 | static | - | ||||||||||||
915 | QFontEngine *loadSingleEngine(int script, | - | ||||||||||||
916 | const QFontDef &request, | - | ||||||||||||
917 | QtFontFamily *family, QtFontFoundry *foundry, | - | ||||||||||||
918 | QtFontStyle *style, QtFontSize *size) | - | ||||||||||||
919 | { | - | ||||||||||||
920 | Q_UNUSED(foundry); | - | ||||||||||||
921 | - | |||||||||||||
922 | Q_ASSERT(size); | - | ||||||||||||
923 | QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); | - | ||||||||||||
924 | int pixelSize = size->pixelSize; | - | ||||||||||||
925 | if (!pixelSize || (style->smoothScalable && pixelSize == SMOOTH_SCALABLE) | - | ||||||||||||
926 | || pfdb->fontsAlwaysScalable()) { | - | ||||||||||||
927 | pixelSize = request.pixelSize; | - | ||||||||||||
928 | } | - | ||||||||||||
929 | - | |||||||||||||
930 | QFontDef def = request; | - | ||||||||||||
931 | def.pixelSize = pixelSize; | - | ||||||||||||
932 | - | |||||||||||||
933 | QFontCache *fontCache = QFontCache::instance(); | - | ||||||||||||
934 | - | |||||||||||||
935 | QFontCache::Key key(def,script); | - | ||||||||||||
936 | QFontEngine *engine = fontCache->findEngine(key); | - | ||||||||||||
937 | if (!engine) { | - | ||||||||||||
938 | const bool cacheForCommonScript = script != QChar::Script_Common | - | ||||||||||||
939 | && (family->writingSystems[QFontDatabase::Latin] & QtFontFamily::Supported) != 0; | - | ||||||||||||
940 | - | |||||||||||||
941 | if (Q_LIKELY(cacheForCommonScript)) { | - | ||||||||||||
942 | // fast path: check if engine was loaded for another script | - | ||||||||||||
943 | key.script = QChar::Script_Common; | - | ||||||||||||
944 | engine = fontCache->findEngine(key); | - | ||||||||||||
945 | key.script = script; | - | ||||||||||||
946 | if (engine) { | - | ||||||||||||
947 | // Also check for OpenType tables when using complex scripts | - | ||||||||||||
948 | if (Q_UNLIKELY(!engine->supportsScript(QChar::Script(script)))) { | - | ||||||||||||
949 | qWarning(" OpenType support missing for script %d", script); | - | ||||||||||||
950 | return 0; | - | ||||||||||||
951 | } | - | ||||||||||||
952 | - | |||||||||||||
953 | engine->isSmoothlyScalable = style->smoothScalable; | - | ||||||||||||
954 | fontCache->insertEngine(key, engine); | - | ||||||||||||
955 | return engine; | - | ||||||||||||
956 | } | - | ||||||||||||
957 | } | - | ||||||||||||
958 | - | |||||||||||||
959 | // If the font data's native stretch matches the requested stretch we need to set stretch to 100 | - | ||||||||||||
960 | // to avoid the fontengine synthesizing stretch. If they didn't match exactly we need to calculate | - | ||||||||||||
961 | // the new stretch factor. This only done if not matched by styleName. | - | ||||||||||||
962 | if (style->key.stretch != 0 && request.stretch != 0 | - | ||||||||||||
963 | && (request.styleName.isEmpty() || request.styleName != style->styleName)) { | - | ||||||||||||
964 | def.stretch = (request.stretch * 100 + 50) / style->key.stretch; | - | ||||||||||||
965 | } | - | ||||||||||||
966 | - | |||||||||||||
967 | engine = pfdb->fontEngine(def, size->handle); | - | ||||||||||||
968 | if (engine) { | - | ||||||||||||
969 | // Also check for OpenType tables when using complex scripts | - | ||||||||||||
970 | if (!engine->supportsScript(QChar::Script(script))) { | - | ||||||||||||
971 | qWarning(" OpenType support missing for script %d", script); | - | ||||||||||||
972 | if (engine->ref.load() == 0) | - | ||||||||||||
973 | delete engine; | - | ||||||||||||
974 | return 0; | - | ||||||||||||
975 | } | - | ||||||||||||
976 | - | |||||||||||||
977 | engine->isSmoothlyScalable = style->smoothScalable; | - | ||||||||||||
978 | fontCache->insertEngine(key, engine); | - | ||||||||||||
979 | - | |||||||||||||
980 | if (Q_LIKELY(cacheForCommonScript && !engine->symbol)) { | - | ||||||||||||
981 | // cache engine for Common script as well | - | ||||||||||||
982 | key.script = QChar::Script_Common; | - | ||||||||||||
983 | if (!fontCache->findEngine(key)) | - | ||||||||||||
984 | fontCache->insertEngine(key, engine); | - | ||||||||||||
985 | } | - | ||||||||||||
986 | } | - | ||||||||||||
987 | } | - | ||||||||||||
988 | return engine; | - | ||||||||||||
989 | } | - | ||||||||||||
990 | - | |||||||||||||
991 | static | - | ||||||||||||
992 | QFontEngine *loadEngine(int script, const QFontDef &request, | - | ||||||||||||
993 | QtFontFamily *family, QtFontFoundry *foundry, | - | ||||||||||||
994 | QtFontStyle *style, QtFontSize *size) | - | ||||||||||||
995 | { | - | ||||||||||||
996 | QFontEngine *engine = loadSingleEngine(script, request, family, foundry, style, size); | - | ||||||||||||
997 | - | |||||||||||||
998 | if (engine && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) { | - | ||||||||||||
999 | QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); | - | ||||||||||||
1000 | QFontEngineMulti *pfMultiEngine = pfdb->fontEngineMulti(engine, QChar::Script(script)); | - | ||||||||||||
1001 | if (!request.fallBackFamilies.isEmpty()) { | - | ||||||||||||
1002 | QStringList fallbacks = request.fallBackFamilies; | - | ||||||||||||
1003 | - | |||||||||||||
1004 | QFont::StyleHint styleHint = QFont::StyleHint(request.styleHint); | - | ||||||||||||
1005 | if (styleHint == QFont::AnyStyle && request.fixedPitch) | - | ||||||||||||
1006 | styleHint = QFont::TypeWriter; | - | ||||||||||||
1007 | - | |||||||||||||
1008 | fallbacks += fallbacksForFamily(family->name, QFont::Style(style->key.style), styleHint, QChar::Script(script)); | - | ||||||||||||
1009 | - | |||||||||||||
1010 | pfMultiEngine->setFallbackFamiliesList(fallbacks); | - | ||||||||||||
1011 | } | - | ||||||||||||
1012 | engine = pfMultiEngine; | - | ||||||||||||
1013 | - | |||||||||||||
1014 | // Cache Multi font engine as well in case we got the single | - | ||||||||||||
1015 | // font engine when we are actually looking for a Multi one | - | ||||||||||||
1016 | QFontCache::Key key(request, script, 1); | - | ||||||||||||
1017 | QFontCache::instance()->insertEngine(key, engine); | - | ||||||||||||
1018 | } | - | ||||||||||||
1019 | - | |||||||||||||
1020 | return engine; | - | ||||||||||||
1021 | } | - | ||||||||||||
1022 | - | |||||||||||||
1023 | static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) | - | ||||||||||||
1024 | { | - | ||||||||||||
1025 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
1026 | - | |||||||||||||
1027 | fnt->families = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->addApplicationFont(fnt->data,fnt->fileName); | - | ||||||||||||
1028 | - | |||||||||||||
1029 | db->reregisterAppFonts = true; | - | ||||||||||||
1030 | } | - | ||||||||||||
1031 | - | |||||||||||||
1032 | static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &styleKey, | - | ||||||||||||
1033 | const QString &styleName = QString()) | - | ||||||||||||
1034 | { | - | ||||||||||||
1035 | int best = 0; | - | ||||||||||||
1036 | int dist = 0xffff; | - | ||||||||||||
1037 | - | |||||||||||||
1038 | for ( int i = 0; i < foundry->count; i++ ) { | - | ||||||||||||
1039 | QtFontStyle *style = foundry->styles[i]; | - | ||||||||||||
1040 | - | |||||||||||||
1041 | if (!styleName.isEmpty() && styleName == style->styleName) { | - | ||||||||||||
1042 | dist = 0; | - | ||||||||||||
1043 | best = i; | - | ||||||||||||
1044 | break; | - | ||||||||||||
1045 | } | - | ||||||||||||
1046 | - | |||||||||||||
1047 | int d = qAbs( styleKey.weight - style->key.weight ); | - | ||||||||||||
1048 | - | |||||||||||||
1049 | if ( styleKey.stretch != 0 && style->key.stretch != 0 ) { | - | ||||||||||||
1050 | d += qAbs( styleKey.stretch - style->key.stretch ); | - | ||||||||||||
1051 | } | - | ||||||||||||
1052 | - | |||||||||||||
1053 | if (styleKey.style != style->key.style) { | - | ||||||||||||
1054 | if (styleKey.style != QFont::StyleNormal && style->key.style != QFont::StyleNormal) | - | ||||||||||||
1055 | // one is italic, the other oblique | - | ||||||||||||
1056 | d += 0x0001; | - | ||||||||||||
1057 | else | - | ||||||||||||
1058 | d += 0x1000; | - | ||||||||||||
1059 | } | - | ||||||||||||
1060 | - | |||||||||||||
1061 | if ( d < dist ) { | - | ||||||||||||
1062 | best = i; | - | ||||||||||||
1063 | dist = d; | - | ||||||||||||
1064 | } | - | ||||||||||||
1065 | } | - | ||||||||||||
1066 | - | |||||||||||||
1067 | FM_DEBUG( " best style has distance 0x%x", dist ); dead code: QMessageLogger(__FILE__, 1067, __PRETTY_FUNCTION__).debug( " best style has distance 0x%x", dist ); | - | ||||||||||||
1068 | return foundry->styles[best]; | - | ||||||||||||
1069 | } | - | ||||||||||||
1070 | - | |||||||||||||
1071 | - | |||||||||||||
1072 | static | - | ||||||||||||
1073 | unsigned int bestFoundry(int script, unsigned int score, int styleStrategy, | - | ||||||||||||
1074 | const QtFontFamily *family, const QString &foundry_name, | - | ||||||||||||
1075 | QtFontStyle::Key styleKey, int pixelSize, char pitch, | - | ||||||||||||
1076 | QtFontDesc *desc, const QString &styleName = QString()) | - | ||||||||||||
1077 | { | - | ||||||||||||
1078 | Q_UNUSED(script); | - | ||||||||||||
1079 | Q_UNUSED(pitch); | - | ||||||||||||
1080 | - | |||||||||||||
1081 | desc->foundry = 0; | - | ||||||||||||
1082 | desc->style = 0; | - | ||||||||||||
1083 | desc->size = 0; | - | ||||||||||||
1084 | - | |||||||||||||
1085 | - | |||||||||||||
1086 | FM_DEBUG(" REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count); dead code: QMessageLogger(__FILE__, 1086, __PRETTY_FUNCTION__).debug(" REMARK: looking for best foundry for family '%s' [%d]", family->name.toLatin1().constData(), family->count); | - | ||||||||||||
1087 | - | |||||||||||||
1088 | for (int x = 0; x < family->count; ++x) { | - | ||||||||||||
1089 | QtFontFoundry *foundry = family->foundries[x]; | - | ||||||||||||
1090 | if (!foundry_name.isEmpty() && foundry->name.compare(foundry_name, Qt::CaseInsensitive) != 0) | - | ||||||||||||
1091 | continue; | - | ||||||||||||
1092 | - | |||||||||||||
1093 | FM_DEBUG(" looking for matching style in foundry '%s' %d", dead code: QMessageLogger(__FILE__, 1093, __PRETTY_FUNCTION__).debug(" looking for matching style in foundry '%s' %d", foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count); | - | ||||||||||||
1094 | foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count); dead code: QMessageLogger(__FILE__, 1093, __PRETTY_FUNCTION__).debug(" looking for matching style in foundry '%s' %d", foundry->name.isEmpty() ? "-- none --" : foundry->name.toLatin1().constData(), foundry->count); | - | ||||||||||||
1095 | - | |||||||||||||
1096 | QtFontStyle *style = bestStyle(foundry, styleKey, styleName); | - | ||||||||||||
1097 | - | |||||||||||||
1098 | if (!style->smoothScalable && (styleStrategy & QFont::ForceOutline)) { | - | ||||||||||||
1099 | FM_DEBUG(" ForceOutline set, but not smoothly scalable"); dead code: QMessageLogger(__FILE__, 1099, __PRETTY_FUNCTION__).debug(" ForceOutline set, but not smoothly scalable"); | - | ||||||||||||
1100 | continue; | - | ||||||||||||
1101 | } | - | ||||||||||||
1102 | - | |||||||||||||
1103 | int px = -1; | - | ||||||||||||
1104 | QtFontSize *size = 0; | - | ||||||||||||
1105 | - | |||||||||||||
1106 | // 1. see if we have an exact matching size | - | ||||||||||||
1107 | if (!(styleStrategy & QFont::ForceOutline)) { | - | ||||||||||||
1108 | size = style->pixelSize(pixelSize); | - | ||||||||||||
1109 | if (size) { | - | ||||||||||||
1110 | FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize); dead code: QMessageLogger(__FILE__, 1110, __PRETTY_FUNCTION__).debug(" found exact size match (%d pixels)", size->pixelSize); | - | ||||||||||||
1111 | px = size->pixelSize; | - | ||||||||||||
1112 | } | - | ||||||||||||
1113 | } | - | ||||||||||||
1114 | - | |||||||||||||
1115 | // 2. see if we have a smoothly scalable font | - | ||||||||||||
1116 | if (!size && style->smoothScalable && ! (styleStrategy & QFont::PreferBitmap)) { | - | ||||||||||||
1117 | size = style->pixelSize(SMOOTH_SCALABLE); | - | ||||||||||||
1118 | if (size) { | - | ||||||||||||
1119 | FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize); dead code: QMessageLogger(__FILE__, 1119, __PRETTY_FUNCTION__).debug(" found smoothly scalable font (%d pixels)", pixelSize); | - | ||||||||||||
1120 | px = pixelSize; | - | ||||||||||||
1121 | } | - | ||||||||||||
1122 | } | - | ||||||||||||
1123 | - | |||||||||||||
1124 | // 3. see if we have a bitmap scalable font | - | ||||||||||||
1125 | if (!size && style->bitmapScalable && (styleStrategy & QFont::PreferMatch)) { | - | ||||||||||||
1126 | size = style->pixelSize(0); | - | ||||||||||||
1127 | if (size) { | - | ||||||||||||
1128 | FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize); dead code: QMessageLogger(__FILE__, 1128, __PRETTY_FUNCTION__).debug(" found bitmap scalable font (%d pixels)", pixelSize); | - | ||||||||||||
1129 | px = pixelSize; | - | ||||||||||||
1130 | } | - | ||||||||||||
1131 | } | - | ||||||||||||
1132 | - | |||||||||||||
1133 | - | |||||||||||||
1134 | // 4. find closest size match | - | ||||||||||||
1135 | if (! size) { | - | ||||||||||||
1136 | unsigned int distance = ~0u; | - | ||||||||||||
1137 | for (int x = 0; x < style->count; ++x) { | - | ||||||||||||
1138 | - | |||||||||||||
1139 | unsigned int d; | - | ||||||||||||
1140 | if (style->pixelSizes[x].pixelSize < pixelSize) { | - | ||||||||||||
1141 | // penalize sizes that are smaller than the | - | ||||||||||||
1142 | // requested size, due to truncation from floating | - | ||||||||||||
1143 | // point to integer conversions | - | ||||||||||||
1144 | d = pixelSize - style->pixelSizes[x].pixelSize + 1; | - | ||||||||||||
1145 | } else { | - | ||||||||||||
1146 | d = style->pixelSizes[x].pixelSize - pixelSize; | - | ||||||||||||
1147 | } | - | ||||||||||||
1148 | - | |||||||||||||
1149 | if (d < distance) { | - | ||||||||||||
1150 | distance = d; | - | ||||||||||||
1151 | size = style->pixelSizes + x; | - | ||||||||||||
1152 | FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize); dead code: QMessageLogger(__FILE__, 1152, __PRETTY_FUNCTION__).debug(" best size so far: %3d (%d)", size->pixelSize, pixelSize); | - | ||||||||||||
1153 | } | - | ||||||||||||
1154 | } | - | ||||||||||||
1155 | - | |||||||||||||
1156 | if (!size) { | - | ||||||||||||
1157 | FM_DEBUG(" no size supports the script we want"); dead code: QMessageLogger(__FILE__, 1157, __PRETTY_FUNCTION__).debug(" no size supports the script we want"); | - | ||||||||||||
1158 | continue; | - | ||||||||||||
1159 | } | - | ||||||||||||
1160 | - | |||||||||||||
1161 | if (style->bitmapScalable && ! (styleStrategy & QFont::PreferQuality) && | - | ||||||||||||
1162 | (distance * 10 / pixelSize) >= 2) { | - | ||||||||||||
1163 | // the closest size is not close enough, go ahead and | - | ||||||||||||
1164 | // use a bitmap scaled font | - | ||||||||||||
1165 | size = style->pixelSize(0); | - | ||||||||||||
1166 | px = pixelSize; | - | ||||||||||||
1167 | } else { | - | ||||||||||||
1168 | px = size->pixelSize; | - | ||||||||||||
1169 | } | - | ||||||||||||
1170 | } | - | ||||||||||||
1171 | - | |||||||||||||
1172 | - | |||||||||||||
1173 | unsigned int this_score = 0x0000; | - | ||||||||||||
1174 | enum { | - | ||||||||||||
1175 | PitchMismatch = 0x4000, | - | ||||||||||||
1176 | StyleMismatch = 0x2000, | - | ||||||||||||
1177 | BitmapScaledPenalty = 0x1000 | - | ||||||||||||
1178 | }; | - | ||||||||||||
1179 | if (pitch != '*') { | - | ||||||||||||
1180 | if ((pitch == 'm' && !family->fixedPitch) | - | ||||||||||||
1181 | || (pitch == 'p' && family->fixedPitch)) | - | ||||||||||||
1182 | this_score += PitchMismatch; | - | ||||||||||||
1183 | } | - | ||||||||||||
1184 | if (styleKey != style->key) | - | ||||||||||||
1185 | this_score += StyleMismatch; | - | ||||||||||||
1186 | if (!style->smoothScalable && px != size->pixelSize) // bitmap scaled | - | ||||||||||||
1187 | this_score += BitmapScaledPenalty; | - | ||||||||||||
1188 | if (px != pixelSize) // close, but not exact, size match | - | ||||||||||||
1189 | this_score += qAbs(px - pixelSize); | - | ||||||||||||
1190 | - | |||||||||||||
1191 | if (this_score < score) { | - | ||||||||||||
1192 | FM_DEBUG(" found a match: score %x best score so far %x", dead code: QMessageLogger(__FILE__, 1192, __PRETTY_FUNCTION__).debug(" found a match: score %x best score so far %x", this_score, score); | - | ||||||||||||
1193 | this_score, score); dead code: QMessageLogger(__FILE__, 1192, __PRETTY_FUNCTION__).debug(" found a match: score %x best score so far %x", this_score, score); | - | ||||||||||||
1194 | - | |||||||||||||
1195 | score = this_score; | - | ||||||||||||
1196 | desc->foundry = foundry; | - | ||||||||||||
1197 | desc->style = style; | - | ||||||||||||
1198 | desc->size = size; | - | ||||||||||||
1199 | } else { | - | ||||||||||||
1200 | FM_DEBUG(" score %x no better than best %x", this_score, score); dead code: QMessageLogger(__FILE__, 1200, __PRETTY_FUNCTION__).debug(" score %x no better than best %x", this_score, score); | - | ||||||||||||
1201 | } | - | ||||||||||||
1202 | } | - | ||||||||||||
1203 | - | |||||||||||||
1204 | return score; | - | ||||||||||||
1205 | } | - | ||||||||||||
1206 | - | |||||||||||||
1207 | static bool matchFamilyName(const QString &familyName, QtFontFamily *f) | - | ||||||||||||
1208 | { | - | ||||||||||||
1209 | if (familyName.isEmpty()) | - | ||||||||||||
1210 | return true; | - | ||||||||||||
1211 | return f->matchesFamilyName(familyName); | - | ||||||||||||
1212 | } | - | ||||||||||||
1213 | - | |||||||||||||
1214 | /*! | - | ||||||||||||
1215 | \internal | - | ||||||||||||
1216 | - | |||||||||||||
1217 | Tries to find the best match for a given request and family/foundry | - | ||||||||||||
1218 | */ | - | ||||||||||||
1219 | static int match(int script, const QFontDef &request, | - | ||||||||||||
1220 | const QString &family_name, const QString &foundry_name, | - | ||||||||||||
1221 | QtFontDesc *desc, const QList<int> &blacklistedFamilies) | - | ||||||||||||
1222 | { | - | ||||||||||||
1223 | int result = -1; | - | ||||||||||||
1224 | - | |||||||||||||
1225 | QtFontStyle::Key styleKey; | - | ||||||||||||
1226 | styleKey.style = request.style; | - | ||||||||||||
1227 | styleKey.weight = request.weight; | - | ||||||||||||
1228 | styleKey.stretch = request.stretch; | - | ||||||||||||
1229 | char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p'; | - | ||||||||||||
1230 | - | |||||||||||||
1231 | - | |||||||||||||
1232 | FM_DEBUG("QFontDatabase::match\n" dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1233 | " request:\n" dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1234 | " family: %s [%s], script: %d\n" dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1235 | " weight: %d, style: %d\n" dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1236 | " stretch: %d\n" dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1237 | " pixelSize: %g\n" dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1238 | " pitch: %c", dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1239 | family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1240 | foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1241 | script, request.weight, request.style, request.stretch, request.pixelSize, pitch); dead code: QMessageLogger(__FILE__, 1232, __PRETTY_FUNCTION__).debug("QFontDatabase::match\n" " request:\n" " family: %s [%s], script: %d\n" " weight: %d, style: %d\n" " stretch: %d\n" " pixelSize: %g\n" " pitch: %c", family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(), foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(), script, request.weight, request.style, request.stretch, request.pixelSize, pitch); | - | ||||||||||||
1242 | - | |||||||||||||
1243 | desc->family = 0; | - | ||||||||||||
1244 | desc->foundry = 0; | - | ||||||||||||
1245 | desc->style = 0; | - | ||||||||||||
1246 | desc->size = 0; | - | ||||||||||||
1247 | - | |||||||||||||
1248 | unsigned int score = ~0u; | - | ||||||||||||
1249 | - | |||||||||||||
1250 | load(family_name, script); | - | ||||||||||||
1251 | - | |||||||||||||
1252 | size_t writingSystem = std::find(scriptForWritingSystem, scriptForWritingSystem + | - | ||||||||||||
1253 | QFontDatabase::WritingSystemsCount, script) - scriptForWritingSystem; | - | ||||||||||||
1254 | if (writingSystem >= QFontDatabase::WritingSystemsCount) | - | ||||||||||||
1255 | writingSystem = QFontDatabase::Any; | - | ||||||||||||
1256 | - | |||||||||||||
1257 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
1258 | for (int x = 0; x < db->count; ++x) { | - | ||||||||||||
1259 | if (blacklistedFamilies.contains(x)) | - | ||||||||||||
1260 | continue; | - | ||||||||||||
1261 | QtFontDesc test; | - | ||||||||||||
1262 | test.family = db->families[x]; | - | ||||||||||||
1263 | - | |||||||||||||
1264 | if (!matchFamilyName(family_name, test.family)) | - | ||||||||||||
1265 | continue; | - | ||||||||||||
1266 | - | |||||||||||||
1267 | test.family->ensurePopulated(); | - | ||||||||||||
1268 | - | |||||||||||||
1269 | // Check if family is supported in the script we want | - | ||||||||||||
1270 | if (writingSystem != QFontDatabase::Any && !(test.family->writingSystems[writingSystem] & QtFontFamily::Supported)) | - | ||||||||||||
1271 | continue; | - | ||||||||||||
1272 | - | |||||||||||||
1273 | // as we know the script is supported, we can be sure | - | ||||||||||||
1274 | // to find a matching font here. | - | ||||||||||||
1275 | unsigned int newscore = | - | ||||||||||||
1276 | bestFoundry(script, score, request.styleStrategy, | - | ||||||||||||
1277 | test.family, foundry_name, styleKey, request.pixelSize, pitch, | - | ||||||||||||
1278 | &test, request.styleName); | - | ||||||||||||
1279 | if (test.foundry == 0 && !foundry_name.isEmpty()) { | - | ||||||||||||
1280 | // the specific foundry was not found, so look for | - | ||||||||||||
1281 | // any foundry matching our requirements | - | ||||||||||||
1282 | newscore = bestFoundry(script, score, request.styleStrategy, test.family, | - | ||||||||||||
1283 | QString(), styleKey, request.pixelSize, | - | ||||||||||||
1284 | pitch, &test, request.styleName); | - | ||||||||||||
1285 | } | - | ||||||||||||
1286 | - | |||||||||||||
1287 | if (newscore < score) { | - | ||||||||||||
1288 | result = x; | - | ||||||||||||
1289 | score = newscore; | - | ||||||||||||
1290 | *desc = test; | - | ||||||||||||
1291 | } | - | ||||||||||||
1292 | if (newscore < 10) // xlfd instead of FT... just accept it | - | ||||||||||||
1293 | break; | - | ||||||||||||
1294 | } | - | ||||||||||||
1295 | return result; | - | ||||||||||||
1296 | } | - | ||||||||||||
1297 | - | |||||||||||||
1298 | static QString styleStringHelper(int weight, QFont::Style style) | - | ||||||||||||
1299 | { | - | ||||||||||||
1300 | QString result; | - | ||||||||||||
1301 | if (weight > QFont::Normal) { | - | ||||||||||||
1302 | if (weight >= QFont::Black) | - | ||||||||||||
1303 | result = QCoreApplication::translate("QFontDatabase", "Black"); | - | ||||||||||||
1304 | else if (weight >= QFont::ExtraBold) | - | ||||||||||||
1305 | result = QCoreApplication::translate("QFontDatabase", "Extra Bold"); | - | ||||||||||||
1306 | else if (weight >= QFont::Bold) | - | ||||||||||||
1307 | result = QCoreApplication::translate("QFontDatabase", "Bold"); | - | ||||||||||||
1308 | else if (weight >= QFont::DemiBold) | - | ||||||||||||
1309 | result = QCoreApplication::translate("QFontDatabase", "Demi Bold"); | - | ||||||||||||
1310 | else if (weight >= QFont::Medium) | - | ||||||||||||
1311 | result = QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"); | - | ||||||||||||
1312 | } else { | - | ||||||||||||
1313 | if (weight <= QFont::Thin) | - | ||||||||||||
1314 | result = QCoreApplication::translate("QFontDatabase", "Thin"); | - | ||||||||||||
1315 | else if (weight <= QFont::ExtraLight) | - | ||||||||||||
1316 | result = QCoreApplication::translate("QFontDatabase", "Extra Light"); | - | ||||||||||||
1317 | else if (weight <= QFont::Light) | - | ||||||||||||
1318 | result = QCoreApplication::translate("QFontDatabase", "Light"); | - | ||||||||||||
1319 | } | - | ||||||||||||
1320 | - | |||||||||||||
1321 | if (style == QFont::StyleItalic) | - | ||||||||||||
1322 | result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Italic"); | - | ||||||||||||
1323 | else if (style == QFont::StyleOblique) | - | ||||||||||||
1324 | result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Oblique"); | - | ||||||||||||
1325 | - | |||||||||||||
1326 | if (result.isEmpty()) | - | ||||||||||||
1327 | result = QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"); | - | ||||||||||||
1328 | - | |||||||||||||
1329 | return result.simplified(); | - | ||||||||||||
1330 | } | - | ||||||||||||
1331 | - | |||||||||||||
1332 | /*! | - | ||||||||||||
1333 | Returns a string that describes the style of the \a font. For | - | ||||||||||||
1334 | example, "Bold Italic", "Bold", "Italic" or "Normal". An empty | - | ||||||||||||
1335 | string may be returned. | - | ||||||||||||
1336 | */ | - | ||||||||||||
1337 | QString QFontDatabase::styleString(const QFont &font) | - | ||||||||||||
1338 | { | - | ||||||||||||
1339 | return font.styleName().isEmpty() ? styleStringHelper(font.weight(), font.style()) | - | ||||||||||||
1340 | : font.styleName(); | - | ||||||||||||
1341 | } | - | ||||||||||||
1342 | - | |||||||||||||
1343 | /*! | - | ||||||||||||
1344 | Returns a string that describes the style of the \a fontInfo. For | - | ||||||||||||
1345 | example, "Bold Italic", "Bold", "Italic" or "Normal". An empty | - | ||||||||||||
1346 | string may be returned. | - | ||||||||||||
1347 | */ | - | ||||||||||||
1348 | QString QFontDatabase::styleString(const QFontInfo &fontInfo) | - | ||||||||||||
1349 | { | - | ||||||||||||
1350 | return fontInfo.styleName().isEmpty() ? styleStringHelper(fontInfo.weight(), fontInfo.style()) | - | ||||||||||||
1351 | : fontInfo.styleName(); | - | ||||||||||||
1352 | } | - | ||||||||||||
1353 | - | |||||||||||||
1354 | - | |||||||||||||
1355 | /*! | - | ||||||||||||
1356 | \class QFontDatabase | - | ||||||||||||
1357 | \threadsafe | - | ||||||||||||
1358 | \inmodule QtGui | - | ||||||||||||
1359 | - | |||||||||||||
1360 | \brief The QFontDatabase class provides information about the fonts available in the underlying window system. | - | ||||||||||||
1361 | - | |||||||||||||
1362 | \ingroup appearance | - | ||||||||||||
1363 | - | |||||||||||||
1364 | The most common uses of this class are to query the database for | - | ||||||||||||
1365 | the list of font families() and for the pointSizes() and styles() | - | ||||||||||||
1366 | that are available for each family. An alternative to pointSizes() | - | ||||||||||||
1367 | is smoothSizes() which returns the sizes at which a given family | - | ||||||||||||
1368 | and style will look attractive. | - | ||||||||||||
1369 | - | |||||||||||||
1370 | If the font family is available from two or more foundries the | - | ||||||||||||
1371 | foundry name is included in the family name; for example: | - | ||||||||||||
1372 | "Helvetica [Adobe]" and "Helvetica [Cronyx]". When you specify a | - | ||||||||||||
1373 | family, you can either use the old hyphenated "foundry-family" | - | ||||||||||||
1374 | format or the bracketed "family [foundry]" format; for example: | - | ||||||||||||
1375 | "Cronyx-Helvetica" or "Helvetica [Cronyx]". If the family has a | - | ||||||||||||
1376 | foundry it is always returned using the bracketed format, as is | - | ||||||||||||
1377 | the case with the value returned by families(). | - | ||||||||||||
1378 | - | |||||||||||||
1379 | The font() function returns a QFont given a family, style and | - | ||||||||||||
1380 | point size. | - | ||||||||||||
1381 | - | |||||||||||||
1382 | A family and style combination can be checked to see if it is | - | ||||||||||||
1383 | italic() or bold(), and to retrieve its weight(). Similarly we can | - | ||||||||||||
1384 | call isBitmapScalable(), isSmoothlyScalable(), isScalable() and | - | ||||||||||||
1385 | isFixedPitch(). | - | ||||||||||||
1386 | - | |||||||||||||
1387 | Use the styleString() to obtain a text version of a style. | - | ||||||||||||
1388 | - | |||||||||||||
1389 | The QFontDatabase class also supports some static functions, for | - | ||||||||||||
1390 | example, standardSizes(). You can retrieve the description of a | - | ||||||||||||
1391 | writing system using writingSystemName(), and a sample of | - | ||||||||||||
1392 | characters in a writing system with writingSystemSample(). | - | ||||||||||||
1393 | - | |||||||||||||
1394 | Example: | - | ||||||||||||
1395 | - | |||||||||||||
1396 | \snippet qfontdatabase/main.cpp 0 | - | ||||||||||||
1397 | \snippet qfontdatabase/main.cpp 1 | - | ||||||||||||
1398 | - | |||||||||||||
1399 | This example gets the list of font families, the list of | - | ||||||||||||
1400 | styles for each family, and the point sizes that are available for | - | ||||||||||||
1401 | each combination of family and style, displaying this information | - | ||||||||||||
1402 | in a tree view. | - | ||||||||||||
1403 | - | |||||||||||||
1404 | \sa QFont, QFontInfo, QFontMetrics, {Character Map Example} | - | ||||||||||||
1405 | */ | - | ||||||||||||
1406 | - | |||||||||||||
1407 | /*! | - | ||||||||||||
1408 | Creates a font database object. | - | ||||||||||||
1409 | */ | - | ||||||||||||
1410 | QFontDatabase::QFontDatabase() | - | ||||||||||||
1411 | { | - | ||||||||||||
1412 | if (Q_UNLIKELY(!qApp || !QGuiApplicationPrivate::platformIntegration())()))
| 0 | ||||||||||||
1413 | qFatal("QFontDatabase: Must construct a QGuiApplication before accessing QFontDatabase"); never executed: QMessageLogger(__FILE__, 1413, __PRETTY_FUNCTION__).fatal("QFontDatabase: Must construct a QGuiApplication before accessing QFontDatabase"); | 0 | ||||||||||||
1414 | - | |||||||||||||
1415 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1416 | createDatabase(); | - | ||||||||||||
1417 | d = privateDb(); | - | ||||||||||||
1418 | } never executed: end of block | 0 | ||||||||||||
1419 | - | |||||||||||||
1420 | /*! | - | ||||||||||||
1421 | \enum QFontDatabase::WritingSystem | - | ||||||||||||
1422 | - | |||||||||||||
1423 | \value Any | - | ||||||||||||
1424 | \value Latin | - | ||||||||||||
1425 | \value Greek | - | ||||||||||||
1426 | \value Cyrillic | - | ||||||||||||
1427 | \value Armenian | - | ||||||||||||
1428 | \value Hebrew | - | ||||||||||||
1429 | \value Arabic | - | ||||||||||||
1430 | \value Syriac | - | ||||||||||||
1431 | \value Thaana | - | ||||||||||||
1432 | \value Devanagari | - | ||||||||||||
1433 | \value Bengali | - | ||||||||||||
1434 | \value Gurmukhi | - | ||||||||||||
1435 | \value Gujarati | - | ||||||||||||
1436 | \value Oriya | - | ||||||||||||
1437 | \value Tamil | - | ||||||||||||
1438 | \value Telugu | - | ||||||||||||
1439 | \value Kannada | - | ||||||||||||
1440 | \value Malayalam | - | ||||||||||||
1441 | \value Sinhala | - | ||||||||||||
1442 | \value Thai | - | ||||||||||||
1443 | \value Lao | - | ||||||||||||
1444 | \value Tibetan | - | ||||||||||||
1445 | \value Myanmar | - | ||||||||||||
1446 | \value Georgian | - | ||||||||||||
1447 | \value Khmer | - | ||||||||||||
1448 | \value SimplifiedChinese | - | ||||||||||||
1449 | \value TraditionalChinese | - | ||||||||||||
1450 | \value Japanese | - | ||||||||||||
1451 | \value Korean | - | ||||||||||||
1452 | \value Vietnamese | - | ||||||||||||
1453 | \value Symbol | - | ||||||||||||
1454 | \value Other (the same as Symbol) | - | ||||||||||||
1455 | \value Ogham | - | ||||||||||||
1456 | \value Runic | - | ||||||||||||
1457 | \value Nko | - | ||||||||||||
1458 | - | |||||||||||||
1459 | \omitvalue WritingSystemsCount | - | ||||||||||||
1460 | */ | - | ||||||||||||
1461 | - | |||||||||||||
1462 | /*! | - | ||||||||||||
1463 | \enum QFontDatabase::SystemFont | - | ||||||||||||
1464 | - | |||||||||||||
1465 | \value GeneralFont The default system font. | - | ||||||||||||
1466 | \value FixedFont The fixed font that the system recommends. | - | ||||||||||||
1467 | \value TitleFont The system standard font for titles. | - | ||||||||||||
1468 | \value SmallestReadableFont The smallest readable system font. | - | ||||||||||||
1469 | - | |||||||||||||
1470 | \since 5.2 | - | ||||||||||||
1471 | */ | - | ||||||||||||
1472 | - | |||||||||||||
1473 | /*! | - | ||||||||||||
1474 | Returns a sorted list of the available writing systems. This is | - | ||||||||||||
1475 | list generated from information about all installed fonts on the | - | ||||||||||||
1476 | system. | - | ||||||||||||
1477 | - | |||||||||||||
1478 | \sa families() | - | ||||||||||||
1479 | */ | - | ||||||||||||
1480 | QList<QFontDatabase::WritingSystem> QFontDatabase::writingSystems() const | - | ||||||||||||
1481 | { | - | ||||||||||||
1482 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1483 | - | |||||||||||||
1484 | QT_PREPEND_NAMESPACE(load)(); | - | ||||||||||||
1485 | - | |||||||||||||
1486 | quint64 writingSystemsFound = 0; | - | ||||||||||||
1487 | Q_STATIC_ASSERT(WritingSystemsCount < 64); | - | ||||||||||||
1488 | - | |||||||||||||
1489 | for (int i = 0; i < d->count; ++i) { | - | ||||||||||||
1490 | QtFontFamily *family = d->families[i]; | - | ||||||||||||
1491 | family->ensurePopulated(); | - | ||||||||||||
1492 | - | |||||||||||||
1493 | if (family->count == 0) | - | ||||||||||||
1494 | continue; | - | ||||||||||||
1495 | for (uint x = Latin; x < uint(WritingSystemsCount); ++x) { | - | ||||||||||||
1496 | if (family->writingSystems[x] & QtFontFamily::Supported) | - | ||||||||||||
1497 | writingSystemsFound |= quint64(1) << x; | - | ||||||||||||
1498 | } | - | ||||||||||||
1499 | } | - | ||||||||||||
1500 | - | |||||||||||||
1501 | // mutex protection no longer needed - just working on local data now: | - | ||||||||||||
1502 | locker.unlock(); | - | ||||||||||||
1503 | - | |||||||||||||
1504 | QList<WritingSystem> list; | - | ||||||||||||
1505 | list.reserve(qPopulationCount(writingSystemsFound)); | - | ||||||||||||
1506 | for (uint x = Latin ; x < uint(WritingSystemsCount); ++x) { | - | ||||||||||||
1507 | if (writingSystemsFound & (quint64(1) << x)) | - | ||||||||||||
1508 | list.push_back(WritingSystem(x)); | - | ||||||||||||
1509 | } | - | ||||||||||||
1510 | return list; | - | ||||||||||||
1511 | } | - | ||||||||||||
1512 | - | |||||||||||||
1513 | - | |||||||||||||
1514 | /*! | - | ||||||||||||
1515 | Returns a sorted list of the writing systems supported by a given | - | ||||||||||||
1516 | font \a family. | - | ||||||||||||
1517 | - | |||||||||||||
1518 | \sa families() | - | ||||||||||||
1519 | */ | - | ||||||||||||
1520 | QList<QFontDatabase::WritingSystem> QFontDatabase::writingSystems(const QString &family) const | - | ||||||||||||
1521 | { | - | ||||||||||||
1522 | QString familyName, foundryName; | - | ||||||||||||
1523 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1524 | - | |||||||||||||
1525 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1526 | - | |||||||||||||
1527 | QT_PREPEND_NAMESPACE(load)(); | - | ||||||||||||
1528 | - | |||||||||||||
1529 | QList<WritingSystem> list; | - | ||||||||||||
1530 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1531 | if (!f || f->count == 0) | - | ||||||||||||
1532 | return list; | - | ||||||||||||
1533 | - | |||||||||||||
1534 | for (int x = Latin; x < WritingSystemsCount; ++x) { | - | ||||||||||||
1535 | const WritingSystem writingSystem = WritingSystem(x); | - | ||||||||||||
1536 | if (f->writingSystems[writingSystem] & QtFontFamily::Supported) | - | ||||||||||||
1537 | list.append(writingSystem); | - | ||||||||||||
1538 | } | - | ||||||||||||
1539 | return list; | - | ||||||||||||
1540 | } | - | ||||||||||||
1541 | - | |||||||||||||
1542 | - | |||||||||||||
1543 | /*! | - | ||||||||||||
1544 | Returns a sorted list of the available font families which support | - | ||||||||||||
1545 | the \a writingSystem. | - | ||||||||||||
1546 | - | |||||||||||||
1547 | If a family exists in several foundries, the returned name for | - | ||||||||||||
1548 | that font is in the form "family [foundry]". Examples: "Times | - | ||||||||||||
1549 | [Adobe]", "Times [Cronyx]", "Palatino". | - | ||||||||||||
1550 | - | |||||||||||||
1551 | \sa writingSystems() | - | ||||||||||||
1552 | */ | - | ||||||||||||
1553 | QStringList QFontDatabase::families(WritingSystem writingSystem) const | - | ||||||||||||
1554 | { | - | ||||||||||||
1555 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1556 | - | |||||||||||||
1557 | QT_PREPEND_NAMESPACE(load)(); | - | ||||||||||||
1558 | - | |||||||||||||
1559 | QStringList flist; | - | ||||||||||||
1560 | for (int i = 0; i < d->count; i++) { | - | ||||||||||||
1561 | QtFontFamily *f = d->families[i]; | - | ||||||||||||
1562 | if (f->populated && f->count == 0) | - | ||||||||||||
1563 | continue; | - | ||||||||||||
1564 | if (writingSystem != Any) { | - | ||||||||||||
1565 | f->ensurePopulated(); | - | ||||||||||||
1566 | if (f->writingSystems[writingSystem] != QtFontFamily::Supported) | - | ||||||||||||
1567 | continue; | - | ||||||||||||
1568 | } | - | ||||||||||||
1569 | if (!f->populated || f->count == 1) { | - | ||||||||||||
1570 | flist.append(f->name); | - | ||||||||||||
1571 | } else { | - | ||||||||||||
1572 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1573 | QString str = f->name; | - | ||||||||||||
1574 | QString foundry = f->foundries[j]->name; | - | ||||||||||||
1575 | if (!foundry.isEmpty()) { | - | ||||||||||||
1576 | str += QLatin1String(" ["); | - | ||||||||||||
1577 | str += foundry; | - | ||||||||||||
1578 | str += QLatin1Char(']'); | - | ||||||||||||
1579 | } | - | ||||||||||||
1580 | flist.append(str); | - | ||||||||||||
1581 | } | - | ||||||||||||
1582 | } | - | ||||||||||||
1583 | } | - | ||||||||||||
1584 | return flist; | - | ||||||||||||
1585 | } | - | ||||||||||||
1586 | - | |||||||||||||
1587 | /*! | - | ||||||||||||
1588 | Returns a list of the styles available for the font family \a | - | ||||||||||||
1589 | family. Some example styles: "Light", "Light Italic", "Bold", | - | ||||||||||||
1590 | "Oblique", "Demi". The list may be empty. | - | ||||||||||||
1591 | - | |||||||||||||
1592 | \sa families() | - | ||||||||||||
1593 | */ | - | ||||||||||||
1594 | QStringList QFontDatabase::styles(const QString &family) const | - | ||||||||||||
1595 | { | - | ||||||||||||
1596 | QString familyName, foundryName; | - | ||||||||||||
1597 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1598 | - | |||||||||||||
1599 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1600 | - | |||||||||||||
1601 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1602 | - | |||||||||||||
1603 | QStringList l; | - | ||||||||||||
1604 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1605 | if (!f) | - | ||||||||||||
1606 | return l; | - | ||||||||||||
1607 | - | |||||||||||||
1608 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
1609 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1610 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
1611 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1612 | for (int k = 0; k < foundry->count; k++) { | - | ||||||||||||
1613 | QtFontStyle::Key ke(foundry->styles[k]->key); | - | ||||||||||||
1614 | ke.stretch = 0; | - | ||||||||||||
1615 | allStyles.style(ke, foundry->styles[k]->styleName, true); | - | ||||||||||||
1616 | } | - | ||||||||||||
1617 | } | - | ||||||||||||
1618 | } | - | ||||||||||||
1619 | - | |||||||||||||
1620 | l.reserve(allStyles.count); | - | ||||||||||||
1621 | for (int i = 0; i < allStyles.count; i++) { | - | ||||||||||||
1622 | l.append(allStyles.styles[i]->styleName.isEmpty() ? | - | ||||||||||||
1623 | styleStringHelper(allStyles.styles[i]->key.weight, | - | ||||||||||||
1624 | (QFont::Style)allStyles.styles[i]->key.style) : | - | ||||||||||||
1625 | allStyles.styles[i]->styleName); | - | ||||||||||||
1626 | } | - | ||||||||||||
1627 | return l; | - | ||||||||||||
1628 | } | - | ||||||||||||
1629 | - | |||||||||||||
1630 | /*! | - | ||||||||||||
1631 | Returns \c true if the font that has family \a family and style \a | - | ||||||||||||
1632 | style is fixed pitch; otherwise returns \c false. | - | ||||||||||||
1633 | */ | - | ||||||||||||
1634 | - | |||||||||||||
1635 | bool QFontDatabase::isFixedPitch(const QString &family, | - | ||||||||||||
1636 | const QString &style) const | - | ||||||||||||
1637 | { | - | ||||||||||||
1638 | Q_UNUSED(style); | - | ||||||||||||
1639 | - | |||||||||||||
1640 | QString familyName, foundryName; | - | ||||||||||||
1641 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1642 | - | |||||||||||||
1643 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1644 | - | |||||||||||||
1645 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1646 | - | |||||||||||||
1647 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1648 | return (f && f->fixedPitch); | - | ||||||||||||
1649 | } | - | ||||||||||||
1650 | - | |||||||||||||
1651 | /*! | - | ||||||||||||
1652 | Returns \c true if the font that has family \a family and style \a | - | ||||||||||||
1653 | style is a scalable bitmap font; otherwise returns \c false. Scaling | - | ||||||||||||
1654 | a bitmap font usually produces an unattractive hardly readable | - | ||||||||||||
1655 | result, because the pixels of the font are scaled. If you need to | - | ||||||||||||
1656 | scale a bitmap font it is better to scale it to one of the fixed | - | ||||||||||||
1657 | sizes returned by smoothSizes(). | - | ||||||||||||
1658 | - | |||||||||||||
1659 | \sa isScalable(), isSmoothlyScalable() | - | ||||||||||||
1660 | */ | - | ||||||||||||
1661 | bool QFontDatabase::isBitmapScalable(const QString &family, | - | ||||||||||||
1662 | const QString &style) const | - | ||||||||||||
1663 | { | - | ||||||||||||
1664 | bool bitmapScalable = false; | - | ||||||||||||
1665 | QString familyName, foundryName; | - | ||||||||||||
1666 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1667 | - | |||||||||||||
1668 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1669 | - | |||||||||||||
1670 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1671 | - | |||||||||||||
1672 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1673 | if (!f) return bitmapScalable; | - | ||||||||||||
1674 | - | |||||||||||||
1675 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
1676 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1677 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
1678 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1679 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
1680 | if ((style.isEmpty() || | - | ||||||||||||
1681 | foundry->styles[k]->styleName == style || | - | ||||||||||||
1682 | foundry->styles[k]->key == styleKey) | - | ||||||||||||
1683 | && foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) { | - | ||||||||||||
1684 | bitmapScalable = true; | - | ||||||||||||
1685 | goto end; | - | ||||||||||||
1686 | } | - | ||||||||||||
1687 | } | - | ||||||||||||
1688 | } | - | ||||||||||||
1689 | end: | - | ||||||||||||
1690 | return bitmapScalable; | - | ||||||||||||
1691 | } | - | ||||||||||||
1692 | - | |||||||||||||
1693 | - | |||||||||||||
1694 | /*! | - | ||||||||||||
1695 | Returns \c true if the font that has family \a family and style \a | - | ||||||||||||
1696 | style is smoothly scalable; otherwise returns \c false. If this | - | ||||||||||||
1697 | function returns \c true, it's safe to scale this font to any size, | - | ||||||||||||
1698 | and the result will always look attractive. | - | ||||||||||||
1699 | - | |||||||||||||
1700 | \sa isScalable(), isBitmapScalable() | - | ||||||||||||
1701 | */ | - | ||||||||||||
1702 | bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &style) const | - | ||||||||||||
1703 | { | - | ||||||||||||
1704 | bool smoothScalable = false; | - | ||||||||||||
1705 | QString familyName, foundryName; | - | ||||||||||||
1706 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1707 | - | |||||||||||||
1708 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1709 | - | |||||||||||||
1710 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1711 | - | |||||||||||||
1712 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1713 | if (!f) { | - | ||||||||||||
1714 | for (int i = 0; i < d->count; i++) { | - | ||||||||||||
1715 | if (d->families[i]->matchesFamilyName(familyName)) { | - | ||||||||||||
1716 | f = d->families[i]; | - | ||||||||||||
1717 | f->ensurePopulated(); | - | ||||||||||||
1718 | break; | - | ||||||||||||
1719 | } | - | ||||||||||||
1720 | } | - | ||||||||||||
1721 | } | - | ||||||||||||
1722 | if (!f) return smoothScalable; | - | ||||||||||||
1723 | - | |||||||||||||
1724 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
1725 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1726 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
1727 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1728 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
1729 | if ((style.isEmpty() || | - | ||||||||||||
1730 | foundry->styles[k]->styleName == style || | - | ||||||||||||
1731 | foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) { | - | ||||||||||||
1732 | smoothScalable = true; | - | ||||||||||||
1733 | goto end; | - | ||||||||||||
1734 | } | - | ||||||||||||
1735 | } | - | ||||||||||||
1736 | } | - | ||||||||||||
1737 | end: | - | ||||||||||||
1738 | return smoothScalable; | - | ||||||||||||
1739 | } | - | ||||||||||||
1740 | - | |||||||||||||
1741 | /*! | - | ||||||||||||
1742 | Returns \c true if the font that has family \a family and style \a | - | ||||||||||||
1743 | style is scalable; otherwise returns \c false. | - | ||||||||||||
1744 | - | |||||||||||||
1745 | \sa isBitmapScalable(), isSmoothlyScalable() | - | ||||||||||||
1746 | */ | - | ||||||||||||
1747 | bool QFontDatabase::isScalable(const QString &family, | - | ||||||||||||
1748 | const QString &style) const | - | ||||||||||||
1749 | { | - | ||||||||||||
1750 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1751 | if (isSmoothlyScalable(family, style)) | - | ||||||||||||
1752 | return true; | - | ||||||||||||
1753 | return isBitmapScalable(family, style); | - | ||||||||||||
1754 | } | - | ||||||||||||
1755 | - | |||||||||||||
1756 | - | |||||||||||||
1757 | /*! | - | ||||||||||||
1758 | Returns a list of the point sizes available for the font that has | - | ||||||||||||
1759 | family \a family and style \a styleName. The list may be empty. | - | ||||||||||||
1760 | - | |||||||||||||
1761 | \sa smoothSizes(), standardSizes() | - | ||||||||||||
1762 | */ | - | ||||||||||||
1763 | QList<int> QFontDatabase::pointSizes(const QString &family, | - | ||||||||||||
1764 | const QString &styleName) | - | ||||||||||||
1765 | { | - | ||||||||||||
1766 | if (QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()) | - | ||||||||||||
1767 | return standardSizes(); | - | ||||||||||||
1768 | - | |||||||||||||
1769 | bool smoothScalable = false; | - | ||||||||||||
1770 | QString familyName, foundryName; | - | ||||||||||||
1771 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1772 | - | |||||||||||||
1773 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1774 | - | |||||||||||||
1775 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1776 | - | |||||||||||||
1777 | QList<int> sizes; | - | ||||||||||||
1778 | - | |||||||||||||
1779 | QtFontFamily *fam = d->family(familyName); | - | ||||||||||||
1780 | if (!fam) return sizes; | - | ||||||||||||
1781 | - | |||||||||||||
1782 | - | |||||||||||||
1783 | const int dpi = qt_defaultDpiY(); // embedded | - | ||||||||||||
1784 | - | |||||||||||||
1785 | QtFontStyle::Key styleKey(styleName); | - | ||||||||||||
1786 | for (int j = 0; j < fam->count; j++) { | - | ||||||||||||
1787 | QtFontFoundry *foundry = fam->foundries[j]; | - | ||||||||||||
1788 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1789 | QtFontStyle *style = foundry->style(styleKey, styleName); | - | ||||||||||||
1790 | if (!style) continue; | - | ||||||||||||
1791 | - | |||||||||||||
1792 | if (style->smoothScalable) { | - | ||||||||||||
1793 | smoothScalable = true; | - | ||||||||||||
1794 | goto end; | - | ||||||||||||
1795 | } | - | ||||||||||||
1796 | for (int l = 0; l < style->count; l++) { | - | ||||||||||||
1797 | const QtFontSize *size = style->pixelSizes + l; | - | ||||||||||||
1798 | - | |||||||||||||
1799 | if (size->pixelSize != 0 && size->pixelSize != SMOOTH_SCALABLE) { | - | ||||||||||||
1800 | const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); | - | ||||||||||||
1801 | if (! sizes.contains(pointSize)) | - | ||||||||||||
1802 | sizes.append(pointSize); | - | ||||||||||||
1803 | } | - | ||||||||||||
1804 | } | - | ||||||||||||
1805 | } | - | ||||||||||||
1806 | } | - | ||||||||||||
1807 | end: | - | ||||||||||||
1808 | if (smoothScalable) | - | ||||||||||||
1809 | return standardSizes(); | - | ||||||||||||
1810 | - | |||||||||||||
1811 | std::sort(sizes.begin(), sizes.end()); | - | ||||||||||||
1812 | return sizes; | - | ||||||||||||
1813 | } | - | ||||||||||||
1814 | - | |||||||||||||
1815 | /*! | - | ||||||||||||
1816 | Returns a QFont object that has family \a family, style \a style | - | ||||||||||||
1817 | and point size \a pointSize. If no matching font could be created, | - | ||||||||||||
1818 | a QFont object that uses the application's default font is | - | ||||||||||||
1819 | returned. | - | ||||||||||||
1820 | */ | - | ||||||||||||
1821 | QFont QFontDatabase::font(const QString &family, const QString &style, | - | ||||||||||||
1822 | int pointSize) const | - | ||||||||||||
1823 | { | - | ||||||||||||
1824 | QString familyName, foundryName; | - | ||||||||||||
1825 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1826 | - | |||||||||||||
1827 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1828 | - | |||||||||||||
1829 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1830 | - | |||||||||||||
1831 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
1832 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1833 | if (!f) return QGuiApplication::font(); | - | ||||||||||||
1834 | - | |||||||||||||
1835 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1836 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
1837 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1838 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
1839 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
1840 | } | - | ||||||||||||
1841 | } | - | ||||||||||||
1842 | - | |||||||||||||
1843 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
1844 | QtFontStyle *s = bestStyle(&allStyles, styleKey, style); | - | ||||||||||||
1845 | - | |||||||||||||
1846 | if (!s) // no styles found? | - | ||||||||||||
1847 | return QGuiApplication::font(); | - | ||||||||||||
1848 | - | |||||||||||||
1849 | QFont fnt(family, pointSize, s->key.weight); | - | ||||||||||||
1850 | fnt.setStyle((QFont::Style)s->key.style); | - | ||||||||||||
1851 | if (!s->styleName.isEmpty()) | - | ||||||||||||
1852 | fnt.setStyleName(s->styleName); | - | ||||||||||||
1853 | return fnt; | - | ||||||||||||
1854 | } | - | ||||||||||||
1855 | - | |||||||||||||
1856 | - | |||||||||||||
1857 | /*! | - | ||||||||||||
1858 | Returns the point sizes of a font that has family \a family and | - | ||||||||||||
1859 | style \a styleName that will look attractive. The list may be empty. | - | ||||||||||||
1860 | For non-scalable fonts and bitmap scalable fonts, this function | - | ||||||||||||
1861 | is equivalent to pointSizes(). | - | ||||||||||||
1862 | - | |||||||||||||
1863 | \sa pointSizes(), standardSizes() | - | ||||||||||||
1864 | */ | - | ||||||||||||
1865 | QList<int> QFontDatabase::smoothSizes(const QString &family, | - | ||||||||||||
1866 | const QString &styleName) | - | ||||||||||||
1867 | { | - | ||||||||||||
1868 | if (QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()) | - | ||||||||||||
1869 | return standardSizes(); | - | ||||||||||||
1870 | - | |||||||||||||
1871 | bool smoothScalable = false; | - | ||||||||||||
1872 | QString familyName, foundryName; | - | ||||||||||||
1873 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1874 | - | |||||||||||||
1875 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1876 | - | |||||||||||||
1877 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1878 | - | |||||||||||||
1879 | QList<int> sizes; | - | ||||||||||||
1880 | - | |||||||||||||
1881 | QtFontFamily *fam = d->family(familyName); | - | ||||||||||||
1882 | if (!fam) | - | ||||||||||||
1883 | return sizes; | - | ||||||||||||
1884 | - | |||||||||||||
1885 | const int dpi = qt_defaultDpiY(); // embedded | - | ||||||||||||
1886 | - | |||||||||||||
1887 | QtFontStyle::Key styleKey(styleName); | - | ||||||||||||
1888 | for (int j = 0; j < fam->count; j++) { | - | ||||||||||||
1889 | QtFontFoundry *foundry = fam->foundries[j]; | - | ||||||||||||
1890 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1891 | QtFontStyle *style = foundry->style(styleKey, styleName); | - | ||||||||||||
1892 | if (!style) continue; | - | ||||||||||||
1893 | - | |||||||||||||
1894 | if (style->smoothScalable) { | - | ||||||||||||
1895 | smoothScalable = true; | - | ||||||||||||
1896 | goto end; | - | ||||||||||||
1897 | } | - | ||||||||||||
1898 | for (int l = 0; l < style->count; l++) { | - | ||||||||||||
1899 | const QtFontSize *size = style->pixelSizes + l; | - | ||||||||||||
1900 | - | |||||||||||||
1901 | if (size->pixelSize != 0 && size->pixelSize != SMOOTH_SCALABLE) { | - | ||||||||||||
1902 | const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); | - | ||||||||||||
1903 | if (! sizes.contains(pointSize)) | - | ||||||||||||
1904 | sizes.append(pointSize); | - | ||||||||||||
1905 | } | - | ||||||||||||
1906 | } | - | ||||||||||||
1907 | } | - | ||||||||||||
1908 | } | - | ||||||||||||
1909 | end: | - | ||||||||||||
1910 | if (smoothScalable) | - | ||||||||||||
1911 | return QFontDatabase::standardSizes(); | - | ||||||||||||
1912 | - | |||||||||||||
1913 | std::sort(sizes.begin(), sizes.end()); | - | ||||||||||||
1914 | return sizes; | - | ||||||||||||
1915 | } | - | ||||||||||||
1916 | - | |||||||||||||
1917 | - | |||||||||||||
1918 | /*! | - | ||||||||||||
1919 | Returns a list of standard font sizes. | - | ||||||||||||
1920 | - | |||||||||||||
1921 | \sa smoothSizes(), pointSizes() | - | ||||||||||||
1922 | */ | - | ||||||||||||
1923 | QList<int> QFontDatabase::standardSizes() | - | ||||||||||||
1924 | { | - | ||||||||||||
1925 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->standardSizes(); | - | ||||||||||||
1926 | } | - | ||||||||||||
1927 | - | |||||||||||||
1928 | - | |||||||||||||
1929 | /*! | - | ||||||||||||
1930 | Returns \c true if the font that has family \a family and style \a | - | ||||||||||||
1931 | style is italic; otherwise returns \c false. | - | ||||||||||||
1932 | - | |||||||||||||
1933 | \sa weight(), bold() | - | ||||||||||||
1934 | */ | - | ||||||||||||
1935 | bool QFontDatabase::italic(const QString &family, const QString &style) const | - | ||||||||||||
1936 | { | - | ||||||||||||
1937 | QString familyName, foundryName; | - | ||||||||||||
1938 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1939 | - | |||||||||||||
1940 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1941 | - | |||||||||||||
1942 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1943 | - | |||||||||||||
1944 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
1945 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1946 | if (!f) return false; | - | ||||||||||||
1947 | - | |||||||||||||
1948 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1949 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
1950 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1951 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
1952 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
1953 | } | - | ||||||||||||
1954 | } | - | ||||||||||||
1955 | - | |||||||||||||
1956 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
1957 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||
1958 | return s && s->key.style == QFont::StyleItalic; | - | ||||||||||||
1959 | } | - | ||||||||||||
1960 | - | |||||||||||||
1961 | - | |||||||||||||
1962 | /*! | - | ||||||||||||
1963 | Returns \c true if the font that has family \a family and style \a | - | ||||||||||||
1964 | style is bold; otherwise returns \c false. | - | ||||||||||||
1965 | - | |||||||||||||
1966 | \sa italic(), weight() | - | ||||||||||||
1967 | */ | - | ||||||||||||
1968 | bool QFontDatabase::bold(const QString &family, | - | ||||||||||||
1969 | const QString &style) const | - | ||||||||||||
1970 | { | - | ||||||||||||
1971 | QString familyName, foundryName; | - | ||||||||||||
1972 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
1973 | - | |||||||||||||
1974 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
1975 | - | |||||||||||||
1976 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
1977 | - | |||||||||||||
1978 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
1979 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
1980 | if (!f) return false; | - | ||||||||||||
1981 | - | |||||||||||||
1982 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
1983 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
1984 | if (foundryName.isEmpty() || | - | ||||||||||||
1985 | foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
1986 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
1987 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
1988 | } | - | ||||||||||||
1989 | } | - | ||||||||||||
1990 | - | |||||||||||||
1991 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
1992 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||
1993 | return s && s->key.weight >= QFont::Bold; | - | ||||||||||||
1994 | } | - | ||||||||||||
1995 | - | |||||||||||||
1996 | - | |||||||||||||
1997 | /*! | - | ||||||||||||
1998 | Returns the weight of the font that has family \a family and style | - | ||||||||||||
1999 | \a style. If there is no such family and style combination, | - | ||||||||||||
2000 | returns -1. | - | ||||||||||||
2001 | - | |||||||||||||
2002 | \sa italic(), bold() | - | ||||||||||||
2003 | */ | - | ||||||||||||
2004 | int QFontDatabase::weight(const QString &family, | - | ||||||||||||
2005 | const QString &style) const | - | ||||||||||||
2006 | { | - | ||||||||||||
2007 | QString familyName, foundryName; | - | ||||||||||||
2008 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
2009 | - | |||||||||||||
2010 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2011 | - | |||||||||||||
2012 | QT_PREPEND_NAMESPACE(load)(familyName); | - | ||||||||||||
2013 | - | |||||||||||||
2014 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
2015 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
2016 | if (!f) return -1; | - | ||||||||||||
2017 | - | |||||||||||||
2018 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
2019 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
2020 | if (foundryName.isEmpty() || | - | ||||||||||||
2021 | foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
2022 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
2023 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
2024 | } | - | ||||||||||||
2025 | } | - | ||||||||||||
2026 | - | |||||||||||||
2027 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
2028 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||
2029 | return s ? s->key.weight : -1; | - | ||||||||||||
2030 | } | - | ||||||||||||
2031 | - | |||||||||||||
2032 | - | |||||||||||||
2033 | /*! \internal */ | - | ||||||||||||
2034 | bool QFontDatabase::hasFamily(const QString &family) const | - | ||||||||||||
2035 | { | - | ||||||||||||
2036 | QString parsedFamily, foundry; | - | ||||||||||||
2037 | parseFontName(family, foundry, parsedFamily); | - | ||||||||||||
2038 | const QString familyAlias = resolveFontFamilyAlias(parsedFamily); | - | ||||||||||||
2039 | return families().contains(familyAlias, Qt::CaseInsensitive); | - | ||||||||||||
2040 | } | - | ||||||||||||
2041 | - | |||||||||||||
2042 | - | |||||||||||||
2043 | /*! | - | ||||||||||||
2044 | \since 5.5 | - | ||||||||||||
2045 | - | |||||||||||||
2046 | Returns \c true if and only if the \a family font family is private. | - | ||||||||||||
2047 | - | |||||||||||||
2048 | This happens, for instance, on \macos and iOS, where the system UI fonts are not | - | ||||||||||||
2049 | accessible to the user. For completeness, QFontDatabase::families() returns all | - | ||||||||||||
2050 | font families, including the private ones. You should use this function if you | - | ||||||||||||
2051 | are developing a font selection control in order to keep private fonts hidden. | - | ||||||||||||
2052 | - | |||||||||||||
2053 | \sa families() | - | ||||||||||||
2054 | */ | - | ||||||||||||
2055 | bool QFontDatabase::isPrivateFamily(const QString &family) const | - | ||||||||||||
2056 | { | - | ||||||||||||
2057 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->isPrivateFontFamily(family); | - | ||||||||||||
2058 | } | - | ||||||||||||
2059 | - | |||||||||||||
2060 | - | |||||||||||||
2061 | /*! | - | ||||||||||||
2062 | Returns the names the \a writingSystem (e.g. for displaying to the | - | ||||||||||||
2063 | user in a dialog). | - | ||||||||||||
2064 | */ | - | ||||||||||||
2065 | QString QFontDatabase::writingSystemName(WritingSystem writingSystem) | - | ||||||||||||
2066 | { | - | ||||||||||||
2067 | const char *name = 0; | - | ||||||||||||
2068 | switch (writingSystem) { | - | ||||||||||||
2069 | case Any: | - | ||||||||||||
2070 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Any"); | - | ||||||||||||
2071 | break; | - | ||||||||||||
2072 | case Latin: | - | ||||||||||||
2073 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Latin"); | - | ||||||||||||
2074 | break; | - | ||||||||||||
2075 | case Greek: | - | ||||||||||||
2076 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Greek"); | - | ||||||||||||
2077 | break; | - | ||||||||||||
2078 | case Cyrillic: | - | ||||||||||||
2079 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Cyrillic"); | - | ||||||||||||
2080 | break; | - | ||||||||||||
2081 | case Armenian: | - | ||||||||||||
2082 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Armenian"); | - | ||||||||||||
2083 | break; | - | ||||||||||||
2084 | case Hebrew: | - | ||||||||||||
2085 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Hebrew"); | - | ||||||||||||
2086 | break; | - | ||||||||||||
2087 | case Arabic: | - | ||||||||||||
2088 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Arabic"); | - | ||||||||||||
2089 | break; | - | ||||||||||||
2090 | case Syriac: | - | ||||||||||||
2091 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Syriac"); | - | ||||||||||||
2092 | break; | - | ||||||||||||
2093 | case Thaana: | - | ||||||||||||
2094 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Thaana"); | - | ||||||||||||
2095 | break; | - | ||||||||||||
2096 | case Devanagari: | - | ||||||||||||
2097 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Devanagari"); | - | ||||||||||||
2098 | break; | - | ||||||||||||
2099 | case Bengali: | - | ||||||||||||
2100 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Bengali"); | - | ||||||||||||
2101 | break; | - | ||||||||||||
2102 | case Gurmukhi: | - | ||||||||||||
2103 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Gurmukhi"); | - | ||||||||||||
2104 | break; | - | ||||||||||||
2105 | case Gujarati: | - | ||||||||||||
2106 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Gujarati"); | - | ||||||||||||
2107 | break; | - | ||||||||||||
2108 | case Oriya: | - | ||||||||||||
2109 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Oriya"); | - | ||||||||||||
2110 | break; | - | ||||||||||||
2111 | case Tamil: | - | ||||||||||||
2112 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Tamil"); | - | ||||||||||||
2113 | break; | - | ||||||||||||
2114 | case Telugu: | - | ||||||||||||
2115 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Telugu"); | - | ||||||||||||
2116 | break; | - | ||||||||||||
2117 | case Kannada: | - | ||||||||||||
2118 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Kannada"); | - | ||||||||||||
2119 | break; | - | ||||||||||||
2120 | case Malayalam: | - | ||||||||||||
2121 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Malayalam"); | - | ||||||||||||
2122 | break; | - | ||||||||||||
2123 | case Sinhala: | - | ||||||||||||
2124 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Sinhala"); | - | ||||||||||||
2125 | break; | - | ||||||||||||
2126 | case Thai: | - | ||||||||||||
2127 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Thai"); | - | ||||||||||||
2128 | break; | - | ||||||||||||
2129 | case Lao: | - | ||||||||||||
2130 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Lao"); | - | ||||||||||||
2131 | break; | - | ||||||||||||
2132 | case Tibetan: | - | ||||||||||||
2133 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Tibetan"); | - | ||||||||||||
2134 | break; | - | ||||||||||||
2135 | case Myanmar: | - | ||||||||||||
2136 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Myanmar"); | - | ||||||||||||
2137 | break; | - | ||||||||||||
2138 | case Georgian: | - | ||||||||||||
2139 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Georgian"); | - | ||||||||||||
2140 | break; | - | ||||||||||||
2141 | case Khmer: | - | ||||||||||||
2142 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Khmer"); | - | ||||||||||||
2143 | break; | - | ||||||||||||
2144 | case SimplifiedChinese: | - | ||||||||||||
2145 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Simplified Chinese"); | - | ||||||||||||
2146 | break; | - | ||||||||||||
2147 | case TraditionalChinese: | - | ||||||||||||
2148 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Traditional Chinese"); | - | ||||||||||||
2149 | break; | - | ||||||||||||
2150 | case Japanese: | - | ||||||||||||
2151 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Japanese"); | - | ||||||||||||
2152 | break; | - | ||||||||||||
2153 | case Korean: | - | ||||||||||||
2154 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Korean"); | - | ||||||||||||
2155 | break; | - | ||||||||||||
2156 | case Vietnamese: | - | ||||||||||||
2157 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Vietnamese"); | - | ||||||||||||
2158 | break; | - | ||||||||||||
2159 | case Symbol: | - | ||||||||||||
2160 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Symbol"); | - | ||||||||||||
2161 | break; | - | ||||||||||||
2162 | case Ogham: | - | ||||||||||||
2163 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Ogham"); | - | ||||||||||||
2164 | break; | - | ||||||||||||
2165 | case Runic: | - | ||||||||||||
2166 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Runic"); | - | ||||||||||||
2167 | break; | - | ||||||||||||
2168 | case Nko: | - | ||||||||||||
2169 | name = QT_TRANSLATE_NOOP("QFontDatabase", "N'Ko"); | - | ||||||||||||
2170 | break; | - | ||||||||||||
2171 | default: | - | ||||||||||||
2172 | Q_ASSERT_X(false, "QFontDatabase::writingSystemName", "invalid 'writingSystem' parameter"); | - | ||||||||||||
2173 | break; | - | ||||||||||||
2174 | } | - | ||||||||||||
2175 | return QCoreApplication::translate("QFontDatabase", name); | - | ||||||||||||
2176 | } | - | ||||||||||||
2177 | - | |||||||||||||
2178 | - | |||||||||||||
2179 | /*! | - | ||||||||||||
2180 | Returns a string with sample characters from \a writingSystem. | - | ||||||||||||
2181 | */ | - | ||||||||||||
2182 | QString QFontDatabase::writingSystemSample(WritingSystem writingSystem) | - | ||||||||||||
2183 | { | - | ||||||||||||
2184 | QString sample; | - | ||||||||||||
2185 | switch (writingSystem) { | - | ||||||||||||
2186 | case Any: | - | ||||||||||||
2187 | case Symbol: | - | ||||||||||||
2188 | // show only ascii characters | - | ||||||||||||
2189 | sample += QLatin1String("AaBbzZ"); | - | ||||||||||||
2190 | break; | - | ||||||||||||
2191 | case Latin: | - | ||||||||||||
2192 | // This is cheating... we only show latin-1 characters so that we don't | - | ||||||||||||
2193 | // end up loading lots of fonts - at least on X11... | - | ||||||||||||
2194 | sample = QLatin1String("Aa"); | - | ||||||||||||
2195 | sample += QChar(0x00C3); | - | ||||||||||||
2196 | sample += QChar(0x00E1); | - | ||||||||||||
2197 | sample += QLatin1String("Zz"); | - | ||||||||||||
2198 | break; | - | ||||||||||||
2199 | case Greek: | - | ||||||||||||
2200 | sample += QChar(0x0393); | - | ||||||||||||
2201 | sample += QChar(0x03B1); | - | ||||||||||||
2202 | sample += QChar(0x03A9); | - | ||||||||||||
2203 | sample += QChar(0x03C9); | - | ||||||||||||
2204 | break; | - | ||||||||||||
2205 | case Cyrillic: | - | ||||||||||||
2206 | sample += QChar(0x0414); | - | ||||||||||||
2207 | sample += QChar(0x0434); | - | ||||||||||||
2208 | sample += QChar(0x0436); | - | ||||||||||||
2209 | sample += QChar(0x044f); | - | ||||||||||||
2210 | break; | - | ||||||||||||
2211 | case Armenian: | - | ||||||||||||
2212 | sample += QChar(0x053f); | - | ||||||||||||
2213 | sample += QChar(0x054f); | - | ||||||||||||
2214 | sample += QChar(0x056f); | - | ||||||||||||
2215 | sample += QChar(0x057f); | - | ||||||||||||
2216 | break; | - | ||||||||||||
2217 | case Hebrew: | - | ||||||||||||
2218 | sample += QChar(0x05D0); | - | ||||||||||||
2219 | sample += QChar(0x05D1); | - | ||||||||||||
2220 | sample += QChar(0x05D2); | - | ||||||||||||
2221 | sample += QChar(0x05D3); | - | ||||||||||||
2222 | break; | - | ||||||||||||
2223 | case Arabic: | - | ||||||||||||
2224 | sample += QChar(0x0628); | - | ||||||||||||
2225 | sample += QChar(0x0629); | - | ||||||||||||
2226 | sample += QChar(0x062A); | - | ||||||||||||
2227 | sample += QChar(0x063A); | - | ||||||||||||
2228 | break; | - | ||||||||||||
2229 | case Syriac: | - | ||||||||||||
2230 | sample += QChar(0x0715); | - | ||||||||||||
2231 | sample += QChar(0x0725); | - | ||||||||||||
2232 | sample += QChar(0x0716); | - | ||||||||||||
2233 | sample += QChar(0x0726); | - | ||||||||||||
2234 | break; | - | ||||||||||||
2235 | case Thaana: | - | ||||||||||||
2236 | sample += QChar(0x0784); | - | ||||||||||||
2237 | sample += QChar(0x0794); | - | ||||||||||||
2238 | sample += QChar(0x078c); | - | ||||||||||||
2239 | sample += QChar(0x078d); | - | ||||||||||||
2240 | break; | - | ||||||||||||
2241 | case Devanagari: | - | ||||||||||||
2242 | sample += QChar(0x0905); | - | ||||||||||||
2243 | sample += QChar(0x0915); | - | ||||||||||||
2244 | sample += QChar(0x0925); | - | ||||||||||||
2245 | sample += QChar(0x0935); | - | ||||||||||||
2246 | break; | - | ||||||||||||
2247 | case Bengali: | - | ||||||||||||
2248 | sample += QChar(0x0986); | - | ||||||||||||
2249 | sample += QChar(0x0996); | - | ||||||||||||
2250 | sample += QChar(0x09a6); | - | ||||||||||||
2251 | sample += QChar(0x09b6); | - | ||||||||||||
2252 | break; | - | ||||||||||||
2253 | case Gurmukhi: | - | ||||||||||||
2254 | sample += QChar(0x0a05); | - | ||||||||||||
2255 | sample += QChar(0x0a15); | - | ||||||||||||
2256 | sample += QChar(0x0a25); | - | ||||||||||||
2257 | sample += QChar(0x0a35); | - | ||||||||||||
2258 | break; | - | ||||||||||||
2259 | case Gujarati: | - | ||||||||||||
2260 | sample += QChar(0x0a85); | - | ||||||||||||
2261 | sample += QChar(0x0a95); | - | ||||||||||||
2262 | sample += QChar(0x0aa5); | - | ||||||||||||
2263 | sample += QChar(0x0ab5); | - | ||||||||||||
2264 | break; | - | ||||||||||||
2265 | case Oriya: | - | ||||||||||||
2266 | sample += QChar(0x0b06); | - | ||||||||||||
2267 | sample += QChar(0x0b16); | - | ||||||||||||
2268 | sample += QChar(0x0b2b); | - | ||||||||||||
2269 | sample += QChar(0x0b36); | - | ||||||||||||
2270 | break; | - | ||||||||||||
2271 | case Tamil: | - | ||||||||||||
2272 | sample += QChar(0x0b89); | - | ||||||||||||
2273 | sample += QChar(0x0b99); | - | ||||||||||||
2274 | sample += QChar(0x0ba9); | - | ||||||||||||
2275 | sample += QChar(0x0bb9); | - | ||||||||||||
2276 | break; | - | ||||||||||||
2277 | case Telugu: | - | ||||||||||||
2278 | sample += QChar(0x0c05); | - | ||||||||||||
2279 | sample += QChar(0x0c15); | - | ||||||||||||
2280 | sample += QChar(0x0c25); | - | ||||||||||||
2281 | sample += QChar(0x0c35); | - | ||||||||||||
2282 | break; | - | ||||||||||||
2283 | case Kannada: | - | ||||||||||||
2284 | sample += QChar(0x0c85); | - | ||||||||||||
2285 | sample += QChar(0x0c95); | - | ||||||||||||
2286 | sample += QChar(0x0ca5); | - | ||||||||||||
2287 | sample += QChar(0x0cb5); | - | ||||||||||||
2288 | break; | - | ||||||||||||
2289 | case Malayalam: | - | ||||||||||||
2290 | sample += QChar(0x0d05); | - | ||||||||||||
2291 | sample += QChar(0x0d15); | - | ||||||||||||
2292 | sample += QChar(0x0d25); | - | ||||||||||||
2293 | sample += QChar(0x0d35); | - | ||||||||||||
2294 | break; | - | ||||||||||||
2295 | case Sinhala: | - | ||||||||||||
2296 | sample += QChar(0x0d90); | - | ||||||||||||
2297 | sample += QChar(0x0da0); | - | ||||||||||||
2298 | sample += QChar(0x0db0); | - | ||||||||||||
2299 | sample += QChar(0x0dc0); | - | ||||||||||||
2300 | break; | - | ||||||||||||
2301 | case Thai: | - | ||||||||||||
2302 | sample += QChar(0x0e02); | - | ||||||||||||
2303 | sample += QChar(0x0e12); | - | ||||||||||||
2304 | sample += QChar(0x0e22); | - | ||||||||||||
2305 | sample += QChar(0x0e32); | - | ||||||||||||
2306 | break; | - | ||||||||||||
2307 | case Lao: | - | ||||||||||||
2308 | sample += QChar(0x0e8d); | - | ||||||||||||
2309 | sample += QChar(0x0e9d); | - | ||||||||||||
2310 | sample += QChar(0x0ead); | - | ||||||||||||
2311 | sample += QChar(0x0ebd); | - | ||||||||||||
2312 | break; | - | ||||||||||||
2313 | case Tibetan: | - | ||||||||||||
2314 | sample += QChar(0x0f00); | - | ||||||||||||
2315 | sample += QChar(0x0f01); | - | ||||||||||||
2316 | sample += QChar(0x0f02); | - | ||||||||||||
2317 | sample += QChar(0x0f03); | - | ||||||||||||
2318 | break; | - | ||||||||||||
2319 | case Myanmar: | - | ||||||||||||
2320 | sample += QChar(0x1000); | - | ||||||||||||
2321 | sample += QChar(0x1001); | - | ||||||||||||
2322 | sample += QChar(0x1002); | - | ||||||||||||
2323 | sample += QChar(0x1003); | - | ||||||||||||
2324 | break; | - | ||||||||||||
2325 | case Georgian: | - | ||||||||||||
2326 | sample += QChar(0x10a0); | - | ||||||||||||
2327 | sample += QChar(0x10b0); | - | ||||||||||||
2328 | sample += QChar(0x10c0); | - | ||||||||||||
2329 | sample += QChar(0x10d0); | - | ||||||||||||
2330 | break; | - | ||||||||||||
2331 | case Khmer: | - | ||||||||||||
2332 | sample += QChar(0x1780); | - | ||||||||||||
2333 | sample += QChar(0x1790); | - | ||||||||||||
2334 | sample += QChar(0x17b0); | - | ||||||||||||
2335 | sample += QChar(0x17c0); | - | ||||||||||||
2336 | break; | - | ||||||||||||
2337 | case SimplifiedChinese: | - | ||||||||||||
2338 | sample += QChar(0x4e2d); | - | ||||||||||||
2339 | sample += QChar(0x6587); | - | ||||||||||||
2340 | sample += QChar(0x8303); | - | ||||||||||||
2341 | sample += QChar(0x4f8b); | - | ||||||||||||
2342 | break; | - | ||||||||||||
2343 | case TraditionalChinese: | - | ||||||||||||
2344 | sample += QChar(0x4e2d); | - | ||||||||||||
2345 | sample += QChar(0x6587); | - | ||||||||||||
2346 | sample += QChar(0x7bc4); | - | ||||||||||||
2347 | sample += QChar(0x4f8b); | - | ||||||||||||
2348 | break; | - | ||||||||||||
2349 | case Japanese: | - | ||||||||||||
2350 | sample += QChar(0x30b5); | - | ||||||||||||
2351 | sample += QChar(0x30f3); | - | ||||||||||||
2352 | sample += QChar(0x30d7); | - | ||||||||||||
2353 | sample += QChar(0x30eb); | - | ||||||||||||
2354 | sample += QChar(0x3067); | - | ||||||||||||
2355 | sample += QChar(0x3059); | - | ||||||||||||
2356 | break; | - | ||||||||||||
2357 | case Korean: | - | ||||||||||||
2358 | sample += QChar(0xac00); | - | ||||||||||||
2359 | sample += QChar(0xac11); | - | ||||||||||||
2360 | sample += QChar(0xac1a); | - | ||||||||||||
2361 | sample += QChar(0xac2f); | - | ||||||||||||
2362 | break; | - | ||||||||||||
2363 | case Vietnamese: | - | ||||||||||||
2364 | { | - | ||||||||||||
2365 | static const char vietnameseUtf8[] = { | - | ||||||||||||
2366 | char(0xef), char(0xbb), char(0xbf), char(0xe1), char(0xbb), char(0x97), | - | ||||||||||||
2367 | char(0xe1), char(0xbb), char(0x99), | - | ||||||||||||
2368 | char(0xe1), char(0xbb), char(0x91), | - | ||||||||||||
2369 | char(0xe1), char(0xbb), char(0x93), | - | ||||||||||||
2370 | }; | - | ||||||||||||
2371 | sample += QString::fromUtf8(vietnameseUtf8, sizeof(vietnameseUtf8)); | - | ||||||||||||
2372 | break; | - | ||||||||||||
2373 | } | - | ||||||||||||
2374 | case Ogham: | - | ||||||||||||
2375 | sample += QChar(0x1681); | - | ||||||||||||
2376 | sample += QChar(0x1682); | - | ||||||||||||
2377 | sample += QChar(0x1683); | - | ||||||||||||
2378 | sample += QChar(0x1684); | - | ||||||||||||
2379 | break; | - | ||||||||||||
2380 | case Runic: | - | ||||||||||||
2381 | sample += QChar(0x16a0); | - | ||||||||||||
2382 | sample += QChar(0x16a1); | - | ||||||||||||
2383 | sample += QChar(0x16a2); | - | ||||||||||||
2384 | sample += QChar(0x16a3); | - | ||||||||||||
2385 | break; | - | ||||||||||||
2386 | case Nko: | - | ||||||||||||
2387 | sample += QChar(0x7ca); | - | ||||||||||||
2388 | sample += QChar(0x7cb); | - | ||||||||||||
2389 | sample += QChar(0x7cc); | - | ||||||||||||
2390 | sample += QChar(0x7cd); | - | ||||||||||||
2391 | break; | - | ||||||||||||
2392 | default: | - | ||||||||||||
2393 | break; | - | ||||||||||||
2394 | } | - | ||||||||||||
2395 | return sample; | - | ||||||||||||
2396 | } | - | ||||||||||||
2397 | - | |||||||||||||
2398 | - | |||||||||||||
2399 | void QFontDatabase::parseFontName(const QString &name, QString &foundry, QString &family) | - | ||||||||||||
2400 | { | - | ||||||||||||
2401 | QT_PREPEND_NAMESPACE(parseFontName)(name, foundry, family); | - | ||||||||||||
2402 | } | - | ||||||||||||
2403 | - | |||||||||||||
2404 | void QFontDatabase::createDatabase() | - | ||||||||||||
2405 | { initializeDb(); } | - | ||||||||||||
2406 | - | |||||||||||||
2407 | // used from qfontengine_ft.cpp | - | ||||||||||||
2408 | Q_GUI_EXPORT QByteArray qt_fontdata_from_index(int index) | - | ||||||||||||
2409 | { | - | ||||||||||||
2410 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2411 | return privateDb()->applicationFonts.value(index).data; | - | ||||||||||||
2412 | } | - | ||||||||||||
2413 | - | |||||||||||||
2414 | int QFontDatabasePrivate::addAppFont(const QByteArray &fontData, const QString &fileName) | - | ||||||||||||
2415 | { | - | ||||||||||||
2416 | QFontDatabasePrivate::ApplicationFont font; | - | ||||||||||||
2417 | font.data = fontData; | - | ||||||||||||
2418 | font.fileName = fileName; | - | ||||||||||||
2419 | - | |||||||||||||
2420 | int i; | - | ||||||||||||
2421 | for (i = 0; i < applicationFonts.count(); ++i) | - | ||||||||||||
2422 | if (applicationFonts.at(i).families.isEmpty()) | - | ||||||||||||
2423 | break; | - | ||||||||||||
2424 | if (i >= applicationFonts.count()) { | - | ||||||||||||
2425 | applicationFonts.append(ApplicationFont()); | - | ||||||||||||
2426 | i = applicationFonts.count() - 1; | - | ||||||||||||
2427 | } | - | ||||||||||||
2428 | - | |||||||||||||
2429 | if (font.fileName.isEmpty() && !fontData.isEmpty()) | - | ||||||||||||
2430 | font.fileName = QString::fromLatin1(":qmemoryfonts/") + QString::number(i); | - | ||||||||||||
2431 | - | |||||||||||||
2432 | registerFont(&font); | - | ||||||||||||
2433 | if (font.families.isEmpty()) | - | ||||||||||||
2434 | return -1; | - | ||||||||||||
2435 | - | |||||||||||||
2436 | applicationFonts[i] = font; | - | ||||||||||||
2437 | - | |||||||||||||
2438 | invalidate(); | - | ||||||||||||
2439 | return i; | - | ||||||||||||
2440 | } | - | ||||||||||||
2441 | - | |||||||||||||
2442 | bool QFontDatabasePrivate::isApplicationFont(const QString &fileName) | - | ||||||||||||
2443 | { | - | ||||||||||||
2444 | for (int i = 0; i < applicationFonts.count(); ++i) | - | ||||||||||||
2445 | if (applicationFonts.at(i).fileName == fileName) | - | ||||||||||||
2446 | return true; | - | ||||||||||||
2447 | return false; | - | ||||||||||||
2448 | } | - | ||||||||||||
2449 | - | |||||||||||||
2450 | /*! | - | ||||||||||||
2451 | \since 4.2 | - | ||||||||||||
2452 | - | |||||||||||||
2453 | Loads the font from the file specified by \a fileName and makes it available to | - | ||||||||||||
2454 | the application. An ID is returned that can be used to remove the font again | - | ||||||||||||
2455 | with removeApplicationFont() or to retrieve the list of family names contained | - | ||||||||||||
2456 | in the font. | - | ||||||||||||
2457 | - | |||||||||||||
2458 | The function returns -1 if the font could not be loaded. | - | ||||||||||||
2459 | - | |||||||||||||
2460 | Currently only TrueType fonts, TrueType font collections, and OpenType fonts are | - | ||||||||||||
2461 | supported. | - | ||||||||||||
2462 | - | |||||||||||||
2463 | \note Adding application fonts on Unix/X11 platforms without fontconfig is | - | ||||||||||||
2464 | currently not supported. | - | ||||||||||||
2465 | - | |||||||||||||
2466 | \sa addApplicationFontFromData(), applicationFontFamilies(), removeApplicationFont() | - | ||||||||||||
2467 | */ | - | ||||||||||||
2468 | int QFontDatabase::addApplicationFont(const QString &fileName) | - | ||||||||||||
2469 | { | - | ||||||||||||
2470 | QByteArray data; | - | ||||||||||||
2471 | if (!QFileInfo(fileName).isNativePath()) { | - | ||||||||||||
2472 | QFile f(fileName); | - | ||||||||||||
2473 | if (!f.open(QIODevice::ReadOnly)) | - | ||||||||||||
2474 | return -1; | - | ||||||||||||
2475 | data = f.readAll(); | - | ||||||||||||
2476 | } | - | ||||||||||||
2477 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2478 | return privateDb()->addAppFont(data, fileName); | - | ||||||||||||
2479 | } | - | ||||||||||||
2480 | - | |||||||||||||
2481 | /*! | - | ||||||||||||
2482 | \since 4.2 | - | ||||||||||||
2483 | - | |||||||||||||
2484 | Loads the font from binary data specified by \a fontData and makes it available to | - | ||||||||||||
2485 | the application. An ID is returned that can be used to remove the font again | - | ||||||||||||
2486 | with removeApplicationFont() or to retrieve the list of family names contained | - | ||||||||||||
2487 | in the font. | - | ||||||||||||
2488 | - | |||||||||||||
2489 | The function returns -1 if the font could not be loaded. | - | ||||||||||||
2490 | - | |||||||||||||
2491 | Currently only TrueType fonts and TrueType font collections are supported. | - | ||||||||||||
2492 | - | |||||||||||||
2493 | \b{Note:} Adding application fonts on Unix/X11 platforms without fontconfig is | - | ||||||||||||
2494 | currently not supported. | - | ||||||||||||
2495 | - | |||||||||||||
2496 | \sa addApplicationFont(), applicationFontFamilies(), removeApplicationFont() | - | ||||||||||||
2497 | */ | - | ||||||||||||
2498 | int QFontDatabase::addApplicationFontFromData(const QByteArray &fontData) | - | ||||||||||||
2499 | { | - | ||||||||||||
2500 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2501 | return privateDb()->addAppFont(fontData, QString() /* fileName */); | - | ||||||||||||
2502 | } | - | ||||||||||||
2503 | - | |||||||||||||
2504 | /*! | - | ||||||||||||
2505 | \since 4.2 | - | ||||||||||||
2506 | - | |||||||||||||
2507 | Returns a list of font families for the given application font identified by | - | ||||||||||||
2508 | \a id. | - | ||||||||||||
2509 | - | |||||||||||||
2510 | \sa addApplicationFont(), addApplicationFontFromData() | - | ||||||||||||
2511 | */ | - | ||||||||||||
2512 | QStringList QFontDatabase::applicationFontFamilies(int id) | - | ||||||||||||
2513 | { | - | ||||||||||||
2514 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2515 | return privateDb()->applicationFonts.value(id).families; | - | ||||||||||||
2516 | } | - | ||||||||||||
2517 | - | |||||||||||||
2518 | /*! | - | ||||||||||||
2519 | \since 5.2 | - | ||||||||||||
2520 | - | |||||||||||||
2521 | Returns the most adequate font for a given \a type case for proper integration | - | ||||||||||||
2522 | with the system's look and feel. | - | ||||||||||||
2523 | - | |||||||||||||
2524 | \sa QGuiApplication::font() | - | ||||||||||||
2525 | */ | - | ||||||||||||
2526 | - | |||||||||||||
2527 | QFont QFontDatabase::systemFont(QFontDatabase::SystemFont type) | - | ||||||||||||
2528 | { | - | ||||||||||||
2529 | const QFont *font = 0; | - | ||||||||||||
2530 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { | - | ||||||||||||
2531 | switch (type) { | - | ||||||||||||
2532 | case GeneralFont: | - | ||||||||||||
2533 | font = theme->font(QPlatformTheme::SystemFont); | - | ||||||||||||
2534 | break; | - | ||||||||||||
2535 | case FixedFont: | - | ||||||||||||
2536 | font = theme->font(QPlatformTheme::FixedFont); | - | ||||||||||||
2537 | break; | - | ||||||||||||
2538 | case TitleFont: | - | ||||||||||||
2539 | font = theme->font(QPlatformTheme::TitleBarFont); | - | ||||||||||||
2540 | break; | - | ||||||||||||
2541 | case SmallestReadableFont: | - | ||||||||||||
2542 | font = theme->font(QPlatformTheme::MiniFont); | - | ||||||||||||
2543 | break; | - | ||||||||||||
2544 | } | - | ||||||||||||
2545 | } | - | ||||||||||||
2546 | - | |||||||||||||
2547 | if (font) | - | ||||||||||||
2548 | return *font; | - | ||||||||||||
2549 | else if (QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration()) | - | ||||||||||||
2550 | return integration->fontDatabase()->defaultFont(); | - | ||||||||||||
2551 | else | - | ||||||||||||
2552 | return QFont(); | - | ||||||||||||
2553 | } | - | ||||||||||||
2554 | - | |||||||||||||
2555 | /*! | - | ||||||||||||
2556 | \fn bool QFontDatabase::removeApplicationFont(int id) | - | ||||||||||||
2557 | \since 4.2 | - | ||||||||||||
2558 | - | |||||||||||||
2559 | Removes the previously loaded application font identified by \a | - | ||||||||||||
2560 | id. Returns \c true if unloading of the font succeeded; otherwise | - | ||||||||||||
2561 | returns \c false. | - | ||||||||||||
2562 | - | |||||||||||||
2563 | \sa removeAllApplicationFonts(), addApplicationFont(), | - | ||||||||||||
2564 | addApplicationFontFromData() | - | ||||||||||||
2565 | */ | - | ||||||||||||
2566 | bool QFontDatabase::removeApplicationFont(int handle) | - | ||||||||||||
2567 | { | - | ||||||||||||
2568 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2569 | - | |||||||||||||
2570 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
2571 | if (handle < 0 || handle >= db->applicationFonts.count()) | - | ||||||||||||
2572 | return false; | - | ||||||||||||
2573 | - | |||||||||||||
2574 | db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont(); | - | ||||||||||||
2575 | - | |||||||||||||
2576 | db->reregisterAppFonts = true; | - | ||||||||||||
2577 | db->invalidate(); | - | ||||||||||||
2578 | return true; | - | ||||||||||||
2579 | } | - | ||||||||||||
2580 | - | |||||||||||||
2581 | /*! | - | ||||||||||||
2582 | \fn bool QFontDatabase::removeAllApplicationFonts() | - | ||||||||||||
2583 | \since 4.2 | - | ||||||||||||
2584 | - | |||||||||||||
2585 | Removes all application-local fonts previously added using addApplicationFont() | - | ||||||||||||
2586 | and addApplicationFontFromData(). | - | ||||||||||||
2587 | - | |||||||||||||
2588 | Returns \c true if unloading of the fonts succeeded; otherwise | - | ||||||||||||
2589 | returns \c false. | - | ||||||||||||
2590 | - | |||||||||||||
2591 | \sa removeApplicationFont(), addApplicationFont(), addApplicationFontFromData() | - | ||||||||||||
2592 | */ | - | ||||||||||||
2593 | bool QFontDatabase::removeAllApplicationFonts() | - | ||||||||||||
2594 | { | - | ||||||||||||
2595 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2596 | - | |||||||||||||
2597 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
2598 | if (db->applicationFonts.isEmpty()) | - | ||||||||||||
2599 | return false; | - | ||||||||||||
2600 | - | |||||||||||||
2601 | db->applicationFonts.clear(); | - | ||||||||||||
2602 | db->invalidate(); | - | ||||||||||||
2603 | return true; | - | ||||||||||||
2604 | } | - | ||||||||||||
2605 | - | |||||||||||||
2606 | /*! | - | ||||||||||||
2607 | \fn bool QFontDatabase::supportsThreadedFontRendering() | - | ||||||||||||
2608 | \since 4.4 | - | ||||||||||||
2609 | \deprecated | - | ||||||||||||
2610 | - | |||||||||||||
2611 | Returns \c true if font rendering is supported outside the GUI | - | ||||||||||||
2612 | thread, false otherwise. In other words, a return value of false | - | ||||||||||||
2613 | means that all QPainter::drawText() calls outside the GUI thread | - | ||||||||||||
2614 | will not produce readable output. | - | ||||||||||||
2615 | - | |||||||||||||
2616 | As of 5.0, always returns \c true. | - | ||||||||||||
2617 | - | |||||||||||||
2618 | \sa {Thread-Support in Qt Modules#Painting In Threads}{Painting In Threads} | - | ||||||||||||
2619 | */ | - | ||||||||||||
2620 | #if QT_DEPRECATED_SINCE(5, 2) | - | ||||||||||||
2621 | bool QFontDatabase::supportsThreadedFontRendering() | - | ||||||||||||
2622 | { | - | ||||||||||||
2623 | return true; | - | ||||||||||||
2624 | } | - | ||||||||||||
2625 | #endif | - | ||||||||||||
2626 | - | |||||||||||||
2627 | /*! | - | ||||||||||||
2628 | \internal | - | ||||||||||||
2629 | */ | - | ||||||||||||
2630 | QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script) | - | ||||||||||||
2631 | { | - | ||||||||||||
2632 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
2633 | - | |||||||||||||
2634 | if (!privateDb()->count)
| 0 | ||||||||||||
2635 | initializeDb(); never executed: initializeDb(); | 0 | ||||||||||||
2636 | - | |||||||||||||
2637 | QFontEngine *engine; | - | ||||||||||||
2638 | - | |||||||||||||
2639 | #if defined(QT_BUILD_INTERNAL) | - | ||||||||||||
2640 | // For testing purpose only, emulates an exact-matching monospace font | - | ||||||||||||
2641 | if (qt_enable_test_font && request.family == QLatin1String("__Qt__Box__Engine__")) {
| 0 | ||||||||||||
2642 | engine = new QTestFontEngine(request.pixelSize); | - | ||||||||||||
2643 | engine->fontDef = request; | - | ||||||||||||
2644 | return engine; never executed: return engine; | 0 | ||||||||||||
2645 | } | - | ||||||||||||
2646 | #endif | - | ||||||||||||
2647 | - | |||||||||||||
2648 | QFontCache *fontCache = QFontCache::instance(); | - | ||||||||||||
2649 | - | |||||||||||||
2650 | // Until we specifically asked not to, try looking for Multi font engine | - | ||||||||||||
2651 | // first, the last '1' indicates that we want Multi font engine instead | - | ||||||||||||
2652 | // of single ones | - | ||||||||||||
2653 | bool multi = !(request.styleStrategy & QFont::NoFontMerging); | - | ||||||||||||
2654 | QFontCache::Key key(request, script, multi ? 1 : 0); | - | ||||||||||||
2655 | engine = fontCache->findEngine(key); | - | ||||||||||||
2656 | if (engine) {
| 0 | ||||||||||||
2657 | FM_DEBUG("Cache hit level 1"); dead code: QMessageLogger(__FILE__, 2657, __PRETTY_FUNCTION__).debug("Cache hit level 1"); | - | ||||||||||||
2658 | return engine; never executed: return engine; | 0 | ||||||||||||
2659 | } | - | ||||||||||||
2660 | - | |||||||||||||
2661 | QString family_name, foundry_name; | - | ||||||||||||
2662 | - | |||||||||||||
2663 | parseFontName(request.family, foundry_name, family_name); | - | ||||||||||||
2664 | - | |||||||||||||
2665 | QtFontDesc desc; | - | ||||||||||||
2666 | QList<int> blackListed; | - | ||||||||||||
2667 | int index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed); | - | ||||||||||||
2668 | if (index >= 0) {
| 0 | ||||||||||||
2669 | engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size); | - | ||||||||||||
2670 | if (engine)
| 0 | ||||||||||||
2671 | initFontDef(desc, request, &engine->fontDef, multi); never executed: initFontDef(desc, request, &engine->fontDef, multi); | 0 | ||||||||||||
2672 | else | - | ||||||||||||
2673 | blackListed.append(index); never executed: blackListed.append(index); | 0 | ||||||||||||
2674 | } else { | - | ||||||||||||
2675 | FM_DEBUG(" NO MATCH FOUND\n"); dead code: QMessageLogger(__FILE__, 2675, __PRETTY_FUNCTION__).debug(" NO MATCH FOUND\n"); | - | ||||||||||||
2676 | } never executed: end of block | 0 | ||||||||||||
2677 | - | |||||||||||||
2678 | if (!engine) {
| 0 | ||||||||||||
2679 | if (!request.family.isEmpty()) {
| 0 | ||||||||||||
2680 | QFont::StyleHint styleHint = QFont::StyleHint(request.styleHint); | - | ||||||||||||
2681 | if (styleHint == QFont::AnyStyle && request.fixedPitch)
| 0 | ||||||||||||
2682 | styleHint = QFont::TypeWriter; never executed: styleHint = QFont::TypeWriter; | 0 | ||||||||||||
2683 | - | |||||||||||||
2684 | QStringList fallbacks = request.fallBackFamilies | - | ||||||||||||
2685 | + fallbacksForFamily(request.family, | - | ||||||||||||
2686 | QFont::Style(request.style), | - | ||||||||||||
2687 | styleHint, | - | ||||||||||||
2688 | QChar::Script(script)); | - | ||||||||||||
2689 | if (script > QChar::Script_Common)
| 0 | ||||||||||||
2690 | fallbacks += QString(); // Find the first font matching the specified script. never executed: fallbacks += QString(); | 0 | ||||||||||||
2691 | - | |||||||||||||
2692 | for (int i = 0; !engine && i < fallbacks.size(); i++) {
| 0 | ||||||||||||
2693 | QFontDef def = request; | - | ||||||||||||
2694 | def.family = fallbacks.at(i); | - | ||||||||||||
2695 | QFontCache::Key key(def, script, multi ? 1 : 0); | - | ||||||||||||
2696 | engine = fontCache->findEngine(key); | - | ||||||||||||
2697 | if (!engine) {
| 0 | ||||||||||||
2698 | QtFontDesc desc; | - | ||||||||||||
2699 | do { | - | ||||||||||||
2700 | index = match(multi ? QChar::Script_Common : script, def, def.family, QLatin1String(""), &desc, blackListed); | - | ||||||||||||
2701 | if (index >= 0) {
| 0 | ||||||||||||
2702 | QFontDef loadDef = def; | - | ||||||||||||
2703 | if (loadDef.family.isEmpty())
| 0 | ||||||||||||
2704 | loadDef.family = desc.family->name; never executed: loadDef.family = desc.family->name; | 0 | ||||||||||||
2705 | engine = loadEngine(script, loadDef, desc.family, desc.foundry, desc.style, desc.size); | - | ||||||||||||
2706 | if (engine)
| 0 | ||||||||||||
2707 | initFontDef(desc, loadDef, &engine->fontDef, multi); never executed: initFontDef(desc, loadDef, &engine->fontDef, multi); | 0 | ||||||||||||
2708 | else | - | ||||||||||||
2709 | blackListed.append(index); never executed: blackListed.append(index); | 0 | ||||||||||||
2710 | } | - | ||||||||||||
2711 | } while (index >= 0 && !engine); never executed: end of block
| 0 | ||||||||||||
2712 | } never executed: end of block | 0 | ||||||||||||
2713 | } never executed: end of block | 0 | ||||||||||||
2714 | } never executed: end of block | 0 | ||||||||||||
2715 | - | |||||||||||||
2716 | if (!engine)
| 0 | ||||||||||||
2717 | engine = new QFontEngineBox(request.pixelSize); never executed: engine = new QFontEngineBox(request.pixelSize); | 0 | ||||||||||||
2718 | - | |||||||||||||
2719 | FM_DEBUG("returning box engine"); dead code: QMessageLogger(__FILE__, 2719, __PRETTY_FUNCTION__).debug("returning box engine"); | - | ||||||||||||
2720 | } never executed: end of block | 0 | ||||||||||||
2721 | - | |||||||||||||
2722 | return engine; never executed: return engine; | 0 | ||||||||||||
2723 | } | - | ||||||||||||
2724 | - | |||||||||||||
2725 | void QFontDatabase::load(const QFontPrivate *d, int script) | - | ||||||||||||
2726 | { | - | ||||||||||||
2727 | QFontDef req = d->request; | - | ||||||||||||
2728 | - | |||||||||||||
2729 | if (req.pixelSize == -1) { | - | ||||||||||||
2730 | req.pixelSize = std::floor(((req.pointSize * d->dpi) / 72) * 100 + 0.5) / 100; | - | ||||||||||||
2731 | req.pixelSize = qRound(req.pixelSize); | - | ||||||||||||
2732 | } | - | ||||||||||||
2733 | if (req.pointSize < 0) | - | ||||||||||||
2734 | req.pointSize = req.pixelSize*72.0/d->dpi; | - | ||||||||||||
2735 | if (req.stretch == 0) | - | ||||||||||||
2736 | req.stretch = 100; | - | ||||||||||||
2737 | - | |||||||||||||
2738 | // respect the fallback families that might be passed through the request | - | ||||||||||||
2739 | const QStringList fallBackFamilies = familyList(req); | - | ||||||||||||
2740 | - | |||||||||||||
2741 | if (!d->engineData) { | - | ||||||||||||
2742 | QFontCache *fontCache = QFontCache::instance(); | - | ||||||||||||
2743 | // look for the requested font in the engine data cache | - | ||||||||||||
2744 | // note: fallBackFamilies are not respected in the EngineData cache key; | - | ||||||||||||
2745 | // join them with the primary selection family to avoid cache misses | - | ||||||||||||
2746 | req.family = fallBackFamilies.join(QLatin1Char(',')); | - | ||||||||||||
2747 | - | |||||||||||||
2748 | d->engineData = fontCache->findEngineData(req); | - | ||||||||||||
2749 | if (!d->engineData) { | - | ||||||||||||
2750 | // create a new one | - | ||||||||||||
2751 | d->engineData = new QFontEngineData; | - | ||||||||||||
2752 | fontCache->insertEngineData(req, d->engineData); | - | ||||||||||||
2753 | } | - | ||||||||||||
2754 | d->engineData->ref.ref(); | - | ||||||||||||
2755 | } | - | ||||||||||||
2756 | - | |||||||||||||
2757 | // the cached engineData could have already loaded the engine we want | - | ||||||||||||
2758 | if (d->engineData->engines[script]) | - | ||||||||||||
2759 | return; | - | ||||||||||||
2760 | - | |||||||||||||
2761 | QFontEngine *fe = Q_NULLPTR; | - | ||||||||||||
2762 | - | |||||||||||||
2763 | req.fallBackFamilies = fallBackFamilies; | - | ||||||||||||
2764 | if (!req.fallBackFamilies.isEmpty()) | - | ||||||||||||
2765 | req.family = req.fallBackFamilies.takeFirst(); | - | ||||||||||||
2766 | - | |||||||||||||
2767 | // list of families to try | - | ||||||||||||
2768 | QStringList family_list; | - | ||||||||||||
2769 | - | |||||||||||||
2770 | if (!req.family.isEmpty()) { | - | ||||||||||||
2771 | // Add primary selection | - | ||||||||||||
2772 | family_list << req.family; | - | ||||||||||||
2773 | - | |||||||||||||
2774 | // add the default family | - | ||||||||||||
2775 | QString defaultFamily = QGuiApplication::font().family(); | - | ||||||||||||
2776 | if (! family_list.contains(defaultFamily)) | - | ||||||||||||
2777 | family_list << defaultFamily; | - | ||||||||||||
2778 | - | |||||||||||||
2779 | } | - | ||||||||||||
2780 | - | |||||||||||||
2781 | // null family means find the first font matching the specified script | - | ||||||||||||
2782 | family_list << QString(); | - | ||||||||||||
2783 | - | |||||||||||||
2784 | QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd(); | - | ||||||||||||
2785 | for (; !fe && it != end; ++it) { | - | ||||||||||||
2786 | req.family = *it; | - | ||||||||||||
2787 | - | |||||||||||||
2788 | fe = QFontDatabase::findFont(req, script); | - | ||||||||||||
2789 | if (fe) { | - | ||||||||||||
2790 | if (fe->type() == QFontEngine::Box && !req.family.isEmpty()) { | - | ||||||||||||
2791 | if (fe->ref.load() == 0) | - | ||||||||||||
2792 | delete fe; | - | ||||||||||||
2793 | fe = 0; | - | ||||||||||||
2794 | } else { | - | ||||||||||||
2795 | if (d->dpi > 0) | - | ||||||||||||
2796 | fe->fontDef.pointSize = qreal(double((fe->fontDef.pixelSize * 72) / d->dpi)); | - | ||||||||||||
2797 | } | - | ||||||||||||
2798 | } | - | ||||||||||||
2799 | - | |||||||||||||
2800 | // No need to check requested fallback families again | - | ||||||||||||
2801 | req.fallBackFamilies.clear(); | - | ||||||||||||
2802 | } | - | ||||||||||||
2803 | - | |||||||||||||
2804 | Q_ASSERT(fe); | - | ||||||||||||
2805 | if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) { | - | ||||||||||||
2806 | for (int i = 0; i < QChar::ScriptCount; ++i) { | - | ||||||||||||
2807 | if (!d->engineData->engines[i]) { | - | ||||||||||||
2808 | d->engineData->engines[i] = fe; | - | ||||||||||||
2809 | fe->ref.ref(); | - | ||||||||||||
2810 | } | - | ||||||||||||
2811 | } | - | ||||||||||||
2812 | } else { | - | ||||||||||||
2813 | d->engineData->engines[script] = fe; | - | ||||||||||||
2814 | fe->ref.ref(); | - | ||||||||||||
2815 | } | - | ||||||||||||
2816 | } | - | ||||||||||||
2817 | - | |||||||||||||
2818 | QString QFontDatabase::resolveFontFamilyAlias(const QString &family) | - | ||||||||||||
2819 | { | - | ||||||||||||
2820 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(family); | - | ||||||||||||
2821 | } | - | ||||||||||||
2822 | - | |||||||||||||
2823 | - | |||||||||||||
2824 | QT_END_NAMESPACE | - | ||||||||||||
2825 | - | |||||||||||||
Source code | Switch to Preprocessed file |