| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 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"))
| 0 | ||||||||||||||||||
| 104 | return QFont::Normal; never executed: return QFont::Normal; | 0 | ||||||||||||||||||
| 105 | if (s == QLatin1String("bold"))
| 0 | ||||||||||||||||||
| 106 | return QFont::Bold; never executed: return QFont::Bold; | 0 | ||||||||||||||||||
| 107 | if (s == QLatin1String("semibold") || s == QLatin1String("semi bold")
| 0 | ||||||||||||||||||
| 108 | || s == QLatin1String("demibold") || s == QLatin1String("demi bold"))
| 0 | ||||||||||||||||||
| 109 | return QFont::DemiBold; never executed: return QFont::DemiBold; | 0 | ||||||||||||||||||
| 110 | if (s == QLatin1String("medium"))
| 0 | ||||||||||||||||||
| 111 | return QFont::Medium; never executed: return QFont::Medium; | 0 | ||||||||||||||||||
| 112 | if (s == QLatin1String("black"))
| 0 | ||||||||||||||||||
| 113 | return QFont::Black; never executed: return QFont::Black; | 0 | ||||||||||||||||||
| 114 | if (s == QLatin1String("light"))
| 0 | ||||||||||||||||||
| 115 | return QFont::Light; never executed: return QFont::Light; | 0 | ||||||||||||||||||
| 116 | if (s == QLatin1String("thin"))
| 0 | ||||||||||||||||||
| 117 | return QFont::Thin; never executed: return QFont::Thin; | 0 | ||||||||||||||||||
| 118 | const QStringRef s2 = s.midRef(2); | - | ||||||||||||||||||
| 119 | if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) {
| 0 | ||||||||||||||||||
| 120 | if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light"))
| 0 | ||||||||||||||||||
| 121 | return QFont::ExtraLight; never executed: return QFont::ExtraLight; | 0 | ||||||||||||||||||
| 122 | if (s2 == QLatin1String("trabold") || s2 == QLatin1String("tra bold"))
| 0 | ||||||||||||||||||
| 123 | return QFont::ExtraBold; never executed: return QFont::ExtraBold; | 0 | ||||||||||||||||||
| 124 | } never executed: end of block | 0 | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | // Next up, let's see if contains() matches: slightly more expensive, but | - | ||||||||||||||||||
| 127 | // still fast enough. | - | ||||||||||||||||||
| 128 | if (s.contains(QLatin1String("bold"))) {
| 0 | ||||||||||||||||||
| 129 | if (s.contains(QLatin1String("demi")))
| 0 | ||||||||||||||||||
| 130 | return QFont::DemiBold; never executed: return QFont::DemiBold; | 0 | ||||||||||||||||||
| 131 | return QFont::Bold; never executed: return QFont::Bold; | 0 | ||||||||||||||||||
| 132 | } | - | ||||||||||||||||||
| 133 | if (s.contains(QLatin1String("thin")))
| 0 | ||||||||||||||||||
| 134 | return QFont::Thin; never executed: return QFont::Thin; | 0 | ||||||||||||||||||
| 135 | if (s.contains(QLatin1String("light")))
| 0 | ||||||||||||||||||
| 136 | return QFont::Light; never executed: return QFont::Light; | 0 | ||||||||||||||||||
| 137 | if (s.contains(QLatin1String("black")))
| 0 | ||||||||||||||||||
| 138 | return QFont::Black; never executed: return QFont::Black; | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 145 | return QFont::Normal; never executed: return QFont::Normal; | 0 | ||||||||||||||||||
| 146 | const QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower(); | - | ||||||||||||||||||
| 147 | if (s == translatedBold)
| 0 | ||||||||||||||||||
| 148 | return QFont::Bold; never executed: return QFont::Bold; | 0 | ||||||||||||||||||
| 149 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 150 | return QFont::DemiBold; never executed: return QFont::DemiBold; | 0 | ||||||||||||||||||
| 151 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 152 | return QFont::Medium; never executed: return QFont::Medium; | 0 | ||||||||||||||||||
| 153 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 154 | return QFont::Black; never executed: return QFont::Black; | 0 | ||||||||||||||||||
| 155 | const QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower(); | - | ||||||||||||||||||
| 156 | if (s == translatedLight)
| 0 | ||||||||||||||||||
| 157 | return QFont::Light; never executed: return QFont::Light; | 0 | ||||||||||||||||||
| 158 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Thin"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 159 | return QFont::Thin; never executed: return QFont::Thin; | 0 | ||||||||||||||||||
| 160 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Light"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 161 | return QFont::ExtraLight; never executed: return QFont::ExtraLight; | 0 | ||||||||||||||||||
| 162 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Bold"), Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 163 | return QFont::ExtraBold; never executed: return QFont::ExtraBold; | 0 | ||||||||||||||||||
| 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)) {
| 0 | ||||||||||||||||||
| 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))
| 0 | ||||||||||||||||||
| 172 | return QFont::DemiBold; never executed: return QFont::DemiBold; | 0 | ||||||||||||||||||
| 173 | if (s.contains(translatedExtra))
| 0 | ||||||||||||||||||
| 174 | return QFont::ExtraBold; never executed: return QFont::ExtraBold; | 0 | ||||||||||||||||||
| 175 | return QFont::Bold; never executed: return QFont::Bold; | 0 | ||||||||||||||||||
| 176 | } | - | ||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | if (s.contains(translatedLight)) {
| 0 | ||||||||||||||||||
| 179 | if (s.contains(translatedExtra))
| 0 | ||||||||||||||||||
| 180 | return QFont::ExtraLight; never executed: return QFont::ExtraLight; | 0 | ||||||||||||||||||
| 181 | return QFont::Light; never executed: return QFont::Light; | 0 | ||||||||||||||||||
| 182 | } | - | ||||||||||||||||||
| 183 | return QFont::Normal; never executed: return QFont::Normal; | 0 | ||||||||||||||||||
| 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) { } never executed: end of block | 0 | ||||||||||||||||||
| 203 | Key(const Key &o) : style(o.style), weight(o.weight), stretch(o.stretch) { } never executed: end of block | 0 | ||||||||||||||||||
| 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 && never executed: return (style == other.style && weight == other.weight && (stretch == 0 || other.stretch == 0 || stretch == other.stretch)); | 0 | ||||||||||||||||||
| 210 | (stretch == 0 || other.stretch == 0 || stretch == other.stretch)); never executed: return (style == other.style && weight == other.weight && (stretch == 0 || other.stretch == 0 || stretch == other.stretch)); | 0 | ||||||||||||||||||
| 211 | } | - | ||||||||||||||||||
| 212 | bool operator!=(const Key &other) { | - | ||||||||||||||||||
| 213 | return !operator==(other); never executed: return !operator==(other); | 0 | ||||||||||||||||||
| 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); never executed: return (x < y); | 0 | ||||||||||||||||||
| 219 | } | - | ||||||||||||||||||
| 220 | }; | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | QtFontStyle(const Key &k) | - | ||||||||||||||||||
| 223 | : key(k), bitmapScalable(false), smoothScalable(false), | - | ||||||||||||||||||
| 224 | count(0), pixelSizes(0) | - | ||||||||||||||||||
| 225 | { | - | ||||||||||||||||||
| 226 | } never executed: end of block | 0 | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | ~QtFontStyle() { | - | ||||||||||||||||||
| 229 | while (count) {
| 0 | ||||||||||||||||||
| 230 | // bitfield count-- in while condition does not work correctly in mwccsym2 | - | ||||||||||||||||||
| 231 | count--; | - | ||||||||||||||||||
| 232 | QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||||||||
| 233 | if (integration) {
| 0 | ||||||||||||||||||
| 234 | integration->fontDatabase()->releaseHandle(pixelSizes[count].handle); | - | ||||||||||||||||||
| 235 | } never executed: end of block | 0 | ||||||||||||||||||
| 236 | } never executed: end of block | 0 | ||||||||||||||||||
| 237 | free(pixelSizes); | - | ||||||||||||||||||
| 238 | } never executed: end of block | 0 | ||||||||||||||||||
| 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()) {
| 0 | ||||||||||||||||||
| 258 | // First the straightforward no-translation checks, these are fast. | - | ||||||||||||||||||
| 259 | if (styleString.contains(QLatin1String("Italic")))
| 0 | ||||||||||||||||||
| 260 | style = QFont::StyleItalic; never executed: style = QFont::StyleItalic; | 0 | ||||||||||||||||||
| 261 | else if (styleString.contains(QLatin1String("Oblique")))
| 0 | ||||||||||||||||||
| 262 | style = QFont::StyleOblique; never executed: style = QFont::StyleOblique; | 0 | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | // Then the translation checks. These aren't as fast. | - | ||||||||||||||||||
| 265 | else if (styleString.contains(QCoreApplication::translate("QFontDatabase", "Italic")))
| 0 | ||||||||||||||||||
| 266 | style = QFont::StyleItalic; never executed: style = QFont::StyleItalic; | 0 | ||||||||||||||||||
| 267 | else if (styleString.contains(QCoreApplication::translate("QFontDatabase", "Oblique")))
| 0 | ||||||||||||||||||
| 268 | style = QFont::StyleOblique; never executed: style = QFont::StyleOblique; | 0 | ||||||||||||||||||
| 269 | } never executed: end of block | 0 | ||||||||||||||||||
| 270 | } never executed: end of block | 0 | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add) | - | ||||||||||||||||||
| 273 | { | - | ||||||||||||||||||
| 274 | for (int i = 0; i < count; i++) {
| 0 | ||||||||||||||||||
| 275 | if (pixelSizes[i].pixelSize == size)
| 0 | ||||||||||||||||||
| 276 | return pixelSizes + i; never executed: return pixelSizes + i; | 0 | ||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||
| 278 | if (!add)
| 0 | ||||||||||||||||||
| 279 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | if (!pixelSizes) {
| 0 | ||||||||||||||||||
| 282 | // Most style have only one font size, we avoid waisting memory | - | ||||||||||||||||||
| 283 | QtFontSize *newPixelSizes = (QtFontSize *)malloc(sizeof(QtFontSize)); | - | ||||||||||||||||||
| 284 | Q_CHECK_PTR(newPixelSizes); never executed: qt_check_pointer(__FILE__,284);
| 0 | ||||||||||||||||||
| 285 | pixelSizes = newPixelSizes; | - | ||||||||||||||||||
| 286 | } else if (!(count % 8) || count == 1) { never executed: end of block
| 0 | ||||||||||||||||||
| 287 | QtFontSize *newPixelSizes = (QtFontSize *) | - | ||||||||||||||||||
| 288 | realloc(pixelSizes, | - | ||||||||||||||||||
| 289 | (((count+8) >> 3) << 3) * sizeof(QtFontSize)); | - | ||||||||||||||||||
| 290 | Q_CHECK_PTR(newPixelSizes); never executed: qt_check_pointer(__FILE__,290);
| 0 | ||||||||||||||||||
| 291 | pixelSizes = newPixelSizes; | - | ||||||||||||||||||
| 292 | } never executed: end of block | 0 | ||||||||||||||||||
| 293 | pixelSizes[count].pixelSize = size; | - | ||||||||||||||||||
| 294 | pixelSizes[count].handle = 0; | - | ||||||||||||||||||
| 295 | return pixelSizes + (count++); never executed: return pixelSizes + (count++); | 0 | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | struct QtFontFoundry | - | ||||||||||||||||||
| 299 | { | - | ||||||||||||||||||
| 300 | QtFontFoundry(const QString &n) : name(n), count(0), styles(0) {} never executed: end of block | 0 | ||||||||||||||||||
| 301 | ~QtFontFoundry() { | - | ||||||||||||||||||
| 302 | while (count--)
| 0 | ||||||||||||||||||
| 303 | delete styles[count]; never executed: delete styles[count]; | 0 | ||||||||||||||||||
| 304 | free(styles); | - | ||||||||||||||||||
| 305 | } never executed: end of block | 0 | ||||||||||||||||||
| 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++) {
| 0 | ||||||||||||||||||
| 318 | bool hasStyleName = !styleName.isEmpty(); // search styleName first if available | - | ||||||||||||||||||
| 319 | if (hasStyleName && !styles[pos]->styleName.isEmpty()) {
| 0 | ||||||||||||||||||
| 320 | if (styles[pos]->styleName == styleName)
| 0 | ||||||||||||||||||
| 321 | return styles[pos]; never executed: return styles[pos]; | 0 | ||||||||||||||||||
| 322 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 323 | if (styles[pos]->key == key)
| 0 | ||||||||||||||||||
| 324 | return styles[pos]; never executed: return styles[pos]; | 0 | ||||||||||||||||||
| 325 | } never executed: end of block | 0 | ||||||||||||||||||
| 326 | } | - | ||||||||||||||||||
| 327 | if (!create)
| 0 | ||||||||||||||||||
| 328 | return 0; never executed: return 0; | 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)) {
| 0 | ||||||||||||||||||
| 332 | QtFontStyle **newStyles = (QtFontStyle **) | - | ||||||||||||||||||
| 333 | realloc(styles, (((count+8) >> 3) << 3) * sizeof(QtFontStyle *)); | - | ||||||||||||||||||
| 334 | Q_CHECK_PTR(newStyles); never executed: qt_check_pointer(__FILE__,334);
| 0 | ||||||||||||||||||
| 335 | styles = newStyles; | - | ||||||||||||||||||
| 336 | } never executed: end of block | 0 | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | QtFontStyle *style = new QtFontStyle(key); | - | ||||||||||||||||||
| 339 | style->styleName = styleName; | - | ||||||||||||||||||
| 340 | styles[pos] = style; | - | ||||||||||||||||||
| 341 | count++; | - | ||||||||||||||||||
| 342 | return styles[pos]; never executed: return styles[pos]; | 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 363 | ~QtFontFamily() { | - | ||||||||||||||||||
| 364 | while (count--)
| 0 | ||||||||||||||||||
| 365 | delete foundries[count]; never executed: delete foundries[count]; | 0 | ||||||||||||||||||
| 366 | free(foundries); | - | ||||||||||||||||||
| 367 | } never executed: end of block | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 388 | return foundries[0]; never executed: return foundries[0]; | 0 | ||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | for (int i = 0; i < count; i++) {
| 0 | ||||||||||||||||||
| 391 | if (foundries[i]->name.compare(f, Qt::CaseInsensitive) == 0)
| 0 | ||||||||||||||||||
| 392 | return foundries[i]; never executed: return foundries[i]; | 0 | ||||||||||||||||||
| 393 | } never executed: end of block | 0 | ||||||||||||||||||
| 394 | if (!create)
| 0 | ||||||||||||||||||
| 395 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | if (!(count % 8)) {
| 0 | ||||||||||||||||||
| 398 | QtFontFoundry **newFoundries = (QtFontFoundry **) | - | ||||||||||||||||||
| 399 | realloc(foundries, | - | ||||||||||||||||||
| 400 | (((count+8) >> 3) << 3) * sizeof(QtFontFoundry *)); | - | ||||||||||||||||||
| 401 | Q_CHECK_PTR(newFoundries); never executed: qt_check_pointer(__FILE__,401);
| 0 | ||||||||||||||||||
| 402 | foundries = newFoundries; | - | ||||||||||||||||||
| 403 | } never executed: end of block | 0 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | foundries[count] = new QtFontFoundry(f); | - | ||||||||||||||||||
| 406 | return foundries[count++]; never executed: return foundries[count++]; | 0 | ||||||||||||||||||
| 407 | } | - | ||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | bool QtFontFamily::matchesFamilyName(const QString &familyName) const | - | ||||||||||||||||||
| 410 | { | - | ||||||||||||||||||
| 411 | return name.compare(familyName, Qt::CaseInsensitive) == 0 || aliases.contains(familyName, Qt::CaseInsensitive); never executed: return name.compare(familyName, Qt::CaseInsensitive) == 0 || aliases.contains(familyName, Qt::CaseInsensitive); | 0 | ||||||||||||||||||
| 412 | } | - | ||||||||||||||||||
| 413 | - | |||||||||||||||||||
| 414 | void QtFontFamily::ensurePopulated() | - | ||||||||||||||||||
| 415 | { | - | ||||||||||||||||||
| 416 | if (populated)
| 0 | ||||||||||||||||||
| 417 | return; never executed: return; | 0 | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamily(name); | - | ||||||||||||||||||
| 420 | Q_ASSERT_X(populated, Q_FUNC_INFO, qPrintable(name)); | - | ||||||||||||||||||
| 421 | } never executed: end of block | 0 | ||||||||||||||||||
| 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 | { } never executed: end of block | 0 | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | ~QFontDatabasePrivate() { | - | ||||||||||||||||||
| 465 | free(); | - | ||||||||||||||||||
| 466 | } never executed: end of block | 0 | ||||||||||||||||||
| 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--)
| 0 | ||||||||||||||||||
| 477 | delete families[count]; never executed: delete families[count]; | 0 | ||||||||||||||||||
| 478 | ::free(families); | - | ||||||||||||||||||
| 479 | families = 0; | - | ||||||||||||||||||
| 480 | count = 0; | - | ||||||||||||||||||
| 481 | // don't clear the memory fonts! | - | ||||||||||||||||||
| 482 | } never executed: end of block | 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 523 | while ((res = families[pos]->name.compare(f, Qt::CaseInsensitive)) && pos != low) {
| 0 | ||||||||||||||||||
| 524 | if (res > 0)
| 0 | ||||||||||||||||||
| 525 | high = pos; never executed: high = pos; | 0 | ||||||||||||||||||
| 526 | else | - | ||||||||||||||||||
| 527 | low = pos; never executed: low = pos; | 0 | ||||||||||||||||||
| 528 | pos = (high + low) / 2; | - | ||||||||||||||||||
| 529 | } never executed: end of block | 0 | ||||||||||||||||||
| 530 | if (!res)
| 0 | ||||||||||||||||||
| 531 | fam = families[pos]; never executed: fam = families[pos]; | 0 | ||||||||||||||||||
| 532 | } never executed: end of block | 0 | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | if (!fam && (flags & EnsureCreated)) {
| 0 | ||||||||||||||||||
| 535 | if (res < 0)
| 0 | ||||||||||||||||||
| 536 | pos++; never executed: pos++; | 0 | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | // qDebug() << "adding family " << f.toLatin1() << " at " << pos << " total=" << count; | - | ||||||||||||||||||
| 539 | if (!(count % 8)) {
| 0 | ||||||||||||||||||
| 540 | QtFontFamily **newFamilies = (QtFontFamily **) | - | ||||||||||||||||||
| 541 | realloc(families, | - | ||||||||||||||||||
| 542 | (((count+8) >> 3) << 3) * sizeof(QtFontFamily *)); | - | ||||||||||||||||||
| 543 | Q_CHECK_PTR(newFamilies); never executed: qt_check_pointer(__FILE__,543);
| 0 | ||||||||||||||||||
| 544 | families = newFamilies; | - | ||||||||||||||||||
| 545 | } never executed: end of block | 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 554 | - | |||||||||||||||||||
| 555 | if (fam && (flags & EnsurePopulated))
| 0 | ||||||||||||||||||
| 556 | fam->ensurePopulated(); never executed: fam->ensurePopulated(); | 0 | ||||||||||||||||||
| 557 | - | |||||||||||||||||||
| 558 | return fam; never executed: return fam; | 0 | ||||||||||||||||||
| 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]; never executed: return scriptForWritingSystem[writingSystem]; | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 624 | foundry = name.mid(i + 1, li - i - 1); | - | ||||||||||||||||||
| 625 | if (i > 0 && name[i - 1] == QLatin1Char(' '))
| 0 | ||||||||||||||||||
| 626 | i--; never executed: i--; | 0 | ||||||||||||||||||
| 627 | family = name.left(i); | - | ||||||||||||||||||
| 628 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 629 | foundry.clear(); | - | ||||||||||||||||||
| 630 | family = name; | - | ||||||||||||||||||
| 631 | } never executed: end of block | 0 | ||||||||||||||||||
| 632 | - | |||||||||||||||||||
| 633 | // capitalize the family/foundry names | - | ||||||||||||||||||
| 634 | bool space = true; | - | ||||||||||||||||||
| 635 | QChar *s = family.data(); | - | ||||||||||||||||||
| 636 | int len = family.length(); | - | ||||||||||||||||||
| 637 | while(len--) {
| 0 | ||||||||||||||||||
| 638 | if (space) *s = s->toUpper(); never executed: *s = s->toUpper();
| 0 | ||||||||||||||||||
| 639 | space = s->isSpace(); | - | ||||||||||||||||||
| 640 | ++s; | - | ||||||||||||||||||
| 641 | } never executed: end of block | 0 | ||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | space = true; | - | ||||||||||||||||||
| 644 | s = foundry.data(); | - | ||||||||||||||||||
| 645 | len = foundry.length(); | - | ||||||||||||||||||
| 646 | while(len--) {
| 0 | ||||||||||||||||||
| 647 | if (space) *s = s->toUpper(); never executed: *s = s->toUpper();
| 0 | ||||||||||||||||||
| 648 | space = s->isSpace(); | - | ||||||||||||||||||
| 649 | ++s; | - | ||||||||||||||||||
| 650 | } never executed: end of block | 0 | ||||||||||||||||||
| 651 | } never executed: end of block | 0 | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | - | |||||||||||||||||||
| 654 | struct QtFontDesc | - | ||||||||||||||||||
| 655 | { | - | ||||||||||||||||||
| 656 | inline QtFontDesc() : family(0), foundry(0), style(0), size(0) {} never executed: end of block | 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) {
| 0 | ||||||||||||||||||
| 667 | fontDef->family += QString::fromLatin1(" ["); | - | ||||||||||||||||||
| 668 | fontDef->family += desc.foundry->name; | - | ||||||||||||||||||
| 669 | fontDef->family += QLatin1Char(']'); | - | ||||||||||||||||||
| 670 | } never executed: end of block | 0 | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | if (desc.style->smoothScalable
| 0 | ||||||||||||||||||
| 673 | || QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()
| 0 | ||||||||||||||||||
| 674 | || (desc.style->bitmapScalable && (request.styleStrategy & QFont::PreferMatch))) {
| 0 | ||||||||||||||||||
| 675 | fontDef->pixelSize = request.pixelSize; | - | ||||||||||||||||||
| 676 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 677 | fontDef->pixelSize = desc.size->pixelSize; | - | ||||||||||||||||||
| 678 | } never executed: end of block | 0 | ||||||||||||||||||
| 679 | fontDef->pointSize = request.pointSize; | - | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | fontDef->styleHint = request.styleHint; | - | ||||||||||||||||||
| 682 | fontDef->styleStrategy = request.styleStrategy; | - | ||||||||||||||||||
| 683 | - | |||||||||||||||||||
| 684 | if (!multi)
| 0 | ||||||||||||||||||
| 685 | fontDef->weight = desc.style->key.weight; never executed: fontDef->weight = desc.style->key.weight; | 0 | ||||||||||||||||||
| 686 | if (!multi)
| 0 | ||||||||||||||||||
| 687 | fontDef->style = desc.style->key.style; never executed: fontDef->style = desc.style->key.style; | 0 | ||||||||||||||||||
| 688 | fontDef->fixedPitch = desc.family->fixedPitch; | - | ||||||||||||||||||
| 689 | fontDef->stretch = desc.style->key.stretch; | - | ||||||||||||||||||
| 690 | fontDef->ignorePitch = false; | - | ||||||||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||||||||
| 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 | const auto list = req.family.splitRef(QLatin1Char(',')); | - | ||||||||||||||||||
| 701 | const int numFamilies = list.size(); | - | ||||||||||||||||||
| 702 | family_list.reserve(numFamilies); | - | ||||||||||||||||||
| 703 | for (int i = 0; i < numFamilies; ++i) {
| 0 | ||||||||||||||||||
| 704 | QStringRef 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 | for (int i = 0, size = family_list.size(); i < size; ++i)
| 0 | ||||||||||||||||||
| 713 | 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) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||||||||
| 719 | Q_GLOBAL_STATIC_WITH_ARGS(QMutex, fontDatabaseMutex, (QMutex::Recursive)) never executed: end of blocknever executed: guard.store(QtGlobalStatic::Destroyed);never executed: return &holder.value;
| 0 | ||||||||||||||||||
| 720 | - | |||||||||||||||||||
| 721 | // used in qguiapplication.cpp | - | ||||||||||||||||||
| 722 | void qt_cleanupFontDatabase() | - | ||||||||||||||||||
| 723 | { | - | ||||||||||||||||||
| 724 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||||||||
| 725 | if (db) {
| 0 | ||||||||||||||||||
| 726 | db->fallbacksCache.clear(); | - | ||||||||||||||||||
| 727 | db->free(); | - | ||||||||||||||||||
| 728 | } never executed: end of block | 0 | ||||||||||||||||||
| 729 | } never executed: end of block | 0 | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | // used in qfontengine_x11.cpp | - | ||||||||||||||||||
| 732 | QMutex *qt_fontdatabase_mutex() | - | ||||||||||||||||||
| 733 | { | - | ||||||||||||||||||
| 734 | return fontDatabaseMutex(); never executed: return fontDatabaseMutex(); | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 754 | if (writingSystems.supported(QFontDatabase::WritingSystem(i)))
| 0 | ||||||||||||||||||
| 755 | f->writingSystems[i] = QtFontFamily::Supported; never executed: f->writingSystems[i] = QtFontFamily::Supported; | 0 | ||||||||||||||||||
| 756 | } never executed: end of block | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 764 | QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||||||||
| 765 | if (integration)
| 0 | ||||||||||||||||||
| 766 | integration->fontDatabase()->releaseHandle(size->handle); never executed: integration->fontDatabase()->releaseHandle(size->handle); | 0 | ||||||||||||||||||
| 767 | } never executed: end of block | 0 | ||||||||||||||||||
| 768 | size->handle = handle; | - | ||||||||||||||||||
| 769 | f->populated = true; | - | ||||||||||||||||||
| 770 | } never executed: end of block | 0 | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | void qt_registerFontFamily(const QString &familyName) | - | ||||||||||||||||||
| 773 | { | - | ||||||||||||||||||
| 774 | // Create uninitialized/unpopulated family | - | ||||||||||||||||||
| 775 | privateDb()->family(familyName, QFontDatabasePrivate::EnsureCreated); | - | ||||||||||||||||||
| 776 | } never executed: end of block | 0 | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias) | - | ||||||||||||||||||
| 779 | { | - | ||||||||||||||||||
| 780 | if (alias.isEmpty())
| 0 | ||||||||||||||||||
| 781 | return; never executed: return; | 0 | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||||||||
| 784 | QtFontFamily *f = d->family(familyName, QFontDatabasePrivate::RequestFamily); | - | ||||||||||||||||||
| 785 | if (!f)
| 0 | ||||||||||||||||||
| 786 | return; never executed: return; | 0 | ||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | if (f->aliases.contains(alias, Qt::CaseInsensitive))
| 0 | ||||||||||||||||||
| 789 | return; never executed: return; | 0 | ||||||||||||||||||
| 790 | - | |||||||||||||||||||
| 791 | f->aliases.push_back(alias); | - | ||||||||||||||||||
| 792 | } never executed: end of block | 0 | ||||||||||||||||||
| 793 | - | |||||||||||||||||||
| 794 | QString qt_resolveFontFamilyAlias(const QString &alias) | - | ||||||||||||||||||
| 795 | { | - | ||||||||||||||||||
| 796 | if (!alias.isEmpty()) {
| 0 | ||||||||||||||||||
| 797 | const QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||||||||
| 798 | for (int i = 0; i < d->count; ++i)
| 0 | ||||||||||||||||||
| 799 | if (d->families[i]->matchesFamilyName(alias))
| 0 | ||||||||||||||||||
| 800 | return d->families[i]->name; never executed: return d->families[i]->name; | 0 | ||||||||||||||||||
| 801 | } never executed: end of block | 0 | ||||||||||||||||||
| 802 | return alias; never executed: return alias; | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 817 | writingSystem = QFontDatabase::Any; never executed: writingSystem = QFontDatabase::Any; | 0 | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||||||||
| 820 | for (int i = 0; i < db->count; ++i) {
| 0 | ||||||||||||||||||
| 821 | QtFontFamily *f = db->families[i]; | - | ||||||||||||||||||
| 822 | - | |||||||||||||||||||
| 823 | f->ensurePopulated(); | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | if (writingSystem > QFontDatabase::Any && f->writingSystems[writingSystem] != QtFontFamily::Supported)
| 0 | ||||||||||||||||||
| 826 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 827 | - | |||||||||||||||||||
| 828 | for (int j = 0; j < f->count; ++j) {
| 0 | ||||||||||||||||||
| 829 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 830 | - | |||||||||||||||||||
| 831 | for (int k = 0; k < foundry->count; ++k) {
| 0 | ||||||||||||||||||
| 832 | QString name = foundry->name.isEmpty()
| 0 | ||||||||||||||||||
| 833 | ? f->name | - | ||||||||||||||||||
| 834 | : f->name + QLatin1String(" [") + foundry->name + QLatin1Char(']'); | - | ||||||||||||||||||
| 835 | if (style == foundry->styles[k]->key.style)
| 0 | ||||||||||||||||||
| 836 | preferredFallbacks.append(name); never executed: preferredFallbacks.append(name); | 0 | ||||||||||||||||||
| 837 | else | - | ||||||||||||||||||
| 838 | otherFallbacks.append(name); never executed: otherFallbacks.append(name); | 0 | ||||||||||||||||||
| 839 | } | - | ||||||||||||||||||
| 840 | } never executed: end of block | 0 | ||||||||||||||||||
| 841 | } never executed: end of block | 0 | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | return preferredFallbacks + otherFallbacks; never executed: return preferredFallbacks + otherFallbacks; | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 852 | initializeDb(); never executed: initializeDb(); | 0 | ||||||||||||||||||
| 853 | - | |||||||||||||||||||
| 854 | const FallbacksCacheKey cacheKey = { family, style, styleHint, script }; | - | ||||||||||||||||||
| 855 | - | |||||||||||||||||||
| 856 | if (const QStringList *fallbacks = db->fallbacksCache.object(cacheKey))
| 0 | ||||||||||||||||||
| 857 | return *fallbacks; never executed: return *fallbacks; | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 864 | bool contains = false; | - | ||||||||||||||||||
| 865 | for (int j = 0; j < db->count; j++) {
| 0 | ||||||||||||||||||
| 866 | if (db->families[j]->matchesFamilyName(*i)) {
| 0 | ||||||||||||||||||
| 867 | contains = true; | - | ||||||||||||||||||
| 868 | break; never executed: break; | 0 | ||||||||||||||||||
| 869 | } | - | ||||||||||||||||||
| 870 | } never executed: end of block | 0 | ||||||||||||||||||
| 871 | if (!contains) {
| 0 | ||||||||||||||||||
| 872 | i = retList.erase(i); | - | ||||||||||||||||||
| 873 | --i; | - | ||||||||||||||||||
| 874 | } never executed: end of block | 0 | ||||||||||||||||||
| 875 | } never executed: end of block | 0 | ||||||||||||||||||
| 876 | - | |||||||||||||||||||
| 877 | db->fallbacksCache.insert(cacheKey, new QStringList(retList)); | - | ||||||||||||||||||
| 878 | - | |||||||||||||||||||
| 879 | return retList; never executed: return retList; | 0 | ||||||||||||||||||
| 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); never executed: return fallbacksForFamily(family, style, styleHint, script); | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 896 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); never executed: QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); | 0 | ||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | if (db->reregisterAppFonts) {
| 0 | ||||||||||||||||||
| 899 | for (int i = 0; i < db->applicationFonts.count(); i++) {
| 0 | ||||||||||||||||||
| 900 | if (!db->applicationFonts.at(i).families.isEmpty())
| 0 | ||||||||||||||||||
| 901 | registerFont(&db->applicationFonts[i]); never executed: registerFont(&db->applicationFonts[i]); | 0 | ||||||||||||||||||
| 902 | } never executed: end of block | 0 | ||||||||||||||||||
| 903 | db->reregisterAppFonts = false; | - | ||||||||||||||||||
| 904 | } never executed: end of block | 0 | ||||||||||||||||||
| 905 | } never executed: end of block | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 911 | initializeDb(); never executed: initializeDb(); | 0 | ||||||||||||||||||
| 912 | } never executed: end of block | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 926 | || pfdb->fontsAlwaysScalable()) {
| 0 | ||||||||||||||||||
| 927 | pixelSize = request.pixelSize; | - | ||||||||||||||||||
| 928 | } never executed: end of block | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 938 | const bool cacheForCommonScript = script != QChar::Script_Common
| 0 | ||||||||||||||||||
| 939 | && (family->writingSystems[QFontDatabase::Latin] & QtFontFamily::Supported) != 0;
| 0 | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | if (Q_LIKELY(cacheForCommonScript)) {
| 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 947 | // Also check for OpenType tables when using complex scripts | - | ||||||||||||||||||
| 948 | if (Q_UNLIKELY(!engine->supportsScript(QChar::Script(script)))) {
| 0 | ||||||||||||||||||
| 949 | qWarning(" OpenType support missing for script %d", script); | - | ||||||||||||||||||
| 950 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 951 | } | - | ||||||||||||||||||
| 952 | - | |||||||||||||||||||
| 953 | engine->isSmoothlyScalable = style->smoothScalable; | - | ||||||||||||||||||
| 954 | fontCache->insertEngine(key, engine); | - | ||||||||||||||||||
| 955 | return engine; never executed: return engine; | 0 | ||||||||||||||||||
| 956 | } | - | ||||||||||||||||||
| 957 | } never executed: end of block | 0 | ||||||||||||||||||
| 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
| 0 | ||||||||||||||||||
| 963 | && (request.styleName.isEmpty() || request.styleName != style->styleName)) {
| 0 | ||||||||||||||||||
| 964 | def.stretch = (request.stretch * 100 + 50) / style->key.stretch; | - | ||||||||||||||||||
| 965 | } never executed: end of block | 0 | ||||||||||||||||||
| 966 | - | |||||||||||||||||||
| 967 | engine = pfdb->fontEngine(def, size->handle); | - | ||||||||||||||||||
| 968 | if (engine) {
| 0 | ||||||||||||||||||
| 969 | // Also check for OpenType tables when using complex scripts | - | ||||||||||||||||||
| 970 | if (!engine->supportsScript(QChar::Script(script))) {
| 0 | ||||||||||||||||||
| 971 | qWarning(" OpenType support missing for script %d", script); | - | ||||||||||||||||||
| 972 | if (engine->ref.load() == 0)
| 0 | ||||||||||||||||||
| 973 | delete engine; never executed: delete engine; | 0 | ||||||||||||||||||
| 974 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 975 | } | - | ||||||||||||||||||
| 976 | - | |||||||||||||||||||
| 977 | engine->isSmoothlyScalable = style->smoothScalable; | - | ||||||||||||||||||
| 978 | fontCache->insertEngine(key, engine); | - | ||||||||||||||||||
| 979 | - | |||||||||||||||||||
| 980 | if (Q_LIKELY(cacheForCommonScript && !engine->symbol)) {
| 0 | ||||||||||||||||||
| 981 | // cache engine for Common script as well | - | ||||||||||||||||||
| 982 | key.script = QChar::Script_Common; | - | ||||||||||||||||||
| 983 | if (!fontCache->findEngine(key))
| 0 | ||||||||||||||||||
| 984 | fontCache->insertEngine(key, engine); never executed: fontCache->insertEngine(key, engine); | 0 | ||||||||||||||||||
| 985 | } never executed: end of block | 0 | ||||||||||||||||||
| 986 | } never executed: end of block | 0 | ||||||||||||||||||
| 987 | } never executed: end of block | 0 | ||||||||||||||||||
| 988 | return engine; never executed: return engine; | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 999 | QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); | - | ||||||||||||||||||
| 1000 | QFontEngineMulti *pfMultiEngine = pfdb->fontEngineMulti(engine, QChar::Script(script)); | - | ||||||||||||||||||
| 1001 | if (!request.fallBackFamilies.isEmpty()) {
| 0 | ||||||||||||||||||
| 1002 | QStringList fallbacks = request.fallBackFamilies; | - | ||||||||||||||||||
| 1003 | - | |||||||||||||||||||
| 1004 | QFont::StyleHint styleHint = QFont::StyleHint(request.styleHint); | - | ||||||||||||||||||
| 1005 | if (styleHint == QFont::AnyStyle && request.fixedPitch)
| 0 | ||||||||||||||||||
| 1006 | styleHint = QFont::TypeWriter; never executed: styleHint = QFont::TypeWriter; | 0 | ||||||||||||||||||
| 1007 | - | |||||||||||||||||||
| 1008 | fallbacks += fallbacksForFamily(family->name, QFont::Style(style->key.style), styleHint, QChar::Script(script)); | - | ||||||||||||||||||
| 1009 | - | |||||||||||||||||||
| 1010 | pfMultiEngine->setFallbackFamiliesList(fallbacks); | - | ||||||||||||||||||
| 1011 | } never executed: end of block | 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1019 | - | |||||||||||||||||||
| 1020 | return engine; never executed: return engine; | 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 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++ ) {
| 0 | ||||||||||||||||||
| 1039 | QtFontStyle *style = foundry->styles[i]; | - | ||||||||||||||||||
| 1040 | - | |||||||||||||||||||
| 1041 | if (!styleName.isEmpty() && styleName == style->styleName) {
| 0 | ||||||||||||||||||
| 1042 | dist = 0; | - | ||||||||||||||||||
| 1043 | best = i; | - | ||||||||||||||||||
| 1044 | break; never executed: break; | 0 | ||||||||||||||||||
| 1045 | } | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | int d = qAbs( styleKey.weight - style->key.weight ); | - | ||||||||||||||||||
| 1048 | - | |||||||||||||||||||
| 1049 | if ( styleKey.stretch != 0 && style->key.stretch != 0 ) {
| 0 | ||||||||||||||||||
| 1050 | d += qAbs( styleKey.stretch - style->key.stretch ); | - | ||||||||||||||||||
| 1051 | } never executed: end of block | 0 | ||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | if (styleKey.style != style->key.style) {
| 0 | ||||||||||||||||||
| 1054 | if (styleKey.style != QFont::StyleNormal && style->key.style != QFont::StyleNormal)
| 0 | ||||||||||||||||||
| 1055 | // one is italic, the other oblique | - | ||||||||||||||||||
| 1056 | d += 0x0001; never executed: d += 0x0001; | 0 | ||||||||||||||||||
| 1057 | else | - | ||||||||||||||||||
| 1058 | d += 0x1000; never executed: d += 0x1000; | 0 | ||||||||||||||||||
| 1059 | } | - | ||||||||||||||||||
| 1060 | - | |||||||||||||||||||
| 1061 | if ( d < dist ) {
| 0 | ||||||||||||||||||
| 1062 | best = i; | - | ||||||||||||||||||
| 1063 | dist = d; | - | ||||||||||||||||||
| 1064 | } never executed: end of block | 0 | ||||||||||||||||||
| 1065 | } never executed: end of block | 0 | ||||||||||||||||||
| 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]; never executed: return foundry->styles[best]; | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 1089 | QtFontFoundry *foundry = family->foundries[x]; | - | ||||||||||||||||||
| 1090 | if (!foundry_name.isEmpty() && foundry->name.compare(foundry_name, Qt::CaseInsensitive) != 0)
| 0 | ||||||||||||||||||
| 1091 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 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)) {
| 0 | ||||||||||||||||||
| 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; never executed: continue; | 0 | ||||||||||||||||||
| 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)) {
| 0 | ||||||||||||||||||
| 1108 | size = style->pixelSize(pixelSize); | - | ||||||||||||||||||
| 1109 | if (size) {
| 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1113 | } never executed: end of block | 0 | ||||||||||||||||||
| 1114 | - | |||||||||||||||||||
| 1115 | // 2. see if we have a smoothly scalable font | - | ||||||||||||||||||
| 1116 | if (!size && style->smoothScalable && ! (styleStrategy & QFont::PreferBitmap)) {
| 0 | ||||||||||||||||||
| 1117 | size = style->pixelSize(SMOOTH_SCALABLE); | - | ||||||||||||||||||
| 1118 | if (size) {
| 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1122 | } never executed: end of block | 0 | ||||||||||||||||||
| 1123 | - | |||||||||||||||||||
| 1124 | // 3. see if we have a bitmap scalable font | - | ||||||||||||||||||
| 1125 | if (!size && style->bitmapScalable && (styleStrategy & QFont::PreferMatch)) {
| 0 | ||||||||||||||||||
| 1126 | size = style->pixelSize(0); | - | ||||||||||||||||||
| 1127 | if (size) {
| 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1131 | } never executed: end of block | 0 | ||||||||||||||||||
| 1132 | - | |||||||||||||||||||
| 1133 | - | |||||||||||||||||||
| 1134 | // 4. find closest size match | - | ||||||||||||||||||
| 1135 | if (! size) {
| 0 | ||||||||||||||||||
| 1136 | unsigned int distance = ~0u; | - | ||||||||||||||||||
| 1137 | for (int x = 0; x < style->count; ++x) {
| 0 | ||||||||||||||||||
| 1138 | - | |||||||||||||||||||
| 1139 | unsigned int d; | - | ||||||||||||||||||
| 1140 | if (style->pixelSizes[x].pixelSize < pixelSize) {
| 0 | ||||||||||||||||||
| 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 { never executed: end of block | 0 | ||||||||||||||||||
| 1146 | d = style->pixelSizes[x].pixelSize - pixelSize; | - | ||||||||||||||||||
| 1147 | } never executed: end of block | 0 | ||||||||||||||||||
| 1148 | - | |||||||||||||||||||
| 1149 | if (d < distance) {
| 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1154 | } never executed: end of block | 0 | ||||||||||||||||||
| 1155 | - | |||||||||||||||||||
| 1156 | if (!size) {
| 0 | ||||||||||||||||||
| 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; never executed: continue; | 0 | ||||||||||||||||||
| 1159 | } | - | ||||||||||||||||||
| 1160 | - | |||||||||||||||||||
| 1161 | if (style->bitmapScalable && ! (styleStrategy & QFont::PreferQuality) &&
| 0 | ||||||||||||||||||
| 1162 | (distance * 10 / pixelSize) >= 2) {
| 0 | ||||||||||||||||||
| 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 { never executed: end of block | 0 | ||||||||||||||||||
| 1168 | px = size->pixelSize; | - | ||||||||||||||||||
| 1169 | } never executed: end of block | 0 | ||||||||||||||||||
| 1170 | } | - | ||||||||||||||||||
| 1171 | - | |||||||||||||||||||
| 1172 | - | |||||||||||||||||||
| 1173 | unsigned int this_score = 0x0000; | - | ||||||||||||||||||
| 1174 | enum { | - | ||||||||||||||||||
| 1175 | PitchMismatch = 0x4000, | - | ||||||||||||||||||
| 1176 | StyleMismatch = 0x2000, | - | ||||||||||||||||||
| 1177 | BitmapScaledPenalty = 0x1000 | - | ||||||||||||||||||
| 1178 | }; | - | ||||||||||||||||||
| 1179 | if (pitch != '*') {
| 0 | ||||||||||||||||||
| 1180 | if ((pitch == 'm' && !family->fixedPitch)
| 0 | ||||||||||||||||||
| 1181 | || (pitch == 'p' && family->fixedPitch))
| 0 | ||||||||||||||||||
| 1182 | this_score += PitchMismatch; never executed: this_score += PitchMismatch; | 0 | ||||||||||||||||||
| 1183 | } never executed: end of block | 0 | ||||||||||||||||||
| 1184 | if (styleKey != style->key)
| 0 | ||||||||||||||||||
| 1185 | this_score += StyleMismatch; never executed: this_score += StyleMismatch; | 0 | ||||||||||||||||||
| 1186 | if (!style->smoothScalable && px != size->pixelSize) // bitmap scaled
| 0 | ||||||||||||||||||
| 1187 | this_score += BitmapScaledPenalty; never executed: this_score += BitmapScaledPenalty; | 0 | ||||||||||||||||||
| 1188 | if (px != pixelSize) // close, but not exact, size match
| 0 | ||||||||||||||||||
| 1189 | this_score += qAbs(px - pixelSize); never executed: this_score += qAbs(px - pixelSize); | 0 | ||||||||||||||||||
| 1190 | - | |||||||||||||||||||
| 1191 | if (this_score < score) {
| 0 | ||||||||||||||||||
| 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 { never executed: end of block | 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1202 | } | - | ||||||||||||||||||
| 1203 | - | |||||||||||||||||||
| 1204 | return score; never executed: return score; | 0 | ||||||||||||||||||
| 1205 | } | - | ||||||||||||||||||
| 1206 | - | |||||||||||||||||||
| 1207 | static bool matchFamilyName(const QString &familyName, QtFontFamily *f) | - | ||||||||||||||||||
| 1208 | { | - | ||||||||||||||||||
| 1209 | if (familyName.isEmpty())
| 0 | ||||||||||||||||||
| 1210 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1211 | return f->matchesFamilyName(familyName); never executed: return f->matchesFamilyName(familyName); | 0 | ||||||||||||||||||
| 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';
| 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 1255 | writingSystem = QFontDatabase::Any; never executed: writingSystem = QFontDatabase::Any; | 0 | ||||||||||||||||||
| 1256 | - | |||||||||||||||||||
| 1257 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||||||||
| 1258 | for (int x = 0; x < db->count; ++x) {
| 0 | ||||||||||||||||||
| 1259 | if (blacklistedFamilies.contains(x))
| 0 | ||||||||||||||||||
| 1260 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1261 | QtFontDesc test; | - | ||||||||||||||||||
| 1262 | test.family = db->families[x]; | - | ||||||||||||||||||
| 1263 | - | |||||||||||||||||||
| 1264 | if (!matchFamilyName(family_name, test.family))
| 0 | ||||||||||||||||||
| 1265 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 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))
| 0 | ||||||||||||||||||
| 1271 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 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()) {
| 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1286 | - | |||||||||||||||||||
| 1287 | if (newscore < score) {
| 0 | ||||||||||||||||||
| 1288 | result = x; | - | ||||||||||||||||||
| 1289 | score = newscore; | - | ||||||||||||||||||
| 1290 | *desc = test; | - | ||||||||||||||||||
| 1291 | } never executed: end of block | 0 | ||||||||||||||||||
| 1292 | if (newscore < 10) // xlfd instead of FT... just accept it
| 0 | ||||||||||||||||||
| 1293 | break; never executed: break; | 0 | ||||||||||||||||||
| 1294 | } never executed: end of block | 0 | ||||||||||||||||||
| 1295 | return result; never executed: return result; | 0 | ||||||||||||||||||
| 1296 | } | - | ||||||||||||||||||
| 1297 | - | |||||||||||||||||||
| 1298 | static QString styleStringHelper(int weight, QFont::Style style) | - | ||||||||||||||||||
| 1299 | { | - | ||||||||||||||||||
| 1300 | QString result; | - | ||||||||||||||||||
| 1301 | if (weight > QFont::Normal) {
| 0 | ||||||||||||||||||
| 1302 | if (weight >= QFont::Black)
| 0 | ||||||||||||||||||
| 1303 | result = QCoreApplication::translate("QFontDatabase", "Black"); never executed: result = QCoreApplication::translate("QFontDatabase", "Black"); | 0 | ||||||||||||||||||
| 1304 | else if (weight >= QFont::ExtraBold)
| 0 | ||||||||||||||||||
| 1305 | result = QCoreApplication::translate("QFontDatabase", "Extra Bold"); never executed: result = QCoreApplication::translate("QFontDatabase", "Extra Bold"); | 0 | ||||||||||||||||||
| 1306 | else if (weight >= QFont::Bold)
| 0 | ||||||||||||||||||
| 1307 | result = QCoreApplication::translate("QFontDatabase", "Bold"); never executed: result = QCoreApplication::translate("QFontDatabase", "Bold"); | 0 | ||||||||||||||||||
| 1308 | else if (weight >= QFont::DemiBold)
| 0 | ||||||||||||||||||
| 1309 | result = QCoreApplication::translate("QFontDatabase", "Demi Bold"); never executed: result = QCoreApplication::translate("QFontDatabase", "Demi Bold"); | 0 | ||||||||||||||||||
| 1310 | else if (weight >= QFont::Medium)
| 0 | ||||||||||||||||||
| 1311 | result = QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"); never executed: result = QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"); | 0 | ||||||||||||||||||
| 1312 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1313 | if (weight <= QFont::Thin)
| 0 | ||||||||||||||||||
| 1314 | result = QCoreApplication::translate("QFontDatabase", "Thin"); never executed: result = QCoreApplication::translate("QFontDatabase", "Thin"); | 0 | ||||||||||||||||||
| 1315 | else if (weight <= QFont::ExtraLight)
| 0 | ||||||||||||||||||
| 1316 | result = QCoreApplication::translate("QFontDatabase", "Extra Light"); never executed: result = QCoreApplication::translate("QFontDatabase", "Extra Light"); | 0 | ||||||||||||||||||
| 1317 | else if (weight <= QFont::Light)
| 0 | ||||||||||||||||||
| 1318 | result = QCoreApplication::translate("QFontDatabase", "Light"); never executed: result = QCoreApplication::translate("QFontDatabase", "Light"); | 0 | ||||||||||||||||||
| 1319 | } never executed: end of block | 0 | ||||||||||||||||||
| 1320 | - | |||||||||||||||||||
| 1321 | if (style == QFont::StyleItalic)
| 0 | ||||||||||||||||||
| 1322 | result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Italic"); never executed: result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Italic"); | 0 | ||||||||||||||||||
| 1323 | else if (style == QFont::StyleOblique)
| 0 | ||||||||||||||||||
| 1324 | result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Oblique"); never executed: result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Oblique"); | 0 | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | if (result.isEmpty())
| 0 | ||||||||||||||||||
| 1327 | result = QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"); never executed: result = QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"); | 0 | ||||||||||||||||||
| 1328 | - | |||||||||||||||||||
| 1329 | return result.simplified(); never executed: return result.simplified(); | 0 | ||||||||||||||||||
| 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()) never executed: return font.styleName().isEmpty() ? styleStringHelper(font.weight(), font.style()) : font.styleName(); | 0 | ||||||||||||||||||
| 1340 | : font.styleName(); never executed: return font.styleName().isEmpty() ? styleStringHelper(font.weight(), font.style()) : font.styleName(); | 0 | ||||||||||||||||||
| 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()) never executed: return fontInfo.styleName().isEmpty() ? styleStringHelper(fontInfo.weight(), fontInfo.style()) : fontInfo.styleName(); | 0 | ||||||||||||||||||
| 1351 | : fontInfo.styleName(); never executed: return fontInfo.styleName().isEmpty() ? styleStringHelper(fontInfo.weight(), fontInfo.style()) : fontInfo.styleName(); | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 1490 | QtFontFamily *family = d->families[i]; | - | ||||||||||||||||||
| 1491 | family->ensurePopulated(); | - | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | if (family->count == 0)
| 0 | ||||||||||||||||||
| 1494 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1495 | for (uint x = Latin; x < uint(WritingSystemsCount); ++x) {
| 0 | ||||||||||||||||||
| 1496 | if (family->writingSystems[x] & QtFontFamily::Supported)
| 0 | ||||||||||||||||||
| 1497 | writingSystemsFound |= quint64(1) << x; never executed: writingSystemsFound |= quint64(1) << x; | 0 | ||||||||||||||||||
| 1498 | } never executed: end of block | 0 | ||||||||||||||||||
| 1499 | } never executed: end of block | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 1507 | if (writingSystemsFound & (quint64(1) << x))
| 0 | ||||||||||||||||||
| 1508 | list.push_back(WritingSystem(x)); never executed: list.push_back(WritingSystem(x)); | 0 | ||||||||||||||||||
| 1509 | } never executed: end of block | 0 | ||||||||||||||||||
| 1510 | return list; never executed: return list; | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 1532 | return list; never executed: return list; | 0 | ||||||||||||||||||
| 1533 | - | |||||||||||||||||||
| 1534 | for (int x = Latin; x < WritingSystemsCount; ++x) {
| 0 | ||||||||||||||||||
| 1535 | const WritingSystem writingSystem = WritingSystem(x); | - | ||||||||||||||||||
| 1536 | if (f->writingSystems[writingSystem] & QtFontFamily::Supported)
| 0 | ||||||||||||||||||
| 1537 | list.append(writingSystem); never executed: list.append(writingSystem); | 0 | ||||||||||||||||||
| 1538 | } never executed: end of block | 0 | ||||||||||||||||||
| 1539 | return list; never executed: return list; | 0 | ||||||||||||||||||
| 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++) {
| 0 | ||||||||||||||||||
| 1561 | QtFontFamily *f = d->families[i]; | - | ||||||||||||||||||
| 1562 | if (f->populated && f->count == 0)
| 0 | ||||||||||||||||||
| 1563 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1564 | if (writingSystem != Any) {
| 0 | ||||||||||||||||||
| 1565 | f->ensurePopulated(); | - | ||||||||||||||||||
| 1566 | if (f->writingSystems[writingSystem] != QtFontFamily::Supported)
| 0 | ||||||||||||||||||
| 1567 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1568 | } never executed: end of block | 0 | ||||||||||||||||||
| 1569 | if (!f->populated || f->count == 1) {
| 0 | ||||||||||||||||||
| 1570 | flist.append(f->name); | - | ||||||||||||||||||
| 1571 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1572 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1573 | QString str = f->name; | - | ||||||||||||||||||
| 1574 | QString foundry = f->foundries[j]->name; | - | ||||||||||||||||||
| 1575 | if (!foundry.isEmpty()) {
| 0 | ||||||||||||||||||
| 1576 | str += QLatin1String(" ["); | - | ||||||||||||||||||
| 1577 | str += foundry; | - | ||||||||||||||||||
| 1578 | str += QLatin1Char(']'); | - | ||||||||||||||||||
| 1579 | } never executed: end of block | 0 | ||||||||||||||||||
| 1580 | flist.append(str); | - | ||||||||||||||||||
| 1581 | } never executed: end of block | 0 | ||||||||||||||||||
| 1582 | } never executed: end of block | 0 | ||||||||||||||||||
| 1583 | } | - | ||||||||||||||||||
| 1584 | return flist; never executed: return flist; | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 1606 | return l; never executed: return l; | 0 | ||||||||||||||||||
| 1607 | - | |||||||||||||||||||
| 1608 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||||||||
| 1609 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1610 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 1611 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1612 | for (int k = 0; k < foundry->count; k++) {
| 0 | ||||||||||||||||||
| 1613 | QtFontStyle::Key ke(foundry->styles[k]->key); | - | ||||||||||||||||||
| 1614 | ke.stretch = 0; | - | ||||||||||||||||||
| 1615 | allStyles.style(ke, foundry->styles[k]->styleName, true); | - | ||||||||||||||||||
| 1616 | } never executed: end of block | 0 | ||||||||||||||||||
| 1617 | } never executed: end of block | 0 | ||||||||||||||||||
| 1618 | } never executed: end of block | 0 | ||||||||||||||||||
| 1619 | - | |||||||||||||||||||
| 1620 | l.reserve(allStyles.count); | - | ||||||||||||||||||
| 1621 | for (int i = 0; i < allStyles.count; i++) {
| 0 | ||||||||||||||||||
| 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 | } never executed: end of block | 0 | ||||||||||||||||||
| 1627 | return l; never executed: return l; | 0 | ||||||||||||||||||
| 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); never executed: return (f && f->fixedPitch); | 0 | ||||||||||||||||||
| 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; never executed: return bitmapScalable;
| 0 | ||||||||||||||||||
| 1674 | - | |||||||||||||||||||
| 1675 | QtFontStyle::Key styleKey(style); | - | ||||||||||||||||||
| 1676 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1677 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 1678 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1679 | for (int k = 0; k < foundry->count; k++)
| 0 | ||||||||||||||||||
| 1680 | if ((style.isEmpty() ||
| 0 | ||||||||||||||||||
| 1681 | foundry->styles[k]->styleName == style ||
| 0 | ||||||||||||||||||
| 1682 | foundry->styles[k]->key == styleKey)
| 0 | ||||||||||||||||||
| 1683 | && foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) {
| 0 | ||||||||||||||||||
| 1684 | bitmapScalable = true; | - | ||||||||||||||||||
| 1685 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||
| 1687 | } never executed: end of block | 0 | ||||||||||||||||||
| 1688 | } never executed: end of block | 0 | ||||||||||||||||||
| 1689 | end: code before this statement never executed: end: | 0 | ||||||||||||||||||
| 1690 | return bitmapScalable; never executed: return bitmapScalable; | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 1714 | for (int i = 0; i < d->count; i++) {
| 0 | ||||||||||||||||||
| 1715 | if (d->families[i]->matchesFamilyName(familyName)) {
| 0 | ||||||||||||||||||
| 1716 | f = d->families[i]; | - | ||||||||||||||||||
| 1717 | f->ensurePopulated(); | - | ||||||||||||||||||
| 1718 | break; never executed: break; | 0 | ||||||||||||||||||
| 1719 | } | - | ||||||||||||||||||
| 1720 | } never executed: end of block | 0 | ||||||||||||||||||
| 1721 | } never executed: end of block | 0 | ||||||||||||||||||
| 1722 | if (!f) return smoothScalable; never executed: return smoothScalable;
| 0 | ||||||||||||||||||
| 1723 | - | |||||||||||||||||||
| 1724 | QtFontStyle::Key styleKey(style); | - | ||||||||||||||||||
| 1725 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1726 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 1727 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1728 | for (int k = 0; k < foundry->count; k++)
| 0 | ||||||||||||||||||
| 1729 | if ((style.isEmpty() ||
| 0 | ||||||||||||||||||
| 1730 | foundry->styles[k]->styleName == style ||
| 0 | ||||||||||||||||||
| 1731 | foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) {
| 0 | ||||||||||||||||||
| 1732 | smoothScalable = true; | - | ||||||||||||||||||
| 1733 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 1734 | } | - | ||||||||||||||||||
| 1735 | } never executed: end of block | 0 | ||||||||||||||||||
| 1736 | } never executed: end of block | 0 | ||||||||||||||||||
| 1737 | end: code before this statement never executed: end: | 0 | ||||||||||||||||||
| 1738 | return smoothScalable; never executed: return smoothScalable; | 0 | ||||||||||||||||||
| 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))
| 0 | ||||||||||||||||||
| 1752 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 1753 | return isBitmapScalable(family, style); never executed: return isBitmapScalable(family, style); | 0 | ||||||||||||||||||
| 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())
| 0 | ||||||||||||||||||
| 1767 | return standardSizes(); never executed: return standardSizes(); | 0 | ||||||||||||||||||
| 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; never executed: return sizes;
| 0 | ||||||||||||||||||
| 1781 | - | |||||||||||||||||||
| 1782 | - | |||||||||||||||||||
| 1783 | const int dpi = qt_defaultDpiY(); // embedded | - | ||||||||||||||||||
| 1784 | - | |||||||||||||||||||
| 1785 | QtFontStyle::Key styleKey(styleName); | - | ||||||||||||||||||
| 1786 | for (int j = 0; j < fam->count; j++) {
| 0 | ||||||||||||||||||
| 1787 | QtFontFoundry *foundry = fam->foundries[j]; | - | ||||||||||||||||||
| 1788 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1789 | QtFontStyle *style = foundry->style(styleKey, styleName); | - | ||||||||||||||||||
| 1790 | if (!style) continue; never executed: continue;
| 0 | ||||||||||||||||||
| 1791 | - | |||||||||||||||||||
| 1792 | if (style->smoothScalable) {
| 0 | ||||||||||||||||||
| 1793 | smoothScalable = true; | - | ||||||||||||||||||
| 1794 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 1795 | } | - | ||||||||||||||||||
| 1796 | for (int l = 0; l < style->count; l++) {
| 0 | ||||||||||||||||||
| 1797 | const QtFontSize *size = style->pixelSizes + l; | - | ||||||||||||||||||
| 1798 | - | |||||||||||||||||||
| 1799 | if (size->pixelSize != 0 && size->pixelSize != SMOOTH_SCALABLE) {
| 0 | ||||||||||||||||||
| 1800 | const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); | - | ||||||||||||||||||
| 1801 | if (! sizes.contains(pointSize))
| 0 | ||||||||||||||||||
| 1802 | sizes.append(pointSize); never executed: sizes.append(pointSize); | 0 | ||||||||||||||||||
| 1803 | } never executed: end of block | 0 | ||||||||||||||||||
| 1804 | } never executed: end of block | 0 | ||||||||||||||||||
| 1805 | } never executed: end of block | 0 | ||||||||||||||||||
| 1806 | } never executed: end of block | 0 | ||||||||||||||||||
| 1807 | end: code before this statement never executed: end: | 0 | ||||||||||||||||||
| 1808 | if (smoothScalable)
| 0 | ||||||||||||||||||
| 1809 | return standardSizes(); never executed: return standardSizes(); | 0 | ||||||||||||||||||
| 1810 | - | |||||||||||||||||||
| 1811 | std::sort(sizes.begin(), sizes.end()); | - | ||||||||||||||||||
| 1812 | return sizes; never executed: return sizes; | 0 | ||||||||||||||||||
| 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(); never executed: return QGuiApplication::font();
| 0 | ||||||||||||||||||
| 1834 | - | |||||||||||||||||||
| 1835 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1836 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 1837 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1838 | for (int k = 0; k < foundry->count; k++)
| 0 | ||||||||||||||||||
| 1839 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); never executed: allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | 0 | ||||||||||||||||||
| 1840 | } never executed: end of block | 0 | ||||||||||||||||||
| 1841 | } never executed: end of block | 0 | ||||||||||||||||||
| 1842 | - | |||||||||||||||||||
| 1843 | QtFontStyle::Key styleKey(style); | - | ||||||||||||||||||
| 1844 | QtFontStyle *s = bestStyle(&allStyles, styleKey, style); | - | ||||||||||||||||||
| 1845 | - | |||||||||||||||||||
| 1846 | if (!s) // no styles found?
| 0 | ||||||||||||||||||
| 1847 | return QGuiApplication::font(); never executed: return QGuiApplication::font(); | 0 | ||||||||||||||||||
| 1848 | - | |||||||||||||||||||
| 1849 | QFont fnt(family, pointSize, s->key.weight); | - | ||||||||||||||||||
| 1850 | fnt.setStyle((QFont::Style)s->key.style); | - | ||||||||||||||||||
| 1851 | if (!s->styleName.isEmpty())
| 0 | ||||||||||||||||||
| 1852 | fnt.setStyleName(s->styleName); never executed: fnt.setStyleName(s->styleName); | 0 | ||||||||||||||||||
| 1853 | return fnt; never executed: return fnt; | 0 | ||||||||||||||||||
| 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())
| 0 | ||||||||||||||||||
| 1869 | return standardSizes(); never executed: return standardSizes(); | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 1883 | return sizes; never executed: return sizes; | 0 | ||||||||||||||||||
| 1884 | - | |||||||||||||||||||
| 1885 | const int dpi = qt_defaultDpiY(); // embedded | - | ||||||||||||||||||
| 1886 | - | |||||||||||||||||||
| 1887 | QtFontStyle::Key styleKey(styleName); | - | ||||||||||||||||||
| 1888 | for (int j = 0; j < fam->count; j++) {
| 0 | ||||||||||||||||||
| 1889 | QtFontFoundry *foundry = fam->foundries[j]; | - | ||||||||||||||||||
| 1890 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1891 | QtFontStyle *style = foundry->style(styleKey, styleName); | - | ||||||||||||||||||
| 1892 | if (!style) continue; never executed: continue;
| 0 | ||||||||||||||||||
| 1893 | - | |||||||||||||||||||
| 1894 | if (style->smoothScalable) {
| 0 | ||||||||||||||||||
| 1895 | smoothScalable = true; | - | ||||||||||||||||||
| 1896 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 1897 | } | - | ||||||||||||||||||
| 1898 | for (int l = 0; l < style->count; l++) {
| 0 | ||||||||||||||||||
| 1899 | const QtFontSize *size = style->pixelSizes + l; | - | ||||||||||||||||||
| 1900 | - | |||||||||||||||||||
| 1901 | if (size->pixelSize != 0 && size->pixelSize != SMOOTH_SCALABLE) {
| 0 | ||||||||||||||||||
| 1902 | const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); | - | ||||||||||||||||||
| 1903 | if (! sizes.contains(pointSize))
| 0 | ||||||||||||||||||
| 1904 | sizes.append(pointSize); never executed: sizes.append(pointSize); | 0 | ||||||||||||||||||
| 1905 | } never executed: end of block | 0 | ||||||||||||||||||
| 1906 | } never executed: end of block | 0 | ||||||||||||||||||
| 1907 | } never executed: end of block | 0 | ||||||||||||||||||
| 1908 | } never executed: end of block | 0 | ||||||||||||||||||
| 1909 | end: code before this statement never executed: end: | 0 | ||||||||||||||||||
| 1910 | if (smoothScalable)
| 0 | ||||||||||||||||||
| 1911 | return QFontDatabase::standardSizes(); never executed: return QFontDatabase::standardSizes(); | 0 | ||||||||||||||||||
| 1912 | - | |||||||||||||||||||
| 1913 | std::sort(sizes.begin(), sizes.end()); | - | ||||||||||||||||||
| 1914 | return sizes; never executed: return sizes; | 0 | ||||||||||||||||||
| 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(); never executed: return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->standardSizes(); | 0 | ||||||||||||||||||
| 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; never executed: return false;
| 0 | ||||||||||||||||||
| 1947 | - | |||||||||||||||||||
| 1948 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1949 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 1950 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1951 | for (int k = 0; k < foundry->count; k++)
| 0 | ||||||||||||||||||
| 1952 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); never executed: allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | 0 | ||||||||||||||||||
| 1953 | } never executed: end of block | 0 | ||||||||||||||||||
| 1954 | } never executed: end of block | 0 | ||||||||||||||||||
| 1955 | - | |||||||||||||||||||
| 1956 | QtFontStyle::Key styleKey(style); | - | ||||||||||||||||||
| 1957 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||||||||
| 1958 | return s && s->key.style == QFont::StyleItalic; never executed: return s && s->key.style == QFont::StyleItalic; | 0 | ||||||||||||||||||
| 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; never executed: return false;
| 0 | ||||||||||||||||||
| 1981 | - | |||||||||||||||||||
| 1982 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 1983 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 1984 | if (foundryName.isEmpty() ||
| 0 | ||||||||||||||||||
| 1985 | foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 1986 | for (int k = 0; k < foundry->count; k++)
| 0 | ||||||||||||||||||
| 1987 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); never executed: allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | 0 | ||||||||||||||||||
| 1988 | } never executed: end of block | 0 | ||||||||||||||||||
| 1989 | } never executed: end of block | 0 | ||||||||||||||||||
| 1990 | - | |||||||||||||||||||
| 1991 | QtFontStyle::Key styleKey(style); | - | ||||||||||||||||||
| 1992 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||||||||
| 1993 | return s && s->key.weight >= QFont::Bold; never executed: return s && s->key.weight >= QFont::Bold; | 0 | ||||||||||||||||||
| 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; never executed: return -1;
| 0 | ||||||||||||||||||
| 2017 | - | |||||||||||||||||||
| 2018 | for (int j = 0; j < f->count; j++) {
| 0 | ||||||||||||||||||
| 2019 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||||||||
| 2020 | if (foundryName.isEmpty() ||
| 0 | ||||||||||||||||||
| 2021 | foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) {
| 0 | ||||||||||||||||||
| 2022 | for (int k = 0; k < foundry->count; k++)
| 0 | ||||||||||||||||||
| 2023 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); never executed: allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | 0 | ||||||||||||||||||
| 2024 | } never executed: end of block | 0 | ||||||||||||||||||
| 2025 | } never executed: end of block | 0 | ||||||||||||||||||
| 2026 | - | |||||||||||||||||||
| 2027 | QtFontStyle::Key styleKey(style); | - | ||||||||||||||||||
| 2028 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||||||||
| 2029 | return s ? s->key.weight : -1; never executed: return s ? s->key.weight : -1; | 0 | ||||||||||||||||||
| 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); never executed: return families().contains(familyAlias, Qt::CaseInsensitive); | 0 | ||||||||||||||||||
| 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); never executed: return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->isPrivateFontFamily(family); | 0 | ||||||||||||||||||
| 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: never executed: case Any: | 0 | ||||||||||||||||||
| 2070 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Any"); | - | ||||||||||||||||||
| 2071 | break; never executed: break; | 0 | ||||||||||||||||||
| 2072 | case Latin: never executed: case Latin: | 0 | ||||||||||||||||||
| 2073 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Latin"); | - | ||||||||||||||||||
| 2074 | break; never executed: break; | 0 | ||||||||||||||||||
| 2075 | case Greek: never executed: case Greek: | 0 | ||||||||||||||||||
| 2076 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Greek"); | - | ||||||||||||||||||
| 2077 | break; never executed: break; | 0 | ||||||||||||||||||
| 2078 | case Cyrillic: never executed: case Cyrillic: | 0 | ||||||||||||||||||
| 2079 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Cyrillic"); | - | ||||||||||||||||||
| 2080 | break; never executed: break; | 0 | ||||||||||||||||||
| 2081 | case Armenian: never executed: case Armenian: | 0 | ||||||||||||||||||
| 2082 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Armenian"); | - | ||||||||||||||||||
| 2083 | break; never executed: break; | 0 | ||||||||||||||||||
| 2084 | case Hebrew: never executed: case Hebrew: | 0 | ||||||||||||||||||
| 2085 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Hebrew"); | - | ||||||||||||||||||
| 2086 | break; never executed: break; | 0 | ||||||||||||||||||
| 2087 | case Arabic: never executed: case Arabic: | 0 | ||||||||||||||||||
| 2088 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Arabic"); | - | ||||||||||||||||||
| 2089 | break; never executed: break; | 0 | ||||||||||||||||||
| 2090 | case Syriac: never executed: case Syriac: | 0 | ||||||||||||||||||
| 2091 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Syriac"); | - | ||||||||||||||||||
| 2092 | break; never executed: break; | 0 | ||||||||||||||||||
| 2093 | case Thaana: never executed: case Thaana: | 0 | ||||||||||||||||||
| 2094 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Thaana"); | - | ||||||||||||||||||
| 2095 | break; never executed: break; | 0 | ||||||||||||||||||
| 2096 | case Devanagari: never executed: case Devanagari: | 0 | ||||||||||||||||||
| 2097 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Devanagari"); | - | ||||||||||||||||||
| 2098 | break; never executed: break; | 0 | ||||||||||||||||||
| 2099 | case Bengali: never executed: case Bengali: | 0 | ||||||||||||||||||
| 2100 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Bengali"); | - | ||||||||||||||||||
| 2101 | break; never executed: break; | 0 | ||||||||||||||||||
| 2102 | case Gurmukhi: never executed: case Gurmukhi: | 0 | ||||||||||||||||||
| 2103 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Gurmukhi"); | - | ||||||||||||||||||
| 2104 | break; never executed: break; | 0 | ||||||||||||||||||
| 2105 | case Gujarati: never executed: case Gujarati: | 0 | ||||||||||||||||||
| 2106 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Gujarati"); | - | ||||||||||||||||||
| 2107 | break; never executed: break; | 0 | ||||||||||||||||||
| 2108 | case Oriya: never executed: case Oriya: | 0 | ||||||||||||||||||
| 2109 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Oriya"); | - | ||||||||||||||||||
| 2110 | break; never executed: break; | 0 | ||||||||||||||||||
| 2111 | case Tamil: never executed: case Tamil: | 0 | ||||||||||||||||||
| 2112 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Tamil"); | - | ||||||||||||||||||
| 2113 | break; never executed: break; | 0 | ||||||||||||||||||
| 2114 | case Telugu: never executed: case Telugu: | 0 | ||||||||||||||||||
| 2115 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Telugu"); | - | ||||||||||||||||||
| 2116 | break; never executed: break; | 0 | ||||||||||||||||||
| 2117 | case Kannada: never executed: case Kannada: | 0 | ||||||||||||||||||
| 2118 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Kannada"); | - | ||||||||||||||||||
| 2119 | break; never executed: break; | 0 | ||||||||||||||||||
| 2120 | case Malayalam: never executed: case Malayalam: | 0 | ||||||||||||||||||
| 2121 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Malayalam"); | - | ||||||||||||||||||
| 2122 | break; never executed: break; | 0 | ||||||||||||||||||
| 2123 | case Sinhala: never executed: case Sinhala: | 0 | ||||||||||||||||||
| 2124 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Sinhala"); | - | ||||||||||||||||||
| 2125 | break; never executed: break; | 0 | ||||||||||||||||||
| 2126 | case Thai: never executed: case Thai: | 0 | ||||||||||||||||||
| 2127 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Thai"); | - | ||||||||||||||||||
| 2128 | break; never executed: break; | 0 | ||||||||||||||||||
| 2129 | case Lao: never executed: case Lao: | 0 | ||||||||||||||||||
| 2130 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Lao"); | - | ||||||||||||||||||
| 2131 | break; never executed: break; | 0 | ||||||||||||||||||
| 2132 | case Tibetan: never executed: case Tibetan: | 0 | ||||||||||||||||||
| 2133 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Tibetan"); | - | ||||||||||||||||||
| 2134 | break; never executed: break; | 0 | ||||||||||||||||||
| 2135 | case Myanmar: never executed: case Myanmar: | 0 | ||||||||||||||||||
| 2136 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Myanmar"); | - | ||||||||||||||||||
| 2137 | break; never executed: break; | 0 | ||||||||||||||||||
| 2138 | case Georgian: never executed: case Georgian: | 0 | ||||||||||||||||||
| 2139 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Georgian"); | - | ||||||||||||||||||
| 2140 | break; never executed: break; | 0 | ||||||||||||||||||
| 2141 | case Khmer: never executed: case Khmer: | 0 | ||||||||||||||||||
| 2142 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Khmer"); | - | ||||||||||||||||||
| 2143 | break; never executed: break; | 0 | ||||||||||||||||||
| 2144 | case SimplifiedChinese: never executed: case SimplifiedChinese: | 0 | ||||||||||||||||||
| 2145 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Simplified Chinese"); | - | ||||||||||||||||||
| 2146 | break; never executed: break; | 0 | ||||||||||||||||||
| 2147 | case TraditionalChinese: never executed: case TraditionalChinese: | 0 | ||||||||||||||||||
| 2148 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Traditional Chinese"); | - | ||||||||||||||||||
| 2149 | break; never executed: break; | 0 | ||||||||||||||||||
| 2150 | case Japanese: never executed: case Japanese: | 0 | ||||||||||||||||||
| 2151 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Japanese"); | - | ||||||||||||||||||
| 2152 | break; never executed: break; | 0 | ||||||||||||||||||
| 2153 | case Korean: never executed: case Korean: | 0 | ||||||||||||||||||
| 2154 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Korean"); | - | ||||||||||||||||||
| 2155 | break; never executed: break; | 0 | ||||||||||||||||||
| 2156 | case Vietnamese: never executed: case Vietnamese: | 0 | ||||||||||||||||||
| 2157 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Vietnamese"); | - | ||||||||||||||||||
| 2158 | break; never executed: break; | 0 | ||||||||||||||||||
| 2159 | case Symbol: never executed: case Symbol: | 0 | ||||||||||||||||||
| 2160 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Symbol"); | - | ||||||||||||||||||
| 2161 | break; never executed: break; | 0 | ||||||||||||||||||
| 2162 | case Ogham: never executed: case Ogham: | 0 | ||||||||||||||||||
| 2163 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Ogham"); | - | ||||||||||||||||||
| 2164 | break; never executed: break; | 0 | ||||||||||||||||||
| 2165 | case Runic: never executed: case Runic: | 0 | ||||||||||||||||||
| 2166 | name = QT_TRANSLATE_NOOP("QFontDatabase", "Runic"); | - | ||||||||||||||||||
| 2167 | break; never executed: break; | 0 | ||||||||||||||||||
| 2168 | case Nko: never executed: case Nko: | 0 | ||||||||||||||||||
| 2169 | name = QT_TRANSLATE_NOOP("QFontDatabase", "N'Ko"); | - | ||||||||||||||||||
| 2170 | break; never executed: break; | 0 | ||||||||||||||||||
| 2171 | default: never executed: default: | 0 | ||||||||||||||||||
| 2172 | Q_ASSERT_X(false, "QFontDatabase::writingSystemName", "invalid 'writingSystem' parameter"); | - | ||||||||||||||||||
| 2173 | break; never executed: break; | 0 | ||||||||||||||||||
| 2174 | } | - | ||||||||||||||||||
| 2175 | return QCoreApplication::translate("QFontDatabase", name); never executed: return QCoreApplication::translate("QFontDatabase", name); | 0 | ||||||||||||||||||
| 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: never executed: case Any: | 0 | ||||||||||||||||||
| 2187 | case Symbol: never executed: case Symbol: | 0 | ||||||||||||||||||
| 2188 | // show only ascii characters | - | ||||||||||||||||||
| 2189 | sample += QLatin1String("AaBbzZ"); | - | ||||||||||||||||||
| 2190 | break; never executed: break; | 0 | ||||||||||||||||||
| 2191 | case Latin: never executed: case Latin: | 0 | ||||||||||||||||||
| 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; never executed: break; | 0 | ||||||||||||||||||
| 2199 | case Greek: never executed: case Greek: | 0 | ||||||||||||||||||
| 2200 | sample += QChar(0x0393); | - | ||||||||||||||||||
| 2201 | sample += QChar(0x03B1); | - | ||||||||||||||||||
| 2202 | sample += QChar(0x03A9); | - | ||||||||||||||||||
| 2203 | sample += QChar(0x03C9); | - | ||||||||||||||||||
| 2204 | break; never executed: break; | 0 | ||||||||||||||||||
| 2205 | case Cyrillic: never executed: case Cyrillic: | 0 | ||||||||||||||||||
| 2206 | sample += QChar(0x0414); | - | ||||||||||||||||||
| 2207 | sample += QChar(0x0434); | - | ||||||||||||||||||
| 2208 | sample += QChar(0x0436); | - | ||||||||||||||||||
| 2209 | sample += QChar(0x044f); | - | ||||||||||||||||||
| 2210 | break; never executed: break; | 0 | ||||||||||||||||||
| 2211 | case Armenian: never executed: case Armenian: | 0 | ||||||||||||||||||
| 2212 | sample += QChar(0x053f); | - | ||||||||||||||||||
| 2213 | sample += QChar(0x054f); | - | ||||||||||||||||||
| 2214 | sample += QChar(0x056f); | - | ||||||||||||||||||
| 2215 | sample += QChar(0x057f); | - | ||||||||||||||||||
| 2216 | break; never executed: break; | 0 | ||||||||||||||||||
| 2217 | case Hebrew: never executed: case Hebrew: | 0 | ||||||||||||||||||
| 2218 | sample += QChar(0x05D0); | - | ||||||||||||||||||
| 2219 | sample += QChar(0x05D1); | - | ||||||||||||||||||
| 2220 | sample += QChar(0x05D2); | - | ||||||||||||||||||
| 2221 | sample += QChar(0x05D3); | - | ||||||||||||||||||
| 2222 | break; never executed: break; | 0 | ||||||||||||||||||
| 2223 | case Arabic: never executed: case Arabic: | 0 | ||||||||||||||||||
| 2224 | sample += QChar(0x0628); | - | ||||||||||||||||||
| 2225 | sample += QChar(0x0629); | - | ||||||||||||||||||
| 2226 | sample += QChar(0x062A); | - | ||||||||||||||||||
| 2227 | sample += QChar(0x063A); | - | ||||||||||||||||||
| 2228 | break; never executed: break; | 0 | ||||||||||||||||||
| 2229 | case Syriac: never executed: case Syriac: | 0 | ||||||||||||||||||
| 2230 | sample += QChar(0x0715); | - | ||||||||||||||||||
| 2231 | sample += QChar(0x0725); | - | ||||||||||||||||||
| 2232 | sample += QChar(0x0716); | - | ||||||||||||||||||
| 2233 | sample += QChar(0x0726); | - | ||||||||||||||||||
| 2234 | break; never executed: break; | 0 | ||||||||||||||||||
| 2235 | case Thaana: never executed: case Thaana: | 0 | ||||||||||||||||||
| 2236 | sample += QChar(0x0784); | - | ||||||||||||||||||
| 2237 | sample += QChar(0x0794); | - | ||||||||||||||||||
| 2238 | sample += QChar(0x078c); | - | ||||||||||||||||||
| 2239 | sample += QChar(0x078d); | - | ||||||||||||||||||
| 2240 | break; never executed: break; | 0 | ||||||||||||||||||
| 2241 | case Devanagari: never executed: case Devanagari: | 0 | ||||||||||||||||||
| 2242 | sample += QChar(0x0905); | - | ||||||||||||||||||
| 2243 | sample += QChar(0x0915); | - | ||||||||||||||||||
| 2244 | sample += QChar(0x0925); | - | ||||||||||||||||||
| 2245 | sample += QChar(0x0935); | - | ||||||||||||||||||
| 2246 | break; never executed: break; | 0 | ||||||||||||||||||
| 2247 | case Bengali: never executed: case Bengali: | 0 | ||||||||||||||||||
| 2248 | sample += QChar(0x0986); | - | ||||||||||||||||||
| 2249 | sample += QChar(0x0996); | - | ||||||||||||||||||
| 2250 | sample += QChar(0x09a6); | - | ||||||||||||||||||
| 2251 | sample += QChar(0x09b6); | - | ||||||||||||||||||
| 2252 | break; never executed: break; | 0 | ||||||||||||||||||
| 2253 | case Gurmukhi: never executed: case Gurmukhi: | 0 | ||||||||||||||||||
| 2254 | sample += QChar(0x0a05); | - | ||||||||||||||||||
| 2255 | sample += QChar(0x0a15); | - | ||||||||||||||||||
| 2256 | sample += QChar(0x0a25); | - | ||||||||||||||||||
| 2257 | sample += QChar(0x0a35); | - | ||||||||||||||||||
| 2258 | break; never executed: break; | 0 | ||||||||||||||||||
| 2259 | case Gujarati: never executed: case Gujarati: | 0 | ||||||||||||||||||
| 2260 | sample += QChar(0x0a85); | - | ||||||||||||||||||
| 2261 | sample += QChar(0x0a95); | - | ||||||||||||||||||
| 2262 | sample += QChar(0x0aa5); | - | ||||||||||||||||||
| 2263 | sample += QChar(0x0ab5); | - | ||||||||||||||||||
| 2264 | break; never executed: break; | 0 | ||||||||||||||||||
| 2265 | case Oriya: never executed: case Oriya: | 0 | ||||||||||||||||||
| 2266 | sample += QChar(0x0b06); | - | ||||||||||||||||||
| 2267 | sample += QChar(0x0b16); | - | ||||||||||||||||||
| 2268 | sample += QChar(0x0b2b); | - | ||||||||||||||||||
| 2269 | sample += QChar(0x0b36); | - | ||||||||||||||||||
| 2270 | break; never executed: break; | 0 | ||||||||||||||||||
| 2271 | case Tamil: never executed: case Tamil: | 0 | ||||||||||||||||||
| 2272 | sample += QChar(0x0b89); | - | ||||||||||||||||||
| 2273 | sample += QChar(0x0b99); | - | ||||||||||||||||||
| 2274 | sample += QChar(0x0ba9); | - | ||||||||||||||||||
| 2275 | sample += QChar(0x0bb9); | - | ||||||||||||||||||
| 2276 | break; never executed: break; | 0 | ||||||||||||||||||
| 2277 | case Telugu: never executed: case Telugu: | 0 | ||||||||||||||||||
| 2278 | sample += QChar(0x0c05); | - | ||||||||||||||||||
| 2279 | sample += QChar(0x0c15); | - | ||||||||||||||||||
| 2280 | sample += QChar(0x0c25); | - | ||||||||||||||||||
| 2281 | sample += QChar(0x0c35); | - | ||||||||||||||||||
| 2282 | break; never executed: break; | 0 | ||||||||||||||||||
| 2283 | case Kannada: never executed: case Kannada: | 0 | ||||||||||||||||||
| 2284 | sample += QChar(0x0c85); | - | ||||||||||||||||||
| 2285 | sample += QChar(0x0c95); | - | ||||||||||||||||||
| 2286 | sample += QChar(0x0ca5); | - | ||||||||||||||||||
| 2287 | sample += QChar(0x0cb5); | - | ||||||||||||||||||
| 2288 | break; never executed: break; | 0 | ||||||||||||||||||
| 2289 | case Malayalam: never executed: case Malayalam: | 0 | ||||||||||||||||||
| 2290 | sample += QChar(0x0d05); | - | ||||||||||||||||||
| 2291 | sample += QChar(0x0d15); | - | ||||||||||||||||||
| 2292 | sample += QChar(0x0d25); | - | ||||||||||||||||||
| 2293 | sample += QChar(0x0d35); | - | ||||||||||||||||||
| 2294 | break; never executed: break; | 0 | ||||||||||||||||||
| 2295 | case Sinhala: never executed: case Sinhala: | 0 | ||||||||||||||||||
| 2296 | sample += QChar(0x0d90); | - | ||||||||||||||||||
| 2297 | sample += QChar(0x0da0); | - | ||||||||||||||||||
| 2298 | sample += QChar(0x0db0); | - | ||||||||||||||||||
| 2299 | sample += QChar(0x0dc0); | - | ||||||||||||||||||
| 2300 | break; never executed: break; | 0 | ||||||||||||||||||
| 2301 | case Thai: never executed: case Thai: | 0 | ||||||||||||||||||
| 2302 | sample += QChar(0x0e02); | - | ||||||||||||||||||
| 2303 | sample += QChar(0x0e12); | - | ||||||||||||||||||
| 2304 | sample += QChar(0x0e22); | - | ||||||||||||||||||
| 2305 | sample += QChar(0x0e32); | - | ||||||||||||||||||
| 2306 | break; never executed: break; | 0 | ||||||||||||||||||
| 2307 | case Lao: never executed: case Lao: | 0 | ||||||||||||||||||
| 2308 | sample += QChar(0x0e8d); | - | ||||||||||||||||||
| 2309 | sample += QChar(0x0e9d); | - | ||||||||||||||||||
| 2310 | sample += QChar(0x0ead); | - | ||||||||||||||||||
| 2311 | sample += QChar(0x0ebd); | - | ||||||||||||||||||
| 2312 | break; never executed: break; | 0 | ||||||||||||||||||
| 2313 | case Tibetan: never executed: case Tibetan: | 0 | ||||||||||||||||||
| 2314 | sample += QChar(0x0f00); | - | ||||||||||||||||||
| 2315 | sample += QChar(0x0f01); | - | ||||||||||||||||||
| 2316 | sample += QChar(0x0f02); | - | ||||||||||||||||||
| 2317 | sample += QChar(0x0f03); | - | ||||||||||||||||||
| 2318 | break; never executed: break; | 0 | ||||||||||||||||||
| 2319 | case Myanmar: never executed: case Myanmar: | 0 | ||||||||||||||||||
| 2320 | sample += QChar(0x1000); | - | ||||||||||||||||||
| 2321 | sample += QChar(0x1001); | - | ||||||||||||||||||
| 2322 | sample += QChar(0x1002); | - | ||||||||||||||||||
| 2323 | sample += QChar(0x1003); | - | ||||||||||||||||||
| 2324 | break; never executed: break; | 0 | ||||||||||||||||||
| 2325 | case Georgian: never executed: case Georgian: | 0 | ||||||||||||||||||
| 2326 | sample += QChar(0x10a0); | - | ||||||||||||||||||
| 2327 | sample += QChar(0x10b0); | - | ||||||||||||||||||
| 2328 | sample += QChar(0x10c0); | - | ||||||||||||||||||
| 2329 | sample += QChar(0x10d0); | - | ||||||||||||||||||
| 2330 | break; never executed: break; | 0 | ||||||||||||||||||
| 2331 | case Khmer: never executed: case Khmer: | 0 | ||||||||||||||||||
| 2332 | sample += QChar(0x1780); | - | ||||||||||||||||||
| 2333 | sample += QChar(0x1790); | - | ||||||||||||||||||
| 2334 | sample += QChar(0x17b0); | - | ||||||||||||||||||
| 2335 | sample += QChar(0x17c0); | - | ||||||||||||||||||
| 2336 | break; never executed: break; | 0 | ||||||||||||||||||
| 2337 | case SimplifiedChinese: never executed: case SimplifiedChinese: | 0 | ||||||||||||||||||
| 2338 | sample += QChar(0x4e2d); | - | ||||||||||||||||||
| 2339 | sample += QChar(0x6587); | - | ||||||||||||||||||
| 2340 | sample += QChar(0x8303); | - | ||||||||||||||||||
| 2341 | sample += QChar(0x4f8b); | - | ||||||||||||||||||
| 2342 | break; never executed: break; | 0 | ||||||||||||||||||
| 2343 | case TraditionalChinese: never executed: case TraditionalChinese: | 0 | ||||||||||||||||||
| 2344 | sample += QChar(0x4e2d); | - | ||||||||||||||||||
| 2345 | sample += QChar(0x6587); | - | ||||||||||||||||||
| 2346 | sample += QChar(0x7bc4); | - | ||||||||||||||||||
| 2347 | sample += QChar(0x4f8b); | - | ||||||||||||||||||
| 2348 | break; never executed: break; | 0 | ||||||||||||||||||
| 2349 | case Japanese: never executed: case Japanese: | 0 | ||||||||||||||||||
| 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; never executed: break; | 0 | ||||||||||||||||||
| 2357 | case Korean: never executed: case Korean: | 0 | ||||||||||||||||||
| 2358 | sample += QChar(0xac00); | - | ||||||||||||||||||
| 2359 | sample += QChar(0xac11); | - | ||||||||||||||||||
| 2360 | sample += QChar(0xac1a); | - | ||||||||||||||||||
| 2361 | sample += QChar(0xac2f); | - | ||||||||||||||||||
| 2362 | break; never executed: break; | 0 | ||||||||||||||||||
| 2363 | case Vietnamese: never executed: case Vietnamese: | 0 | ||||||||||||||||||
| 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; never executed: break; | 0 | ||||||||||||||||||
| 2373 | } | - | ||||||||||||||||||
| 2374 | case Ogham: never executed: case Ogham: | 0 | ||||||||||||||||||
| 2375 | sample += QChar(0x1681); | - | ||||||||||||||||||
| 2376 | sample += QChar(0x1682); | - | ||||||||||||||||||
| 2377 | sample += QChar(0x1683); | - | ||||||||||||||||||
| 2378 | sample += QChar(0x1684); | - | ||||||||||||||||||
| 2379 | break; never executed: break; | 0 | ||||||||||||||||||
| 2380 | case Runic: never executed: case Runic: | 0 | ||||||||||||||||||
| 2381 | sample += QChar(0x16a0); | - | ||||||||||||||||||
| 2382 | sample += QChar(0x16a1); | - | ||||||||||||||||||
| 2383 | sample += QChar(0x16a2); | - | ||||||||||||||||||
| 2384 | sample += QChar(0x16a3); | - | ||||||||||||||||||
| 2385 | break; never executed: break; | 0 | ||||||||||||||||||
| 2386 | case Nko: never executed: case Nko: | 0 | ||||||||||||||||||
| 2387 | sample += QChar(0x7ca); | - | ||||||||||||||||||
| 2388 | sample += QChar(0x7cb); | - | ||||||||||||||||||
| 2389 | sample += QChar(0x7cc); | - | ||||||||||||||||||
| 2390 | sample += QChar(0x7cd); | - | ||||||||||||||||||
| 2391 | break; never executed: break; | 0 | ||||||||||||||||||
| 2392 | default: never executed: default: | 0 | ||||||||||||||||||
| 2393 | break; never executed: break; | 0 | ||||||||||||||||||
| 2394 | } | - | ||||||||||||||||||
| 2395 | return sample; never executed: return sample; | 0 | ||||||||||||||||||
| 2396 | } | - | ||||||||||||||||||
| 2397 | - | |||||||||||||||||||
| 2398 | - | |||||||||||||||||||
| 2399 | void QFontDatabase::parseFontName(const QString &name, QString &foundry, QString &family) | - | ||||||||||||||||||
| 2400 | { | - | ||||||||||||||||||
| 2401 | QT_PREPEND_NAMESPACE(parseFontName)(name, foundry, family); | - | ||||||||||||||||||
| 2402 | } never executed: end of block | 0 | ||||||||||||||||||
| 2403 | - | |||||||||||||||||||
| 2404 | void QFontDatabase::createDatabase() | - | ||||||||||||||||||
| 2405 | { never executed: initializeDb(); }end of blocknever executed: end of block | 0 | ||||||||||||||||||
| 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; never executed: return privateDb()->applicationFonts.value(index).data; | 0 | ||||||||||||||||||
| 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)
| 0 | ||||||||||||||||||
| 2422 | if (applicationFonts.at(i).families.isEmpty())
| 0 | ||||||||||||||||||
| 2423 | break; never executed: break; | 0 | ||||||||||||||||||
| 2424 | if (i >= applicationFonts.count()) {
| 0 | ||||||||||||||||||
| 2425 | applicationFonts.append(ApplicationFont()); | - | ||||||||||||||||||
| 2426 | i = applicationFonts.count() - 1; | - | ||||||||||||||||||
| 2427 | } never executed: end of block | 0 | ||||||||||||||||||
| 2428 | - | |||||||||||||||||||
| 2429 | if (font.fileName.isEmpty() && !fontData.isEmpty())
| 0 | ||||||||||||||||||
| 2430 | font.fileName = QString::fromLatin1(":qmemoryfonts/") + QString::number(i); never executed: font.fileName = QString::fromLatin1(":qmemoryfonts/") + QString::number(i); | 0 | ||||||||||||||||||
| 2431 | - | |||||||||||||||||||
| 2432 | registerFont(&font); | - | ||||||||||||||||||
| 2433 | if (font.families.isEmpty())
| 0 | ||||||||||||||||||
| 2434 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2435 | - | |||||||||||||||||||
| 2436 | applicationFonts[i] = font; | - | ||||||||||||||||||
| 2437 | - | |||||||||||||||||||
| 2438 | invalidate(); | - | ||||||||||||||||||
| 2439 | return i; never executed: return i; | 0 | ||||||||||||||||||
| 2440 | } | - | ||||||||||||||||||
| 2441 | - | |||||||||||||||||||
| 2442 | bool QFontDatabasePrivate::isApplicationFont(const QString &fileName) | - | ||||||||||||||||||
| 2443 | { | - | ||||||||||||||||||
| 2444 | for (int i = 0; i < applicationFonts.count(); ++i)
| 0 | ||||||||||||||||||
| 2445 | if (applicationFonts.at(i).fileName == fileName)
| 0 | ||||||||||||||||||
| 2446 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 2447 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 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()) {
| 0 | ||||||||||||||||||
| 2472 | QFile f(fileName); | - | ||||||||||||||||||
| 2473 | if (!f.open(QIODevice::ReadOnly))
| 0 | ||||||||||||||||||
| 2474 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 2475 | data = f.readAll(); | - | ||||||||||||||||||
| 2476 | } never executed: end of block | 0 | ||||||||||||||||||
| 2477 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||||||||
| 2478 | return privateDb()->addAppFont(data, fileName); never executed: return privateDb()->addAppFont(data, fileName); | 0 | ||||||||||||||||||
| 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 */); never executed: return privateDb()->addAppFont(fontData, QString() ); | 0 | ||||||||||||||||||
| 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; never executed: return privateDb()->applicationFonts.value(id).families; | 0 | ||||||||||||||||||
| 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()) {
| 0 | ||||||||||||||||||
| 2531 | switch (type) { | - | ||||||||||||||||||
| 2532 | case GeneralFont: never executed: case GeneralFont: | 0 | ||||||||||||||||||
| 2533 | font = theme->font(QPlatformTheme::SystemFont); | - | ||||||||||||||||||
| 2534 | break; never executed: break; | 0 | ||||||||||||||||||
| 2535 | case FixedFont: never executed: case FixedFont: | 0 | ||||||||||||||||||
| 2536 | font = theme->font(QPlatformTheme::FixedFont); | - | ||||||||||||||||||
| 2537 | break; never executed: break; | 0 | ||||||||||||||||||
| 2538 | case TitleFont: never executed: case TitleFont: | 0 | ||||||||||||||||||
| 2539 | font = theme->font(QPlatformTheme::TitleBarFont); | - | ||||||||||||||||||
| 2540 | break; never executed: break; | 0 | ||||||||||||||||||
| 2541 | case SmallestReadableFont: never executed: case SmallestReadableFont: | 0 | ||||||||||||||||||
| 2542 | font = theme->font(QPlatformTheme::MiniFont); | - | ||||||||||||||||||
| 2543 | break; never executed: break; | 0 | ||||||||||||||||||
| 2544 | } | - | ||||||||||||||||||
| 2545 | } never executed: end of block | 0 | ||||||||||||||||||
| 2546 | - | |||||||||||||||||||
| 2547 | if (font)
| 0 | ||||||||||||||||||
| 2548 | return *font; never executed: return *font; | 0 | ||||||||||||||||||
| 2549 | else if (QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration())
| 0 | ||||||||||||||||||
| 2550 | return integration->fontDatabase()->defaultFont(); never executed: return integration->fontDatabase()->defaultFont(); | 0 | ||||||||||||||||||
| 2551 | else | - | ||||||||||||||||||
| 2552 | return QFont(); never executed: return QFont(); | 0 | ||||||||||||||||||
| 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())
| 0 | ||||||||||||||||||
| 2572 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2573 | - | |||||||||||||||||||
| 2574 | db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont(); | - | ||||||||||||||||||
| 2575 | - | |||||||||||||||||||
| 2576 | db->reregisterAppFonts = true; | - | ||||||||||||||||||
| 2577 | db->invalidate(); | - | ||||||||||||||||||
| 2578 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 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())
| 0 | ||||||||||||||||||
| 2599 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 2600 | - | |||||||||||||||||||
| 2601 | db->applicationFonts.clear(); | - | ||||||||||||||||||
| 2602 | db->invalidate(); | - | ||||||||||||||||||
| 2603 | return true; never executed: return true; | 0 | ||||||||||||||||||
| 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; never executed: return true; | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 2730 | req.pixelSize = std::floor(((req.pointSize * d->dpi) / 72) * 100 + 0.5) / 100; | - | ||||||||||||||||||
| 2731 | req.pixelSize = qRound(req.pixelSize); | - | ||||||||||||||||||
| 2732 | } never executed: end of block | 0 | ||||||||||||||||||
| 2733 | if (req.pointSize < 0)
| 0 | ||||||||||||||||||
| 2734 | req.pointSize = req.pixelSize*72.0/d->dpi; never executed: req.pointSize = req.pixelSize*72.0/d->dpi; | 0 | ||||||||||||||||||
| 2735 | if (req.stretch == 0)
| 0 | ||||||||||||||||||
| 2736 | req.stretch = 100; never executed: req.stretch = 100; | 0 | ||||||||||||||||||
| 2737 | - | |||||||||||||||||||
| 2738 | // respect the fallback families that might be passed through the request | - | ||||||||||||||||||
| 2739 | const QStringList fallBackFamilies = familyList(req); | - | ||||||||||||||||||
| 2740 | - | |||||||||||||||||||
| 2741 | if (!d->engineData) {
| 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 2750 | // create a new one | - | ||||||||||||||||||
| 2751 | d->engineData = new QFontEngineData; | - | ||||||||||||||||||
| 2752 | fontCache->insertEngineData(req, d->engineData); | - | ||||||||||||||||||
| 2753 | } never executed: end of block | 0 | ||||||||||||||||||
| 2754 | d->engineData->ref.ref(); | - | ||||||||||||||||||
| 2755 | } never executed: end of block | 0 | ||||||||||||||||||
| 2756 | - | |||||||||||||||||||
| 2757 | // the cached engineData could have already loaded the engine we want | - | ||||||||||||||||||
| 2758 | if (d->engineData->engines[script])
| 0 | ||||||||||||||||||
| 2759 | return; never executed: return; | 0 | ||||||||||||||||||
| 2760 | - | |||||||||||||||||||
| 2761 | QFontEngine *fe = Q_NULLPTR; | - | ||||||||||||||||||
| 2762 | - | |||||||||||||||||||
| 2763 | req.fallBackFamilies = fallBackFamilies; | - | ||||||||||||||||||
| 2764 | if (!req.fallBackFamilies.isEmpty())
| 0 | ||||||||||||||||||
| 2765 | req.family = req.fallBackFamilies.takeFirst(); never executed: req.family = req.fallBackFamilies.takeFirst(); | 0 | ||||||||||||||||||
| 2766 | - | |||||||||||||||||||
| 2767 | // list of families to try | - | ||||||||||||||||||
| 2768 | QStringList family_list; | - | ||||||||||||||||||
| 2769 | - | |||||||||||||||||||
| 2770 | if (!req.family.isEmpty()) {
| 0 | ||||||||||||||||||
| 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))
| 0 | ||||||||||||||||||
| 2777 | family_list << defaultFamily; never executed: family_list << defaultFamily; | 0 | ||||||||||||||||||
| 2778 | - | |||||||||||||||||||
| 2779 | } never executed: end of block | 0 | ||||||||||||||||||
| 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) {
| 0 | ||||||||||||||||||
| 2786 | req.family = *it; | - | ||||||||||||||||||
| 2787 | - | |||||||||||||||||||
| 2788 | fe = QFontDatabase::findFont(req, script); | - | ||||||||||||||||||
| 2789 | if (fe) {
| 0 | ||||||||||||||||||
| 2790 | if (fe->type() == QFontEngine::Box && !req.family.isEmpty()) {
| 0 | ||||||||||||||||||
| 2791 | if (fe->ref.load() == 0)
| 0 | ||||||||||||||||||
| 2792 | delete fe; never executed: delete fe; | 0 | ||||||||||||||||||
| 2793 | fe = 0; | - | ||||||||||||||||||
| 2794 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2795 | if (d->dpi > 0)
| 0 | ||||||||||||||||||
| 2796 | fe->fontDef.pointSize = qreal(double((fe->fontDef.pixelSize * 72) / d->dpi)); never executed: fe->fontDef.pointSize = qreal(double((fe->fontDef.pixelSize * 72) / d->dpi)); | 0 | ||||||||||||||||||
| 2797 | } never executed: end of block | 0 | ||||||||||||||||||
| 2798 | } | - | ||||||||||||||||||
| 2799 | - | |||||||||||||||||||
| 2800 | // No need to check requested fallback families again | - | ||||||||||||||||||
| 2801 | req.fallBackFamilies.clear(); | - | ||||||||||||||||||
| 2802 | } never executed: end of block | 0 | ||||||||||||||||||
| 2803 | - | |||||||||||||||||||
| 2804 | Q_ASSERT(fe); | - | ||||||||||||||||||
| 2805 | if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) {
| 0 | ||||||||||||||||||
| 2806 | for (int i = 0; i < QChar::ScriptCount; ++i) {
| 0 | ||||||||||||||||||
| 2807 | if (!d->engineData->engines[i]) {
| 0 | ||||||||||||||||||
| 2808 | d->engineData->engines[i] = fe; | - | ||||||||||||||||||
| 2809 | fe->ref.ref(); | - | ||||||||||||||||||
| 2810 | } never executed: end of block | 0 | ||||||||||||||||||
| 2811 | } never executed: end of block | 0 | ||||||||||||||||||
| 2812 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 2813 | d->engineData->engines[script] = fe; | - | ||||||||||||||||||
| 2814 | fe->ref.ref(); | - | ||||||||||||||||||
| 2815 | } never executed: end of block | 0 | ||||||||||||||||||
| 2816 | } | - | ||||||||||||||||||
| 2817 | - | |||||||||||||||||||
| 2818 | QString QFontDatabase::resolveFontFamilyAlias(const QString &family) | - | ||||||||||||||||||
| 2819 | { | - | ||||||||||||||||||
| 2820 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(family); never executed: return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(family); | 0 | ||||||||||||||||||
| 2821 | } | - | ||||||||||||||||||
| 2822 | - | |||||||||||||||||||
| 2823 | - | |||||||||||||||||||
| 2824 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 2825 | - | |||||||||||||||||||
| Source code | Switch to Preprocessed file |