| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qfontdatabase.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | bool qt_enable_test_font = false; | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | __attribute__((visibility("default"))) void qt_setQtEnableTestFont(bool value) | - | ||||||||||||
| 11 | { | - | ||||||||||||
| 12 | qt_enable_test_font = value; | - | ||||||||||||
| 13 | } | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | - | |||||||||||||
| 16 | static int getFontWeight(const QString &weightString) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | QString s = weightString.toLower(); | - | ||||||||||||
| 19 | if (s == QLatin1String("normal") || s == QLatin1String("regular")) | - | ||||||||||||
| 20 | return QFont::Normal; | - | ||||||||||||
| 21 | if (s == QLatin1String("bold")) | - | ||||||||||||
| 22 | return QFont::Bold; | - | ||||||||||||
| 23 | if (s == QLatin1String("semibold") || s == QLatin1String("semi bold") | - | ||||||||||||
| 24 | || s == QLatin1String("demibold") || s == QLatin1String("demi bold")) | - | ||||||||||||
| 25 | return QFont::DemiBold; | - | ||||||||||||
| 26 | if (s == QLatin1String("medium")) | - | ||||||||||||
| 27 | return QFont::Medium; | - | ||||||||||||
| 28 | if (s == QLatin1String("black")) | - | ||||||||||||
| 29 | return QFont::Black; | - | ||||||||||||
| 30 | if (s == QLatin1String("light")) | - | ||||||||||||
| 31 | return QFont::Light; | - | ||||||||||||
| 32 | if (s == QLatin1String("thin")) | - | ||||||||||||
| 33 | return QFont::Thin; | - | ||||||||||||
| 34 | const QStringRef s2 = s.midRef(2); | - | ||||||||||||
| 35 | if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) { | - | ||||||||||||
| 36 | if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light")) | - | ||||||||||||
| 37 | return QFont::ExtraLight; | - | ||||||||||||
| 38 | if (s2 == QLatin1String("trabold") || s2 == QLatin1String("tra bold")) | - | ||||||||||||
| 39 | return QFont::ExtraBold; | - | ||||||||||||
| 40 | } | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | - | |||||||||||||
| 43 | - | |||||||||||||
| 44 | if (s.contains(QLatin1String("bold"))) { | - | ||||||||||||
| 45 | if (s.contains(QLatin1String("demi"))) | - | ||||||||||||
| 46 | return QFont::DemiBold; | - | ||||||||||||
| 47 | return QFont::Bold; | - | ||||||||||||
| 48 | } | - | ||||||||||||
| 49 | if (s.contains(QLatin1String("thin"))) | - | ||||||||||||
| 50 | return QFont::Thin; | - | ||||||||||||
| 51 | if (s.contains(QLatin1String("light"))) | - | ||||||||||||
| 52 | return QFont::Light; | - | ||||||||||||
| 53 | if (s.contains(QLatin1String("black"))) | - | ||||||||||||
| 54 | return QFont::Black; | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | - | |||||||||||||
| 57 | - | |||||||||||||
| 58 | - | |||||||||||||
| 59 | - | |||||||||||||
| 60 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 61 | return QFont::Normal; | - | ||||||||||||
| 62 | const QString translatedBold = QCoreApplication::translate("QFontDatabase", "Bold").toLower(); | - | ||||||||||||
| 63 | if (s == translatedBold) | - | ||||||||||||
| 64 | return QFont::Bold; | - | ||||||||||||
| 65 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Demi Bold"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 66 | return QFont::DemiBold; | - | ||||||||||||
| 67 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 68 | return QFont::Medium; | - | ||||||||||||
| 69 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Black"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 70 | return QFont::Black; | - | ||||||||||||
| 71 | const QString translatedLight = QCoreApplication::translate("QFontDatabase", "Light").toLower(); | - | ||||||||||||
| 72 | if (s == translatedLight) | - | ||||||||||||
| 73 | return QFont::Light; | - | ||||||||||||
| 74 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Thin"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 75 | return QFont::Thin; | - | ||||||||||||
| 76 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Light"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 77 | return QFont::ExtraLight; | - | ||||||||||||
| 78 | if (s.compare(QCoreApplication::translate("QFontDatabase", "Extra Bold"), Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 79 | return QFont::ExtraBold; | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | - | |||||||||||||
| 82 | - | |||||||||||||
| 83 | const QString translatedExtra = QCoreApplication::translate("QFontDatabase", "Extra").toLower(); | - | ||||||||||||
| 84 | if (s.contains(translatedBold)) { | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | QString translatedDemi = QCoreApplication::translate("QFontDatabase", "Demi").toLower(); | - | ||||||||||||
| 87 | if (s .contains(translatedDemi)) | - | ||||||||||||
| 88 | return QFont::DemiBold; | - | ||||||||||||
| 89 | if (s.contains(translatedExtra)) | - | ||||||||||||
| 90 | return QFont::ExtraBold; | - | ||||||||||||
| 91 | return QFont::Bold; | - | ||||||||||||
| 92 | } | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | if (s.contains(translatedLight)) { | - | ||||||||||||
| 95 | if (s.contains(translatedExtra)) | - | ||||||||||||
| 96 | return QFont::ExtraLight; | - | ||||||||||||
| 97 | return QFont::Light; | - | ||||||||||||
| 98 | } | - | ||||||||||||
| 99 | return QFont::Normal; | - | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | - | |||||||||||||
| 103 | struct QtFontSize | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | void *handle; | - | ||||||||||||
| 107 | - | |||||||||||||
| 108 | unsigned short pixelSize : 16; | - | ||||||||||||
| 109 | }; | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | - | |||||||||||||
| 112 | - | |||||||||||||
| 113 | struct QtFontStyle | - | ||||||||||||
| 114 | { | - | ||||||||||||
| 115 | struct Key { | - | ||||||||||||
| 116 | Key(const QString &styleString); | - | ||||||||||||
| 117 | Key() : style(QFont::StyleNormal), | - | ||||||||||||
| 118 | weight(QFont::Normal), stretch(0) { } | - | ||||||||||||
| 119 | Key(const Key &o) : style(o.style), weight(o.weight), stretch(o.stretch) { } | - | ||||||||||||
| 120 | uint style : 2; | - | ||||||||||||
| 121 | signed int weight : 8; | - | ||||||||||||
| 122 | signed int stretch : 12; | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | bool operator==(const Key & other) { | - | ||||||||||||
| 125 | return (style == other.style && weight == other.weight && | - | ||||||||||||
| 126 | (stretch == 0 || other.stretch == 0 || stretch == other.stretch)); | - | ||||||||||||
| 127 | } | - | ||||||||||||
| 128 | bool operator!=(const Key &other) { | - | ||||||||||||
| 129 | return !operator==(other); | - | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | bool operator <(const Key &o) { | - | ||||||||||||
| 132 | int x = (style << 12) + (weight << 14) + stretch; | - | ||||||||||||
| 133 | int y = (o.style << 12) + (o.weight << 14) + o.stretch; | - | ||||||||||||
| 134 | return (x < y); | - | ||||||||||||
| 135 | } | - | ||||||||||||
| 136 | }; | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | QtFontStyle(const Key &k) | - | ||||||||||||
| 139 | : key(k), bitmapScalable(false), smoothScalable(false), | - | ||||||||||||
| 140 | count(0), pixelSizes(0) | - | ||||||||||||
| 141 | { | - | ||||||||||||
| 142 | } | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | ~QtFontStyle() { | - | ||||||||||||
| 145 | while (count) { | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | count--; | - | ||||||||||||
| 148 | QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||
| 149 | if (integration) { | - | ||||||||||||
| 150 | integration->fontDatabase()->releaseHandle(pixelSizes[count].handle); | - | ||||||||||||
| 151 | } | - | ||||||||||||
| 152 | } | - | ||||||||||||
| 153 | free(pixelSizes); | - | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | Key key; | - | ||||||||||||
| 157 | bool bitmapScalable : 1; | - | ||||||||||||
| 158 | bool smoothScalable : 1; | - | ||||||||||||
| 159 | signed int count : 30; | - | ||||||||||||
| 160 | QtFontSize *pixelSizes; | - | ||||||||||||
| 161 | QString styleName; | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | bool antialiased; | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | QtFontSize *pixelSize(unsigned short size, bool = false); | - | ||||||||||||
| 166 | }; | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | QtFontStyle::Key::Key(const QString &styleString) | - | ||||||||||||
| 169 | : style(QFont::StyleNormal), weight(QFont::Normal), stretch(0) | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | weight = getFontWeight(styleString); | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | if (!styleString.isEmpty()) { | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | if (styleString.contains(QLatin1String("Italic"))) | - | ||||||||||||
| 176 | style = QFont::StyleItalic; | - | ||||||||||||
| 177 | else if (styleString.contains(QLatin1String("Oblique"))) | - | ||||||||||||
| 178 | style = QFont::StyleOblique; | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | - | |||||||||||||
| 181 | else if (styleString.contains(QCoreApplication::translate("QFontDatabase", "Italic"))) | - | ||||||||||||
| 182 | style = QFont::StyleItalic; | - | ||||||||||||
| 183 | else if (styleString.contains(QCoreApplication::translate("QFontDatabase", "Oblique"))) | - | ||||||||||||
| 184 | style = QFont::StyleOblique; | - | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | } | - | ||||||||||||
| 187 | - | |||||||||||||
| 188 | QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add) | - | ||||||||||||
| 189 | { | - | ||||||||||||
| 190 | for (int i = 0; i < count; i++) { | - | ||||||||||||
| 191 | if (pixelSizes[i].pixelSize == size) | - | ||||||||||||
| 192 | return pixelSizes + i; | - | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | if (!add) | - | ||||||||||||
| 195 | return 0; | - | ||||||||||||
| 196 | - | |||||||||||||
| 197 | if (!pixelSizes) { | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | QtFontSize *newPixelSizes = (QtFontSize *)malloc(sizeof(QtFontSize)); | - | ||||||||||||
| 200 | do {if(!(newPixelSizes))qt_check_pointer(__FILE__,278284);} while (0); | - | ||||||||||||
| 201 | pixelSizes = newPixelSizes; | - | ||||||||||||
| 202 | } else if (!(count % 8) || count == 1) { | - | ||||||||||||
| 203 | QtFontSize *newPixelSizes = (QtFontSize *) | - | ||||||||||||
| 204 | realloc(pixelSizes, | - | ||||||||||||
| 205 | (((count+8) >> 3) << 3) * sizeof(QtFontSize)); | - | ||||||||||||
| 206 | do {if(!(newPixelSizes))qt_check_pointer(__FILE__,284290);} while (0); | - | ||||||||||||
| 207 | pixelSizes = newPixelSizes; | - | ||||||||||||
| 208 | } | - | ||||||||||||
| 209 | pixelSizes[count].pixelSize = size; | - | ||||||||||||
| 210 | pixelSizes[count].handle = 0; | - | ||||||||||||
| 211 | return pixelSizes + (count++); | - | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | struct QtFontFoundry | - | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | QtFontFoundry(const QString &n) : name(n), count(0), styles(0) {} | - | ||||||||||||
| 217 | ~QtFontFoundry() { | - | ||||||||||||
| 218 | while (count--) | - | ||||||||||||
| 219 | delete styles[count]; | - | ||||||||||||
| 220 | free(styles); | - | ||||||||||||
| 221 | } | - | ||||||||||||
| 222 | - | |||||||||||||
| 223 | QString name; | - | ||||||||||||
| 224 | - | |||||||||||||
| 225 | int count; | - | ||||||||||||
| 226 | QtFontStyle **styles; | - | ||||||||||||
| 227 | QtFontStyle *style(const QtFontStyle::Key &, const QString & = QString(), bool = false); | - | ||||||||||||
| 228 | }; | - | ||||||||||||
| 229 | - | |||||||||||||
| 230 | QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &styleName, bool create) | - | ||||||||||||
| 231 | { | - | ||||||||||||
| 232 | int pos = 0; | - | ||||||||||||
| 233 | for (; pos < count; pos++) { | - | ||||||||||||
| 234 | bool hasStyleName = !styleName.isEmpty(); | - | ||||||||||||
| 235 | if (hasStyleName && !styles[pos]->styleName.isEmpty()) { | - | ||||||||||||
| 236 | if (styles[pos]->styleName == styleName) | - | ||||||||||||
| 237 | return styles[pos]; | - | ||||||||||||
| 238 | } else { | - | ||||||||||||
| 239 | if (styles[pos]->key == key) | - | ||||||||||||
| 240 | return styles[pos]; | - | ||||||||||||
| 241 | } | - | ||||||||||||
| 242 | } | - | ||||||||||||
| 243 | if (!create) | - | ||||||||||||
| 244 | return 0; | - | ||||||||||||
| 245 | - | |||||||||||||
| 246 | - | |||||||||||||
| 247 | if (!(count % 8)) { | - | ||||||||||||
| 248 | QtFontStyle **newStyles = (QtFontStyle **) | - | ||||||||||||
| 249 | realloc(styles, (((count+8) >> 3) << 3) * sizeof(QtFontStyle *)); | - | ||||||||||||
| 250 | do {if(!(newStyles))qt_check_pointer(__FILE__,328334);} while (0); | - | ||||||||||||
| 251 | styles = newStyles; | - | ||||||||||||
| 252 | } | - | ||||||||||||
| 253 | - | |||||||||||||
| 254 | QtFontStyle *style = new QtFontStyle(key); | - | ||||||||||||
| 255 | style->styleName = styleName; | - | ||||||||||||
| 256 | styles[pos] = style; | - | ||||||||||||
| 257 | count++; | - | ||||||||||||
| 258 | return styles[pos]; | - | ||||||||||||
| 259 | } | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | - | |||||||||||||
| 262 | struct QtFontFamily | - | ||||||||||||
| 263 | { | - | ||||||||||||
| 264 | enum WritingSystemStatus { | - | ||||||||||||
| 265 | Unknown = 0, | - | ||||||||||||
| 266 | Supported = 1, | - | ||||||||||||
| 267 | UnsupportedFT = 2, | - | ||||||||||||
| 268 | Unsupported = UnsupportedFT | - | ||||||||||||
| 269 | }; | - | ||||||||||||
| 270 | - | |||||||||||||
| 271 | QtFontFamily(const QString &n) | - | ||||||||||||
| 272 | : | - | ||||||||||||
| 273 | populated(false), | - | ||||||||||||
| 274 | fixedPitch(false), | - | ||||||||||||
| 275 | name(n), count(0), foundries(0) | - | ||||||||||||
| 276 | { | - | ||||||||||||
| 277 | memset(writingSystems, 0, sizeof(writingSystems)); | - | ||||||||||||
| 278 | } | - | ||||||||||||
| 279 | ~QtFontFamily() { | - | ||||||||||||
| 280 | while (count--) | - | ||||||||||||
| 281 | delete foundries[count]; | - | ||||||||||||
| 282 | free(foundries); | - | ||||||||||||
| 283 | } | - | ||||||||||||
| 284 | - | |||||||||||||
| 285 | bool populated : 1; | - | ||||||||||||
| 286 | bool fixedPitch : 1; | - | ||||||||||||
| 287 | - | |||||||||||||
| 288 | QString name; | - | ||||||||||||
| 289 | QStringList aliases; | - | ||||||||||||
| 290 | int count; | - | ||||||||||||
| 291 | QtFontFoundry **foundries; | - | ||||||||||||
| 292 | - | |||||||||||||
| 293 | unsigned char writingSystems[QFontDatabase::WritingSystemsCount]; | - | ||||||||||||
| 294 | - | |||||||||||||
| 295 | bool matchesFamilyName(const QString &familyName) const; | - | ||||||||||||
| 296 | QtFontFoundry *foundry(const QString &f, bool = false); | - | ||||||||||||
| 297 | - | |||||||||||||
| 298 | void ensurePopulated(); | - | ||||||||||||
| 299 | }; | - | ||||||||||||
| 300 | - | |||||||||||||
| 301 | QtFontFoundry *QtFontFamily::foundry(const QString &f, bool create) | - | ||||||||||||
| 302 | { | - | ||||||||||||
| 303 | if (f.isNull() && count == 1) | - | ||||||||||||
| 304 | return foundries[0]; | - | ||||||||||||
| 305 | - | |||||||||||||
| 306 | for (int i = 0; i < count; i++) { | - | ||||||||||||
| 307 | if (foundries[i]->name.compare(f, Qt::CaseInsensitive) == 0) | - | ||||||||||||
| 308 | return foundries[i]; | - | ||||||||||||
| 309 | } | - | ||||||||||||
| 310 | if (!create) | - | ||||||||||||
| 311 | return 0; | - | ||||||||||||
| 312 | - | |||||||||||||
| 313 | if (!(count % 8)) { | - | ||||||||||||
| 314 | QtFontFoundry **newFoundries = (QtFontFoundry **) | - | ||||||||||||
| 315 | realloc(foundries, | - | ||||||||||||
| 316 | (((count+8) >> 3) << 3) * sizeof(QtFontFoundry *)); | - | ||||||||||||
| 317 | do {if(!(newFoundries))qt_check_pointer(__FILE__,395401);} while (0); | - | ||||||||||||
| 318 | foundries = newFoundries; | - | ||||||||||||
| 319 | } | - | ||||||||||||
| 320 | - | |||||||||||||
| 321 | foundries[count] = new QtFontFoundry(f); | - | ||||||||||||
| 322 | return foundries[count++]; | - | ||||||||||||
| 323 | } | - | ||||||||||||
| 324 | - | |||||||||||||
| 325 | bool QtFontFamily::matchesFamilyName(const QString &familyName) const | - | ||||||||||||
| 326 | { | - | ||||||||||||
| 327 | return name.compare(familyName, Qt::CaseInsensitive) == 0 || aliases.contains(familyName, Qt::CaseInsensitive); | - | ||||||||||||
| 328 | } | - | ||||||||||||
| 329 | - | |||||||||||||
| 330 | void QtFontFamily::ensurePopulated() | - | ||||||||||||
| 331 | { | - | ||||||||||||
| 332 | if (populated) | - | ||||||||||||
| 333 | return; | - | ||||||||||||
| 334 | - | |||||||||||||
| 335 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFamily(name); | - | ||||||||||||
| 336 | ((!(populated)) ? qt_assert_x(__PRETTY_FUNCTION__, QString(name).toLocal8Bit().constData(),__FILE__,414420) : qt_noop()); | - | ||||||||||||
| 337 | } | - | ||||||||||||
| 338 | - | |||||||||||||
| 339 | - | |||||||||||||
| 340 | struct FallbacksCacheKey { | - | ||||||||||||
| 341 | QString family; | - | ||||||||||||
| 342 | QFont::Style style; | - | ||||||||||||
| 343 | QFont::StyleHint styleHint; | - | ||||||||||||
| 344 | QChar::Script script; | - | ||||||||||||
| 345 | }; | - | ||||||||||||
| 346 | - | |||||||||||||
| 347 | inline bool operator==(const FallbacksCacheKey &lhs, const FallbacksCacheKey &rhs) noexcept | - | ||||||||||||
| 348 | { | - | ||||||||||||
| 349 | return never executed: lhs.script == rhs.script &&return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family;never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
| 350 | lhs.styleHint == rhs.styleHint && never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
| 351 | lhs.style == rhs.style && never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
| 352 | lhs.family == rhs.family; never executed: return lhs.script == rhs.script && lhs.styleHint == rhs.styleHint && lhs.style == rhs.style && lhs.family == rhs.family; | 0 | ||||||||||||
| 353 | } | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | inline bool operator!=(const FallbacksCacheKey &lhs, const FallbacksCacheKey &rhs) noexcept | - | ||||||||||||
| 356 | { | - | ||||||||||||
| 357 | return never executed: !operator==(lhs, rhs);return !operator==(lhs, rhs);never executed: return !operator==(lhs, rhs); | 0 | ||||||||||||
| 358 | } | - | ||||||||||||
| 359 | - | |||||||||||||
| 360 | inline uint qHash(const FallbacksCacheKey &key, uint seed = 0) noexcept | - | ||||||||||||
| 361 | { | - | ||||||||||||
| 362 | QtPrivate::QHashCombine hash; | - | ||||||||||||
| 363 | seed = hash(seed, key.family); | - | ||||||||||||
| 364 | seed = hash(seed, int(key.style)); | - | ||||||||||||
| 365 | seed = hash(seed, int(key.styleHint)); | - | ||||||||||||
| 366 | seed = hash(seed, int(key.script)); | - | ||||||||||||
| 367 | return never executed: seed;return seed;never executed: return seed; | 0 | ||||||||||||
| 368 | } | - | ||||||||||||
| 369 | - | |||||||||||||
| 370 | - | |||||||||||||
| 371 | class QFontDatabasePrivate | - | ||||||||||||
| 372 | { | - | ||||||||||||
| 373 | public: | - | ||||||||||||
| 374 | QFontDatabasePrivate() | - | ||||||||||||
| 375 | : count(0), families(0), | - | ||||||||||||
| 376 | fallbacksCache(64), | - | ||||||||||||
| 377 | reregisterAppFonts(false) | - | ||||||||||||
| 378 | { } | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | ~QFontDatabasePrivate() { | - | ||||||||||||
| 381 | free(); | - | ||||||||||||
| 382 | } | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | enum FamilyRequestFlags { | - | ||||||||||||
| 385 | RequestFamily = 0, | - | ||||||||||||
| 386 | EnsureCreated, | - | ||||||||||||
| 387 | EnsurePopulated | - | ||||||||||||
| 388 | }; | - | ||||||||||||
| 389 | - | |||||||||||||
| 390 | QtFontFamily *family(const QString &f, FamilyRequestFlags flags = EnsurePopulated); | - | ||||||||||||
| 391 | void free() { | - | ||||||||||||
| 392 | while (count--) | - | ||||||||||||
| 393 | delete families[count]; | - | ||||||||||||
| 394 | ::free(families); | - | ||||||||||||
| 395 | families = 0; | - | ||||||||||||
| 396 | count = 0; | - | ||||||||||||
| 397 | - | |||||||||||||
| 398 | } | - | ||||||||||||
| 399 | - | |||||||||||||
| 400 | int count; | - | ||||||||||||
| 401 | QtFontFamily **families; | - | ||||||||||||
| 402 | - | |||||||||||||
| 403 | QCache<FallbacksCacheKey, QStringList> fallbacksCache; | - | ||||||||||||
| 404 | - | |||||||||||||
| 405 | - | |||||||||||||
| 406 | struct ApplicationFont { | - | ||||||||||||
| 407 | QString fileName; | - | ||||||||||||
| 408 | QByteArray data; | - | ||||||||||||
| 409 | QStringList families; | - | ||||||||||||
| 410 | }; | - | ||||||||||||
| 411 | QVector<ApplicationFont> applicationFonts; | - | ||||||||||||
| 412 | int addAppFont(const QByteArray &fontData, const QString &fileName); | - | ||||||||||||
| 413 | bool reregisterAppFonts; | - | ||||||||||||
| 414 | bool isApplicationFont(const QString &fileName); | - | ||||||||||||
| 415 | - | |||||||||||||
| 416 | void invalidate(); | - | ||||||||||||
| 417 | }; | - | ||||||||||||
| 418 | template<> class QTypeInfo<QFontDatabasePrivate::ApplicationFont > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QFontDatabasePrivate::ApplicationFont)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QFontDatabasePrivate::ApplicationFont >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QFontDatabasePrivate::ApplicationFont) }; static inline const char *name() { return "QFontDatabasePrivate::ApplicationFont"; } }; | - | ||||||||||||
| 419 | - | |||||||||||||
| 420 | void QFontDatabasePrivate::invalidate() | - | ||||||||||||
| 421 | { | - | ||||||||||||
| 422 | QFontCache::instance()->clear(); | - | ||||||||||||
| 423 | - | |||||||||||||
| 424 | fallbacksCache.clear(); | - | ||||||||||||
| 425 | free(); | - | ||||||||||||
| 426 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->invalidate(); | - | ||||||||||||
| 427 | static_cast<QGuiApplication *>(QCoreApplication::instance())->fontDatabaseChanged(); | - | ||||||||||||
| 428 | } | - | ||||||||||||
| 429 | - | |||||||||||||
| 430 | QtFontFamily *QFontDatabasePrivate::family(const QString &f, FamilyRequestFlags flags) | - | ||||||||||||
| 431 | { | - | ||||||||||||
| 432 | QtFontFamily *fam = 0; | - | ||||||||||||
| 433 | - | |||||||||||||
| 434 | int low = 0; | - | ||||||||||||
| 435 | int high = count; | - | ||||||||||||
| 436 | int pos = count / 2; | - | ||||||||||||
| 437 | int res = 1; | - | ||||||||||||
| 438 | if (count) { | - | ||||||||||||
| 439 | while ((res = families[pos]->name.compare(f, Qt::CaseInsensitive)) && pos != low) { | - | ||||||||||||
| 440 | if (res > 0) | - | ||||||||||||
| 441 | high = pos; | - | ||||||||||||
| 442 | else | - | ||||||||||||
| 443 | low = pos; | - | ||||||||||||
| 444 | pos = (high + low) / 2; | - | ||||||||||||
| 445 | } | - | ||||||||||||
| 446 | if (!res) | - | ||||||||||||
| 447 | fam = families[pos]; | - | ||||||||||||
| 448 | } | - | ||||||||||||
| 449 | - | |||||||||||||
| 450 | if (!fam && (flags & EnsureCreated)) { | - | ||||||||||||
| 451 | if (res < 0) | - | ||||||||||||
| 452 | pos++; | - | ||||||||||||
| 453 | - | |||||||||||||
| 454 | - | |||||||||||||
| 455 | if (!(count % 8)) { | - | ||||||||||||
| 456 | QtFontFamily **newFamilies = (QtFontFamily **) | - | ||||||||||||
| 457 | realloc(families, | - | ||||||||||||
| 458 | (((count+8) >> 3) << 3) * sizeof(QtFontFamily *)); | - | ||||||||||||
| 459 | do {if(!(newFamilies))qt_check_pointer(__FILE__,536543);} while (0); | - | ||||||||||||
| 460 | families = newFamilies; | - | ||||||||||||
| 461 | } | - | ||||||||||||
| 462 | - | |||||||||||||
| 463 | QtFontFamily *family = new QtFontFamily(f); | - | ||||||||||||
| 464 | memmove(families + pos + 1, families + pos, (count-pos)*sizeof(QtFontFamily *)); | - | ||||||||||||
| 465 | families[pos] = family; | - | ||||||||||||
| 466 | count++; | - | ||||||||||||
| 467 | - | |||||||||||||
| 468 | fam = families[pos]; | - | ||||||||||||
| 469 | } | - | ||||||||||||
| 470 | - | |||||||||||||
| 471 | if (fam && (flags & EnsurePopulated)) | - | ||||||||||||
| 472 | fam->ensurePopulated(); | - | ||||||||||||
| 473 | - | |||||||||||||
| 474 | return fam; | - | ||||||||||||
| 475 | } | - | ||||||||||||
| 476 | - | |||||||||||||
| 477 | - | |||||||||||||
| 478 | - | |||||||||||||
| 479 | static const int scriptForWritingSystem[] = { | - | ||||||||||||
| 480 | QChar::Script_Common, | - | ||||||||||||
| 481 | QChar::Script_Latin, | - | ||||||||||||
| 482 | QChar::Script_Greek, | - | ||||||||||||
| 483 | QChar::Script_Cyrillic, | - | ||||||||||||
| 484 | QChar::Script_Armenian, | - | ||||||||||||
| 485 | QChar::Script_Hebrew, | - | ||||||||||||
| 486 | QChar::Script_Arabic, | - | ||||||||||||
| 487 | QChar::Script_Syriac, | - | ||||||||||||
| 488 | QChar::Script_Thaana, | - | ||||||||||||
| 489 | QChar::Script_Devanagari, | - | ||||||||||||
| 490 | QChar::Script_Bengali, | - | ||||||||||||
| 491 | QChar::Script_Gurmukhi, | - | ||||||||||||
| 492 | QChar::Script_Gujarati, | - | ||||||||||||
| 493 | QChar::Script_Oriya, | - | ||||||||||||
| 494 | QChar::Script_Tamil, | - | ||||||||||||
| 495 | QChar::Script_Telugu, | - | ||||||||||||
| 496 | QChar::Script_Kannada, | - | ||||||||||||
| 497 | QChar::Script_Malayalam, | - | ||||||||||||
| 498 | QChar::Script_Sinhala, | - | ||||||||||||
| 499 | QChar::Script_Thai, | - | ||||||||||||
| 500 | QChar::Script_Lao, | - | ||||||||||||
| 501 | QChar::Script_Tibetan, | - | ||||||||||||
| 502 | QChar::Script_Myanmar, | - | ||||||||||||
| 503 | QChar::Script_Georgian, | - | ||||||||||||
| 504 | QChar::Script_Khmer, | - | ||||||||||||
| 505 | QChar::Script_Han, | - | ||||||||||||
| 506 | QChar::Script_Han, | - | ||||||||||||
| 507 | QChar::Script_Han, | - | ||||||||||||
| 508 | QChar::Script_Hangul, | - | ||||||||||||
| 509 | QChar::Script_Latin, | - | ||||||||||||
| 510 | QChar::Script_Common, | - | ||||||||||||
| 511 | QChar::Script_Ogham, | - | ||||||||||||
| 512 | QChar::Script_Runic, | - | ||||||||||||
| 513 | QChar::Script_Nko | - | ||||||||||||
| 514 | }; | - | ||||||||||||
| 515 | - | |||||||||||||
| 516 | static_assert(bool(sizeof(scriptForWritingSystem) / sizeof(scriptForWritingSystem[0]) == QFontDatabase::WritingSystemsCount), "sizeof(scriptForWritingSystem) / sizeof(scriptForWritingSystem[0]) == QFontDatabase::WritingSystemsCount"); | - | ||||||||||||
| 517 | - | |||||||||||||
| 518 | __attribute__((visibility("default"))) int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSystem) | - | ||||||||||||
| 519 | { | - | ||||||||||||
| 520 | return scriptForWritingSystem[writingSystem]; | - | ||||||||||||
| 521 | } | - | ||||||||||||
| 522 | static void parseFontName(const QString &name, QString &foundry, QString &family) | - | ||||||||||||
| 523 | { | - | ||||||||||||
| 524 | int i = name.indexOf(QLatin1Char('[')); | - | ||||||||||||
| 525 | int li = name.lastIndexOf(QLatin1Char(']')); | - | ||||||||||||
| 526 | if (i >= 0 && li >= 0 && i < li) { | - | ||||||||||||
| 527 | foundry = name.mid(i + 1, li - i - 1); | - | ||||||||||||
| 528 | if (i > 0 && name[i - 1] == QLatin1Char(' ')) | - | ||||||||||||
| 529 | i--; | - | ||||||||||||
| 530 | family = name.left(i); | - | ||||||||||||
| 531 | } else { | - | ||||||||||||
| 532 | foundry.clear(); | - | ||||||||||||
| 533 | family = name; | - | ||||||||||||
| 534 | } | - | ||||||||||||
| 535 | - | |||||||||||||
| 536 | - | |||||||||||||
| 537 | bool space = true; | - | ||||||||||||
| 538 | QChar *s = family.data(); | - | ||||||||||||
| 539 | int len = family.length(); | - | ||||||||||||
| 540 | while(len--) { | - | ||||||||||||
| 541 | if (space) *s = s->toUpper(); | - | ||||||||||||
| 542 | space = s->isSpace(); | - | ||||||||||||
| 543 | ++s; | - | ||||||||||||
| 544 | } | - | ||||||||||||
| 545 | - | |||||||||||||
| 546 | space = true; | - | ||||||||||||
| 547 | s = foundry.data(); | - | ||||||||||||
| 548 | len = foundry.length(); | - | ||||||||||||
| 549 | while(len--) { | - | ||||||||||||
| 550 | if (space) *s = s->toUpper(); | - | ||||||||||||
| 551 | space = s->isSpace(); | - | ||||||||||||
| 552 | ++s; | - | ||||||||||||
| 553 | } | - | ||||||||||||
| 554 | } | - | ||||||||||||
| 555 | - | |||||||||||||
| 556 | - | |||||||||||||
| 557 | struct QtFontDesc | - | ||||||||||||
| 558 | { | - | ||||||||||||
| 559 | inline QtFontDesc() : family(0), foundry(0), style(0), size(0) {} | - | ||||||||||||
| 560 | QtFontFamily *family; | - | ||||||||||||
| 561 | QtFontFoundry *foundry; | - | ||||||||||||
| 562 | QtFontStyle *style; | - | ||||||||||||
| 563 | QtFontSize *size; | - | ||||||||||||
| 564 | }; | - | ||||||||||||
| 565 | - | |||||||||||||
| 566 | static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDef *fontDef, bool multi) | - | ||||||||||||
| 567 | { | - | ||||||||||||
| 568 | fontDef->family = desc.family->name; | - | ||||||||||||
| 569 | if (! desc.foundry->name.isEmpty() && desc.family->count > 1) { | - | ||||||||||||
| 570 | fontDef->family += QString::fromLatin1(" ["); | - | ||||||||||||
| 571 | fontDef->family += desc.foundry->name; | - | ||||||||||||
| 572 | fontDef->family += QLatin1Char(']'); | - | ||||||||||||
| 573 | } | - | ||||||||||||
| 574 | - | |||||||||||||
| 575 | if (desc.style->smoothScalable | - | ||||||||||||
| 576 | || QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable() | - | ||||||||||||
| 577 | || (desc.style->bitmapScalable && (request.styleStrategy & QFont::PreferMatch))) { | - | ||||||||||||
| 578 | fontDef->pixelSize = request.pixelSize; | - | ||||||||||||
| 579 | } else { | - | ||||||||||||
| 580 | fontDef->pixelSize = desc.size->pixelSize; | - | ||||||||||||
| 581 | } | - | ||||||||||||
| 582 | fontDef->pointSize = request.pointSize; | - | ||||||||||||
| 583 | - | |||||||||||||
| 584 | fontDef->styleHint = request.styleHint; | - | ||||||||||||
| 585 | fontDef->styleStrategy = request.styleStrategy; | - | ||||||||||||
| 586 | - | |||||||||||||
| 587 | if (!multi) | - | ||||||||||||
| 588 | fontDef->weight = desc.style->key.weight; | - | ||||||||||||
| 589 | if (!multi) | - | ||||||||||||
| 590 | fontDef->style = desc.style->key.style; | - | ||||||||||||
| 591 | fontDef->fixedPitch = desc.family->fixedPitch; | - | ||||||||||||
| 592 | fontDef->stretch = desc.style->key.stretch; | - | ||||||||||||
| 593 | fontDef->ignorePitch = false; | - | ||||||||||||
| 594 | } | - | ||||||||||||
| 595 | - | |||||||||||||
| 596 | static QStringList familyList(const QFontDef &req) | - | ||||||||||||
| 597 | { | - | ||||||||||||
| 598 | - | |||||||||||||
| 599 | QStringList family_list; | - | ||||||||||||
| 600 | if (req.family.isEmpty()
| 0 | ||||||||||||
| 601 | return never executed: family_list;return family_list;never executed: return family_list; | 0 | ||||||||||||
| 602 | - | |||||||||||||
| 603 | QStringListconst auto list = req.family.splitsplitRef(QLatin1Char(',')); | - | ||||||||||||
| 604 | const int numFamilies = list.size(); | - | ||||||||||||
| 605 | family_list.reserve(numFamilies); | - | ||||||||||||
| 606 | for (int i = 0; i < numFamilies
| 0 | ||||||||||||
| 607 | QStringQStringRef str = list.at(i).trimmed(); | - | ||||||||||||
| 608 | if ((str.startsWith(QLatin1Char('"'))
| 0 | ||||||||||||
| 609 | || (str.startsWith(QLatin1Char('\''))
| 0 | ||||||||||||
| 610 | str = str.mid(1, str.length() - 2); never executed: str = str.mid(1, str.length() - 2); | 0 | ||||||||||||
| 611 | family_list << str;.toString(); | - | ||||||||||||
| 612 | } never executed: end of block | 0 | ||||||||||||
| 613 | - | |||||||||||||
| 614 | - | |||||||||||||
| 615 | QStringList subs_list; | 0 | ||||||||||||
QStringList::ConstIterator itfor (int i = family_list.constBegin(), end0, size = family_list.constEndsize(); for (; it != endi < size
| ||||||||||||||
| 616 | subs_listfamily_list never executed: += QFont::substitutes(*it);(family_list+= subs_list;.at(i));family_list += QFont::substitutes(family_list.at(i));never executed: family_list += QFont::substitutes(family_list.at(i)); | 0 | ||||||||||||
| 617 | - | |||||||||||||
| 618 | return never executed: family_list;return family_list;never executed: return family_list; | 0 | ||||||||||||
| 619 | } | - | ||||||||||||
| 620 | - | |||||||||||||
| 621 | namespace { namespace Q_QGS_privateDb { typedef QFontDatabasePrivate Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QFontDatabasePrivate, Q_QGS_privateDb::innerFunction, Q_QGS_privateDb::guard> privateDb; | - | ||||||||||||
| 622 | namespace { namespace Q_QGS_fontDatabaseMutex { typedef QMutex Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type (QMutex::Recursive))) : value (QMutex::Recursive) { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QMutex, Q_QGS_fontDatabaseMutex::innerFunction, Q_QGS_fontDatabaseMutex::guard> fontDatabaseMutex; | - | ||||||||||||
| 623 | - | |||||||||||||
| 624 | - | |||||||||||||
| 625 | void qt_cleanupFontDatabase() | - | ||||||||||||
| 626 | { | - | ||||||||||||
| 627 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 628 | if (db) { | - | ||||||||||||
| 629 | db->fallbacksCache.clear(); | - | ||||||||||||
| 630 | db->free(); | - | ||||||||||||
| 631 | } | - | ||||||||||||
| 632 | } | - | ||||||||||||
| 633 | - | |||||||||||||
| 634 | - | |||||||||||||
| 635 | QMutex *qt_fontdatabase_mutex() | - | ||||||||||||
| 636 | { | - | ||||||||||||
| 637 | return fontDatabaseMutex(); | - | ||||||||||||
| 638 | } | - | ||||||||||||
| 639 | - | |||||||||||||
| 640 | - | |||||||||||||
| 641 | void qt_registerFont(const QString &familyName, const QString &stylename, | - | ||||||||||||
| 642 | const QString &foundryname, int weight, | - | ||||||||||||
| 643 | QFont::Style style, int stretch, bool antialiased, | - | ||||||||||||
| 644 | bool scalable, int pixelSize, bool fixedPitch, | - | ||||||||||||
| 645 | const QSupportedWritingSystems &writingSystems, void *handle) | - | ||||||||||||
| 646 | { | - | ||||||||||||
| 647 | QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||
| 648 | - | |||||||||||||
| 649 | QtFontStyle::Key styleKey; | - | ||||||||||||
| 650 | styleKey.style = style; | - | ||||||||||||
| 651 | styleKey.weight = weight; | - | ||||||||||||
| 652 | styleKey.stretch = stretch; | - | ||||||||||||
| 653 | QtFontFamily *f = d->family(familyName, QFontDatabasePrivate::EnsureCreated); | - | ||||||||||||
| 654 | f->fixedPitch = fixedPitch; | - | ||||||||||||
| 655 | - | |||||||||||||
| 656 | for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { | - | ||||||||||||
| 657 | if (writingSystems.supported(QFontDatabase::WritingSystem(i))) | - | ||||||||||||
| 658 | f->writingSystems[i] = QtFontFamily::Supported; | - | ||||||||||||
| 659 | } | - | ||||||||||||
| 660 | - | |||||||||||||
| 661 | QtFontFoundry *foundry = f->foundry(foundryname, true); | - | ||||||||||||
| 662 | QtFontStyle *fontStyle = foundry->style(styleKey, stylename, true); | - | ||||||||||||
| 663 | fontStyle->smoothScalable = scalable; | - | ||||||||||||
| 664 | fontStyle->antialiased = antialiased; | - | ||||||||||||
| 665 | QtFontSize *size = fontStyle->pixelSize(pixelSize ? pixelSize : 0xffff, true); | - | ||||||||||||
| 666 | if (size->handle) { | - | ||||||||||||
| 667 | QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||
| 668 | if (integration) | - | ||||||||||||
| 669 | integration->fontDatabase()->releaseHandle(size->handle); | - | ||||||||||||
| 670 | } | - | ||||||||||||
| 671 | size->handle = handle; | - | ||||||||||||
| 672 | f->populated = true; | - | ||||||||||||
| 673 | } | - | ||||||||||||
| 674 | - | |||||||||||||
| 675 | void qt_registerFontFamily(const QString &familyName) | - | ||||||||||||
| 676 | { | - | ||||||||||||
| 677 | - | |||||||||||||
| 678 | privateDb()->family(familyName, QFontDatabasePrivate::EnsureCreated); | - | ||||||||||||
| 679 | } | - | ||||||||||||
| 680 | - | |||||||||||||
| 681 | void qt_registerAliasToFontFamily(const QString &familyName, const QString &alias) | - | ||||||||||||
| 682 | { | - | ||||||||||||
| 683 | if (alias.isEmpty()) | - | ||||||||||||
| 684 | return; | - | ||||||||||||
| 685 | - | |||||||||||||
| 686 | QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||
| 687 | QtFontFamily *f = d->family(familyName, QFontDatabasePrivate::RequestFamily); | - | ||||||||||||
| 688 | if (!f) | - | ||||||||||||
| 689 | return; | - | ||||||||||||
| 690 | - | |||||||||||||
| 691 | if (f->aliases.contains(alias, Qt::CaseInsensitive)) | - | ||||||||||||
| 692 | return; | - | ||||||||||||
| 693 | - | |||||||||||||
| 694 | f->aliases.push_back(alias); | - | ||||||||||||
| 695 | } | - | ||||||||||||
| 696 | - | |||||||||||||
| 697 | QString qt_resolveFontFamilyAlias(const QString &alias) | - | ||||||||||||
| 698 | { | - | ||||||||||||
| 699 | if (!alias.isEmpty()) { | - | ||||||||||||
| 700 | const QFontDatabasePrivate *d = privateDb(); | - | ||||||||||||
| 701 | for (int i = 0; i < d->count; ++i) | - | ||||||||||||
| 702 | if (d->families[i]->matchesFamilyName(alias)) | - | ||||||||||||
| 703 | return d->families[i]->name; | - | ||||||||||||
| 704 | } | - | ||||||||||||
| 705 | return alias; | - | ||||||||||||
| 706 | } | - | ||||||||||||
| 707 | - | |||||||||||||
| 708 | QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const | - | ||||||||||||
| 709 | { | - | ||||||||||||
| 710 | (void)family;; | - | ||||||||||||
| 711 | (void)styleHint;; | - | ||||||||||||
| 712 | - | |||||||||||||
| 713 | QStringList preferredFallbacks; | - | ||||||||||||
| 714 | QStringList otherFallbacks; | - | ||||||||||||
| 715 | - | |||||||||||||
| 716 | size_t writingSystem = std::find(scriptForWritingSystem, | - | ||||||||||||
| 717 | scriptForWritingSystem + QFontDatabase::WritingSystemsCount, | - | ||||||||||||
| 718 | script) - scriptForWritingSystem; | - | ||||||||||||
| 719 | if (writingSystem >= QFontDatabase::WritingSystemsCount) | - | ||||||||||||
| 720 | writingSystem = QFontDatabase::Any; | - | ||||||||||||
| 721 | - | |||||||||||||
| 722 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 723 | for (int i = 0; i < db->count; ++i) { | - | ||||||||||||
| 724 | QtFontFamily *f = db->families[i]; | - | ||||||||||||
| 725 | - | |||||||||||||
| 726 | f->ensurePopulated(); | - | ||||||||||||
| 727 | - | |||||||||||||
| 728 | if (writingSystem > QFontDatabase::Any && f->writingSystems[writingSystem] != QtFontFamily::Supported) | - | ||||||||||||
| 729 | continue; | - | ||||||||||||
| 730 | - | |||||||||||||
| 731 | for (int j = 0; j < f->count; ++j) { | - | ||||||||||||
| 732 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 733 | - | |||||||||||||
| 734 | for (int k = 0; k < foundry->count; ++k) { | - | ||||||||||||
| 735 | QString name = foundry->name.isEmpty() | - | ||||||||||||
| 736 | ? f->name | - | ||||||||||||
| 737 | : f->name + QLatin1String(" [") + foundry->name + QLatin1Char(']'); | - | ||||||||||||
| 738 | if (style == foundry->styles[k]->key.style) | - | ||||||||||||
| 739 | preferredFallbacks.append(name); | - | ||||||||||||
| 740 | else | - | ||||||||||||
| 741 | otherFallbacks.append(name); | - | ||||||||||||
| 742 | } | - | ||||||||||||
| 743 | } | - | ||||||||||||
| 744 | } | - | ||||||||||||
| 745 | - | |||||||||||||
| 746 | return preferredFallbacks + otherFallbacks; | - | ||||||||||||
| 747 | } | - | ||||||||||||
| 748 | - | |||||||||||||
| 749 | static void initializeDb(); | - | ||||||||||||
| 750 | - | |||||||||||||
| 751 | static QStringList fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) | - | ||||||||||||
| 752 | { | - | ||||||||||||
| 753 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 754 | if (!db->count) | - | ||||||||||||
| 755 | initializeDb(); | - | ||||||||||||
| 756 | - | |||||||||||||
| 757 | const FallbacksCacheKey cacheKey = { family, style, styleHint, script }; | - | ||||||||||||
| 758 | - | |||||||||||||
| 759 | if (const QStringList *fallbacks = db->fallbacksCache.object(cacheKey)) | - | ||||||||||||
| 760 | return *fallbacks; | - | ||||||||||||
| 761 | - | |||||||||||||
| 762 | - | |||||||||||||
| 763 | QStringList retList = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(family,style,styleHint,script); | - | ||||||||||||
| 764 | - | |||||||||||||
| 765 | QStringList::iterator i; | - | ||||||||||||
| 766 | for (i = retList.begin(); i != retList.end(); ++i) { | - | ||||||||||||
| 767 | bool contains = false; | - | ||||||||||||
| 768 | for (int j = 0; j < db->count; j++) { | - | ||||||||||||
| 769 | if (db->families[j]->matchesFamilyName(*i)) { | - | ||||||||||||
| 770 | contains = true; | - | ||||||||||||
| 771 | break; | - | ||||||||||||
| 772 | } | - | ||||||||||||
| 773 | } | - | ||||||||||||
| 774 | if (!contains) { | - | ||||||||||||
| 775 | i = retList.erase(i); | - | ||||||||||||
| 776 | --i; | - | ||||||||||||
| 777 | } | - | ||||||||||||
| 778 | } | - | ||||||||||||
| 779 | - | |||||||||||||
| 780 | db->fallbacksCache.insert(cacheKey, new QStringList(retList)); | - | ||||||||||||
| 781 | - | |||||||||||||
| 782 | return retList; | - | ||||||||||||
| 783 | } | - | ||||||||||||
| 784 | - | |||||||||||||
| 785 | QStringList qt_fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) | - | ||||||||||||
| 786 | { | - | ||||||||||||
| 787 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 788 | return fallbacksForFamily(family, style, styleHint, script); | - | ||||||||||||
| 789 | } | - | ||||||||||||
| 790 | - | |||||||||||||
| 791 | static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt); | - | ||||||||||||
| 792 | - | |||||||||||||
| 793 | static void initializeDb() | - | ||||||||||||
| 794 | { | - | ||||||||||||
| 795 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 796 | - | |||||||||||||
| 797 | - | |||||||||||||
| 798 | if (!db->count) | - | ||||||||||||
| 799 | QGuiApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase(); | - | ||||||||||||
| 800 | - | |||||||||||||
| 801 | if (db->reregisterAppFonts) { | - | ||||||||||||
| 802 | for (int i = 0; i < db->applicationFonts.count(); i++) { | - | ||||||||||||
| 803 | if (!db->applicationFonts.at(i).families.isEmpty()) | - | ||||||||||||
| 804 | registerFont(&db->applicationFonts[i]); | - | ||||||||||||
| 805 | } | - | ||||||||||||
| 806 | db->reregisterAppFonts = false; | - | ||||||||||||
| 807 | } | - | ||||||||||||
| 808 | } | - | ||||||||||||
| 809 | - | |||||||||||||
| 810 | static inline void load(const QString & = QString(), int = -1) | - | ||||||||||||
| 811 | { | - | ||||||||||||
| 812 | - | |||||||||||||
| 813 | if (!privateDb()->count) | - | ||||||||||||
| 814 | initializeDb(); | - | ||||||||||||
| 815 | } | - | ||||||||||||
| 816 | - | |||||||||||||
| 817 | static | - | ||||||||||||
| 818 | QFontEngine *loadSingleEngine(int script, | - | ||||||||||||
| 819 | const QFontDef &request, | - | ||||||||||||
| 820 | QtFontFamily *family, QtFontFoundry *foundry, | - | ||||||||||||
| 821 | QtFontStyle *style, QtFontSize *size) | - | ||||||||||||
| 822 | { | - | ||||||||||||
| 823 | (void)foundry;; | - | ||||||||||||
| 824 | - | |||||||||||||
| 825 | ((!(size)) ? qt_assert("size",__FILE__,920922) : qt_noop()); | - | ||||||||||||
| 826 | QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); | - | ||||||||||||
| 827 | int pixelSize = size->pixelSize; | - | ||||||||||||
| 828 | if (!pixelSize || (style->smoothScalable && pixelSize == 0xffff) | - | ||||||||||||
| 829 | || pfdb->fontsAlwaysScalable()) { | - | ||||||||||||
| 830 | pixelSize = request.pixelSize; | - | ||||||||||||
| 831 | } | - | ||||||||||||
| 832 | - | |||||||||||||
| 833 | QFontDef def = request; | - | ||||||||||||
| 834 | def.pixelSize = pixelSize; | - | ||||||||||||
| 835 | - | |||||||||||||
| 836 | QFontCache *fontCache = QFontCache::instance(); | - | ||||||||||||
| 837 | - | |||||||||||||
| 838 | QFontCache::Key key(def,script); | - | ||||||||||||
| 839 | QFontEngine *engine = fontCache->findEngine(key); | - | ||||||||||||
| 840 | if (!engine) { | - | ||||||||||||
| 841 | const bool cacheForCommonScript = script != QChar::Script_Common | - | ||||||||||||
| 842 | && (family->writingSystems[QFontDatabase::Latin] & QtFontFamily::Supported) != 0; | - | ||||||||||||
| 843 | - | |||||||||||||
| 844 | if (__builtin_expect(!!(cacheForCommonScript), true)) { | - | ||||||||||||
| 845 | - | |||||||||||||
| 846 | key.script = QChar::Script_Common; | - | ||||||||||||
| 847 | engine = fontCache->findEngine(key); | - | ||||||||||||
| 848 | key.script = script; | - | ||||||||||||
| 849 | if (engine) { | - | ||||||||||||
| 850 | - | |||||||||||||
| 851 | if (__builtin_expect(!!(!engine->supportsScript(QChar::Script(script))), false)) { | - | ||||||||||||
| 852 | QMessageLogger(__FILE__, 947949, __PRETTY_FUNCTION__).warning(" OpenType support missing for script %d", script); | - | ||||||||||||
| 853 | return 0; | - | ||||||||||||
| 854 | } | - | ||||||||||||
| 855 | - | |||||||||||||
| 856 | engine->isSmoothlyScalable = style->smoothScalable; | - | ||||||||||||
| 857 | fontCache->insertEngine(key, engine); | - | ||||||||||||
| 858 | return engine; | - | ||||||||||||
| 859 | } | - | ||||||||||||
| 860 | } | - | ||||||||||||
| 861 | - | |||||||||||||
| 862 | - | |||||||||||||
| 863 | - | |||||||||||||
| 864 | - | |||||||||||||
| 865 | if (style->key.stretch != 0 && request.stretch != 0 | - | ||||||||||||
| 866 | && (request.styleName.isEmpty() || request.styleName != style->styleName)) { | - | ||||||||||||
| 867 | def.stretch = (request.stretch * 100 + 50) / style->key.stretch; | - | ||||||||||||
| 868 | } | - | ||||||||||||
| 869 | - | |||||||||||||
| 870 | engine = pfdb->fontEngine(def, size->handle); | - | ||||||||||||
| 871 | if (engine) { | - | ||||||||||||
| 872 | - | |||||||||||||
| 873 | if (!engine->supportsScript(QChar::Script(script))) { | - | ||||||||||||
| 874 | QMessageLogger(__FILE__, 969971, __PRETTY_FUNCTION__).warning(" OpenType support missing for script %d", script); | - | ||||||||||||
| 875 | if (engine->ref.load() == 0) | - | ||||||||||||
| 876 | delete engine; | - | ||||||||||||
| 877 | return 0; | - | ||||||||||||
| 878 | } | - | ||||||||||||
| 879 | - | |||||||||||||
| 880 | engine->isSmoothlyScalable = style->smoothScalable; | - | ||||||||||||
| 881 | fontCache->insertEngine(key, engine); | - | ||||||||||||
| 882 | - | |||||||||||||
| 883 | if (__builtin_expect(!!(cacheForCommonScript && !engine->symbol), true)) { | - | ||||||||||||
| 884 | - | |||||||||||||
| 885 | key.script = QChar::Script_Common; | - | ||||||||||||
| 886 | if (!fontCache->findEngine(key)) | - | ||||||||||||
| 887 | fontCache->insertEngine(key, engine); | - | ||||||||||||
| 888 | } | - | ||||||||||||
| 889 | } | - | ||||||||||||
| 890 | } | - | ||||||||||||
| 891 | return engine; | - | ||||||||||||
| 892 | } | - | ||||||||||||
| 893 | - | |||||||||||||
| 894 | static | - | ||||||||||||
| 895 | QFontEngine *loadEngine(int script, const QFontDef &request, | - | ||||||||||||
| 896 | QtFontFamily *family, QtFontFoundry *foundry, | - | ||||||||||||
| 897 | QtFontStyle *style, QtFontSize *size) | - | ||||||||||||
| 898 | { | - | ||||||||||||
| 899 | QFontEngine *engine = loadSingleEngine(script, request, family, foundry, style, size); | - | ||||||||||||
| 900 | - | |||||||||||||
| 901 | if (engine && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol) { | - | ||||||||||||
| 902 | QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); | - | ||||||||||||
| 903 | QFontEngineMulti *pfMultiEngine = pfdb->fontEngineMulti(engine, QChar::Script(script)); | - | ||||||||||||
| 904 | if (!request.fallBackFamilies.isEmpty()) { | - | ||||||||||||
| 905 | QStringList fallbacks = request.fallBackFamilies; | - | ||||||||||||
| 906 | - | |||||||||||||
| 907 | QFont::StyleHint styleHint = QFont::StyleHint(request.styleHint); | - | ||||||||||||
| 908 | if (styleHint == QFont::AnyStyle && request.fixedPitch) | - | ||||||||||||
| 909 | styleHint = QFont::TypeWriter; | - | ||||||||||||
| 910 | - | |||||||||||||
| 911 | fallbacks += fallbacksForFamily(family->name, QFont::Style(style->key.style), styleHint, QChar::Script(script)); | - | ||||||||||||
| 912 | - | |||||||||||||
| 913 | pfMultiEngine->setFallbackFamiliesList(fallbacks); | - | ||||||||||||
| 914 | } | - | ||||||||||||
| 915 | engine = pfMultiEngine; | - | ||||||||||||
| 916 | - | |||||||||||||
| 917 | - | |||||||||||||
| 918 | - | |||||||||||||
| 919 | QFontCache::Key key(request, script, 1); | - | ||||||||||||
| 920 | QFontCache::instance()->insertEngine(key, engine); | - | ||||||||||||
| 921 | } | - | ||||||||||||
| 922 | - | |||||||||||||
| 923 | return engine; | - | ||||||||||||
| 924 | } | - | ||||||||||||
| 925 | - | |||||||||||||
| 926 | static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt) | - | ||||||||||||
| 927 | { | - | ||||||||||||
| 928 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 929 | - | |||||||||||||
| 930 | fnt->families = QGuiApplicationPrivate::platformIntegration()->fontDatabase()->addApplicationFont(fnt->data,fnt->fileName); | - | ||||||||||||
| 931 | - | |||||||||||||
| 932 | db->reregisterAppFonts = true; | - | ||||||||||||
| 933 | } | - | ||||||||||||
| 934 | - | |||||||||||||
| 935 | static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &styleKey, | - | ||||||||||||
| 936 | const QString &styleName = QString()) | - | ||||||||||||
| 937 | { | - | ||||||||||||
| 938 | int best = 0; | - | ||||||||||||
| 939 | int dist = 0xffff; | - | ||||||||||||
| 940 | - | |||||||||||||
| 941 | for ( int i = 0; i < foundry->count; i++ ) { | - | ||||||||||||
| 942 | QtFontStyle *style = foundry->styles[i]; | - | ||||||||||||
| 943 | - | |||||||||||||
| 944 | if (!styleName.isEmpty() && styleName == style->styleName) { | - | ||||||||||||
| 945 | dist = 0; | - | ||||||||||||
| 946 | best = i; | - | ||||||||||||
| 947 | break; | - | ||||||||||||
| 948 | } | - | ||||||||||||
| 949 | - | |||||||||||||
| 950 | int d = qAbs( styleKey.weight - style->key.weight ); | - | ||||||||||||
| 951 | - | |||||||||||||
| 952 | if ( styleKey.stretch != 0 && style->key.stretch != 0 ) { | - | ||||||||||||
| 953 | d += qAbs( styleKey.stretch - style->key.stretch ); | - | ||||||||||||
| 954 | } | - | ||||||||||||
| 955 | - | |||||||||||||
| 956 | if (styleKey.style != style->key.style) { | - | ||||||||||||
| 957 | if (styleKey.style != QFont::StyleNormal && style->key.style != QFont::StyleNormal) | - | ||||||||||||
| 958 | - | |||||||||||||
| 959 | d += 0x0001; | - | ||||||||||||
| 960 | else | - | ||||||||||||
| 961 | d += 0x1000; | - | ||||||||||||
| 962 | } | - | ||||||||||||
| 963 | - | |||||||||||||
| 964 | if ( d < dist ) { | - | ||||||||||||
| 965 | best = i; | - | ||||||||||||
| 966 | dist = d; | - | ||||||||||||
| 967 | } | - | ||||||||||||
| 968 | } | - | ||||||||||||
| 969 | - | |||||||||||||
| 970 | if (false) QMessageLogger(__FILE__, 10651067, __PRETTY_FUNCTION__).debug( " best style has distance 0x%x", dist ); dead code: QMessageLogger(__FILE__, 1067, __PRETTY_FUNCTION__).debug( " best style has distance 0x%x", dist ); | - | ||||||||||||
| 971 | return foundry->styles[best]; | - | ||||||||||||
| 972 | } | - | ||||||||||||
| 973 | - | |||||||||||||
| 974 | - | |||||||||||||
| 975 | static | - | ||||||||||||
| 976 | unsigned int bestFoundry(int script, unsigned int score, int styleStrategy, | - | ||||||||||||
| 977 | const QtFontFamily *family, const QString &foundry_name, | - | ||||||||||||
| 978 | QtFontStyle::Key styleKey, int pixelSize, char pitch, | - | ||||||||||||
| 979 | QtFontDesc *desc, const QString &styleName = QString()) | - | ||||||||||||
| 980 | { | - | ||||||||||||
| 981 | (void)script;; | - | ||||||||||||
| 982 | (void)pitch;; | - | ||||||||||||
| 983 | - | |||||||||||||
| 984 | desc->foundry = 0; | - | ||||||||||||
| 985 | desc->style = 0; | - | ||||||||||||
| 986 | desc->size = 0; | - | ||||||||||||
| 987 | - | |||||||||||||
| 988 | - | |||||||||||||
| 989 | if (false) QMessageLogger(__FILE__, 10841086, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 990 | - | |||||||||||||
| 991 | for (int x = 0; x < family->count; ++x) { | - | ||||||||||||
| 992 | QtFontFoundry *foundry = family->foundries[x]; | - | ||||||||||||
| 993 | if (!foundry_name.isEmpty() && foundry->name.compare(foundry_name, Qt::CaseInsensitive) != 0) | - | ||||||||||||
| 994 | continue; | - | ||||||||||||
| 995 | - | |||||||||||||
| 996 | if (false) QMessageLogger(__FILE__, 10911093, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 997 | 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); | - | ||||||||||||
| 998 | - | |||||||||||||
| 999 | QtFontStyle *style = bestStyle(foundry, styleKey, styleName); | - | ||||||||||||
| 1000 | - | |||||||||||||
| 1001 | if (!style->smoothScalable && (styleStrategy & QFont::ForceOutline)) { | - | ||||||||||||
| 1002 | if (false) QMessageLogger(__FILE__, 10971099, __PRETTY_FUNCTION__).debug(" ForceOutline set, but not smoothly scalable"); dead code: QMessageLogger(__FILE__, 1099, __PRETTY_FUNCTION__).debug(" ForceOutline set, but not smoothly scalable"); | - | ||||||||||||
| 1003 | continue; | - | ||||||||||||
| 1004 | } | - | ||||||||||||
| 1005 | - | |||||||||||||
| 1006 | int px = -1; | - | ||||||||||||
| 1007 | QtFontSize *size = 0; | - | ||||||||||||
| 1008 | - | |||||||||||||
| 1009 | - | |||||||||||||
| 1010 | if (!(styleStrategy & QFont::ForceOutline)) { | - | ||||||||||||
| 1011 | size = style->pixelSize(pixelSize); | - | ||||||||||||
| 1012 | if (size) { | - | ||||||||||||
| 1013 | if (false) QMessageLogger(__FILE__, 11081110, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 1014 | px = size->pixelSize; | - | ||||||||||||
| 1015 | } | - | ||||||||||||
| 1016 | } | - | ||||||||||||
| 1017 | - | |||||||||||||
| 1018 | - | |||||||||||||
| 1019 | if (!size && style->smoothScalable && ! (styleStrategy & QFont::PreferBitmap)) { | - | ||||||||||||
| 1020 | size = style->pixelSize(0xffff); | - | ||||||||||||
| 1021 | if (size) { | - | ||||||||||||
| 1022 | if (false) QMessageLogger(__FILE__, 11171119, __PRETTY_FUNCTION__).debug(" found smoothly scalable font (%d pixels)", pixelSize); dead code: QMessageLogger(__FILE__, 1119, __PRETTY_FUNCTION__).debug(" found smoothly scalable font (%d pixels)", pixelSize); | - | ||||||||||||
| 1023 | px = pixelSize; | - | ||||||||||||
| 1024 | } | - | ||||||||||||
| 1025 | } | - | ||||||||||||
| 1026 | - | |||||||||||||
| 1027 | - | |||||||||||||
| 1028 | if (!size && style->bitmapScalable && (styleStrategy & QFont::PreferMatch)) { | - | ||||||||||||
| 1029 | size = style->pixelSize(0); | - | ||||||||||||
| 1030 | if (size) { | - | ||||||||||||
| 1031 | if (false) QMessageLogger(__FILE__, 11261128, __PRETTY_FUNCTION__).debug(" found bitmap scalable font (%d pixels)", pixelSize); dead code: QMessageLogger(__FILE__, 1128, __PRETTY_FUNCTION__).debug(" found bitmap scalable font (%d pixels)", pixelSize); | - | ||||||||||||
| 1032 | px = pixelSize; | - | ||||||||||||
| 1033 | } | - | ||||||||||||
| 1034 | } | - | ||||||||||||
| 1035 | - | |||||||||||||
| 1036 | - | |||||||||||||
| 1037 | - | |||||||||||||
| 1038 | if (! size) { | - | ||||||||||||
| 1039 | unsigned int distance = ~0u; | - | ||||||||||||
| 1040 | for (int x = 0; x < style->count; ++x) { | - | ||||||||||||
| 1041 | - | |||||||||||||
| 1042 | unsigned int d; | - | ||||||||||||
| 1043 | if (style->pixelSizes[x].pixelSize < pixelSize) { | - | ||||||||||||
| 1044 | - | |||||||||||||
| 1045 | - | |||||||||||||
| 1046 | - | |||||||||||||
| 1047 | d = pixelSize - style->pixelSizes[x].pixelSize + 1; | - | ||||||||||||
| 1048 | } else { | - | ||||||||||||
| 1049 | d = style->pixelSizes[x].pixelSize - pixelSize; | - | ||||||||||||
| 1050 | } | - | ||||||||||||
| 1051 | - | |||||||||||||
| 1052 | if (d < distance) { | - | ||||||||||||
| 1053 | distance = d; | - | ||||||||||||
| 1054 | size = style->pixelSizes + x; | - | ||||||||||||
| 1055 | if (false) QMessageLogger(__FILE__, 11501152, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 1056 | } | - | ||||||||||||
| 1057 | } | - | ||||||||||||
| 1058 | - | |||||||||||||
| 1059 | if (!size) { | - | ||||||||||||
| 1060 | if (false) QMessageLogger(__FILE__, 11551157, __PRETTY_FUNCTION__).debug(" no size supports the script we want"); dead code: QMessageLogger(__FILE__, 1157, __PRETTY_FUNCTION__).debug(" no size supports the script we want"); | - | ||||||||||||
| 1061 | continue; | - | ||||||||||||
| 1062 | } | - | ||||||||||||
| 1063 | - | |||||||||||||
| 1064 | if (style->bitmapScalable && ! (styleStrategy & QFont::PreferQuality) && | - | ||||||||||||
| 1065 | (distance * 10 / pixelSize) >= 2) { | - | ||||||||||||
| 1066 | - | |||||||||||||
| 1067 | - | |||||||||||||
| 1068 | size = style->pixelSize(0); | - | ||||||||||||
| 1069 | px = pixelSize; | - | ||||||||||||
| 1070 | } else { | - | ||||||||||||
| 1071 | px = size->pixelSize; | - | ||||||||||||
| 1072 | } | - | ||||||||||||
| 1073 | } | - | ||||||||||||
| 1074 | - | |||||||||||||
| 1075 | - | |||||||||||||
| 1076 | unsigned int this_score = 0x0000; | - | ||||||||||||
| 1077 | enum { | - | ||||||||||||
| 1078 | PitchMismatch = 0x4000, | - | ||||||||||||
| 1079 | StyleMismatch = 0x2000, | - | ||||||||||||
| 1080 | BitmapScaledPenalty = 0x1000 | - | ||||||||||||
| 1081 | }; | - | ||||||||||||
| 1082 | if (pitch != '*') { | - | ||||||||||||
| 1083 | if ((pitch == 'm' && !family->fixedPitch) | - | ||||||||||||
| 1084 | || (pitch == 'p' && family->fixedPitch)) | - | ||||||||||||
| 1085 | this_score += PitchMismatch; | - | ||||||||||||
| 1086 | } | - | ||||||||||||
| 1087 | if (styleKey != style->key) | - | ||||||||||||
| 1088 | this_score += StyleMismatch; | - | ||||||||||||
| 1089 | if (!style->smoothScalable && px != size->pixelSize) | - | ||||||||||||
| 1090 | this_score += BitmapScaledPenalty; | - | ||||||||||||
| 1091 | if (px != pixelSize) | - | ||||||||||||
| 1092 | this_score += qAbs(px - pixelSize); | - | ||||||||||||
| 1093 | - | |||||||||||||
| 1094 | if (this_score < score) { | - | ||||||||||||
| 1095 | if (false) QMessageLogger(__FILE__, 11901192, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 1096 | this_score, score); dead code: QMessageLogger(__FILE__, 1192, __PRETTY_FUNCTION__).debug(" found a match: score %x best score so far %x", this_score, score); | - | ||||||||||||
| 1097 | - | |||||||||||||
| 1098 | score = this_score; | - | ||||||||||||
| 1099 | desc->foundry = foundry; | - | ||||||||||||
| 1100 | desc->style = style; | - | ||||||||||||
| 1101 | desc->size = size; | - | ||||||||||||
| 1102 | } else { | - | ||||||||||||
| 1103 | if (false) QMessageLogger(__FILE__, 11981200, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 1104 | } | - | ||||||||||||
| 1105 | } | - | ||||||||||||
| 1106 | - | |||||||||||||
| 1107 | return score; | - | ||||||||||||
| 1108 | } | - | ||||||||||||
| 1109 | - | |||||||||||||
| 1110 | static bool matchFamilyName(const QString &familyName, QtFontFamily *f) | - | ||||||||||||
| 1111 | { | - | ||||||||||||
| 1112 | if (familyName.isEmpty()) | - | ||||||||||||
| 1113 | return true; | - | ||||||||||||
| 1114 | return f->matchesFamilyName(familyName); | - | ||||||||||||
| 1115 | } | - | ||||||||||||
| 1116 | - | |||||||||||||
| 1117 | - | |||||||||||||
| 1118 | - | |||||||||||||
| 1119 | - | |||||||||||||
| 1120 | - | |||||||||||||
| 1121 | - | |||||||||||||
| 1122 | static int match(int script, const QFontDef &request, | - | ||||||||||||
| 1123 | const QString &family_name, const QString &foundry_name, | - | ||||||||||||
| 1124 | QtFontDesc *desc, const QList<int> &blacklistedFamilies) | - | ||||||||||||
| 1125 | { | - | ||||||||||||
| 1126 | int result = -1; | - | ||||||||||||
| 1127 | - | |||||||||||||
| 1128 | QtFontStyle::Key styleKey; | - | ||||||||||||
| 1129 | styleKey.style = request.style; | - | ||||||||||||
| 1130 | styleKey.weight = request.weight; | - | ||||||||||||
| 1131 | styleKey.stretch = request.stretch; | - | ||||||||||||
| 1132 | char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p'; | - | ||||||||||||
| 1133 | - | |||||||||||||
| 1134 | - | |||||||||||||
| 1135 | if (false) QMessageLogger(__FILE__, 12301232, __PRETTY_FUNCTION__).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); | - | ||||||||||||
| 1136 | " 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); | - | ||||||||||||
| 1137 | " 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); | - | ||||||||||||
| 1138 | " 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); | - | ||||||||||||
| 1139 | " 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); | - | ||||||||||||
| 1140 | " 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); | - | ||||||||||||
| 1141 | " 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); | - | ||||||||||||
| 1142 | 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); | - | ||||||||||||
| 1143 | 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); | - | ||||||||||||
| 1144 | 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); | - | ||||||||||||
| 1145 | - | |||||||||||||
| 1146 | desc->family = 0; | - | ||||||||||||
| 1147 | desc->foundry = 0; | - | ||||||||||||
| 1148 | desc->style = 0; | - | ||||||||||||
| 1149 | desc->size = 0; | - | ||||||||||||
| 1150 | - | |||||||||||||
| 1151 | unsigned int score = ~0u; | - | ||||||||||||
| 1152 | - | |||||||||||||
| 1153 | load(family_name, script); | - | ||||||||||||
| 1154 | - | |||||||||||||
| 1155 | size_t writingSystem = std::find(scriptForWritingSystem, scriptForWritingSystem + | - | ||||||||||||
| 1156 | QFontDatabase::WritingSystemsCount, script) - scriptForWritingSystem; | - | ||||||||||||
| 1157 | if (writingSystem >= QFontDatabase::WritingSystemsCount) | - | ||||||||||||
| 1158 | writingSystem = QFontDatabase::Any; | - | ||||||||||||
| 1159 | - | |||||||||||||
| 1160 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 1161 | for (int x = 0; x < db->count; ++x) { | - | ||||||||||||
| 1162 | if (blacklistedFamilies.contains(x)) | - | ||||||||||||
| 1163 | continue; | - | ||||||||||||
| 1164 | QtFontDesc test; | - | ||||||||||||
| 1165 | test.family = db->families[x]; | - | ||||||||||||
| 1166 | - | |||||||||||||
| 1167 | if (!matchFamilyName(family_name, test.family)) | - | ||||||||||||
| 1168 | continue; | - | ||||||||||||
| 1169 | - | |||||||||||||
| 1170 | test.family->ensurePopulated(); | - | ||||||||||||
| 1171 | - | |||||||||||||
| 1172 | - | |||||||||||||
| 1173 | if (writingSystem != QFontDatabase::Any && !(test.family->writingSystems[writingSystem] & QtFontFamily::Supported)) | - | ||||||||||||
| 1174 | continue; | - | ||||||||||||
| 1175 | - | |||||||||||||
| 1176 | - | |||||||||||||
| 1177 | - | |||||||||||||
| 1178 | unsigned int newscore = | - | ||||||||||||
| 1179 | bestFoundry(script, score, request.styleStrategy, | - | ||||||||||||
| 1180 | test.family, foundry_name, styleKey, request.pixelSize, pitch, | - | ||||||||||||
| 1181 | &test, request.styleName); | - | ||||||||||||
| 1182 | if (test.foundry == 0 && !foundry_name.isEmpty()) { | - | ||||||||||||
| 1183 | - | |||||||||||||
| 1184 | - | |||||||||||||
| 1185 | newscore = bestFoundry(script, score, request.styleStrategy, test.family, | - | ||||||||||||
| 1186 | QString(), styleKey, request.pixelSize, | - | ||||||||||||
| 1187 | pitch, &test, request.styleName); | - | ||||||||||||
| 1188 | } | - | ||||||||||||
| 1189 | - | |||||||||||||
| 1190 | if (newscore < score) { | - | ||||||||||||
| 1191 | result = x; | - | ||||||||||||
| 1192 | score = newscore; | - | ||||||||||||
| 1193 | *desc = test; | - | ||||||||||||
| 1194 | } | - | ||||||||||||
| 1195 | if (newscore < 10) | - | ||||||||||||
| 1196 | break; | - | ||||||||||||
| 1197 | } | - | ||||||||||||
| 1198 | return result; | - | ||||||||||||
| 1199 | } | - | ||||||||||||
| 1200 | - | |||||||||||||
| 1201 | static QString styleStringHelper(int weight, QFont::Style style) | - | ||||||||||||
| 1202 | { | - | ||||||||||||
| 1203 | QString result; | - | ||||||||||||
| 1204 | if (weight > QFont::Normal) { | - | ||||||||||||
| 1205 | if (weight >= QFont::Black) | - | ||||||||||||
| 1206 | result = QCoreApplication::translate("QFontDatabase", "Black"); | - | ||||||||||||
| 1207 | else if (weight >= QFont::ExtraBold) | - | ||||||||||||
| 1208 | result = QCoreApplication::translate("QFontDatabase", "Extra Bold"); | - | ||||||||||||
| 1209 | else if (weight >= QFont::Bold) | - | ||||||||||||
| 1210 | result = QCoreApplication::translate("QFontDatabase", "Bold"); | - | ||||||||||||
| 1211 | else if (weight >= QFont::DemiBold) | - | ||||||||||||
| 1212 | result = QCoreApplication::translate("QFontDatabase", "Demi Bold"); | - | ||||||||||||
| 1213 | else if (weight >= QFont::Medium) | - | ||||||||||||
| 1214 | result = QCoreApplication::translate("QFontDatabase", "Medium", "The Medium font weight"); | - | ||||||||||||
| 1215 | } else { | - | ||||||||||||
| 1216 | if (weight <= QFont::Thin) | - | ||||||||||||
| 1217 | result = QCoreApplication::translate("QFontDatabase", "Thin"); | - | ||||||||||||
| 1218 | else if (weight <= QFont::ExtraLight) | - | ||||||||||||
| 1219 | result = QCoreApplication::translate("QFontDatabase", "Extra Light"); | - | ||||||||||||
| 1220 | else if (weight <= QFont::Light) | - | ||||||||||||
| 1221 | result = QCoreApplication::translate("QFontDatabase", "Light"); | - | ||||||||||||
| 1222 | } | - | ||||||||||||
| 1223 | - | |||||||||||||
| 1224 | if (style == QFont::StyleItalic) | - | ||||||||||||
| 1225 | result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Italic"); | - | ||||||||||||
| 1226 | else if (style == QFont::StyleOblique) | - | ||||||||||||
| 1227 | result += QLatin1Char(' ') + QCoreApplication::translate("QFontDatabase", "Oblique"); | - | ||||||||||||
| 1228 | - | |||||||||||||
| 1229 | if (result.isEmpty()) | - | ||||||||||||
| 1230 | result = QCoreApplication::translate("QFontDatabase", "Normal", "The Normal or Regular font weight"); | - | ||||||||||||
| 1231 | - | |||||||||||||
| 1232 | return result.simplified(); | - | ||||||||||||
| 1233 | } | - | ||||||||||||
| 1234 | - | |||||||||||||
| 1235 | - | |||||||||||||
| 1236 | - | |||||||||||||
| 1237 | - | |||||||||||||
| 1238 | - | |||||||||||||
| 1239 | - | |||||||||||||
| 1240 | QString QFontDatabase::styleString(const QFont &font) | - | ||||||||||||
| 1241 | { | - | ||||||||||||
| 1242 | return font.styleName().isEmpty() ? styleStringHelper(font.weight(), font.style()) | - | ||||||||||||
| 1243 | : font.styleName(); | - | ||||||||||||
| 1244 | } | - | ||||||||||||
| 1245 | - | |||||||||||||
| 1246 | - | |||||||||||||
| 1247 | - | |||||||||||||
| 1248 | - | |||||||||||||
| 1249 | - | |||||||||||||
| 1250 | - | |||||||||||||
| 1251 | QString QFontDatabase::styleString(const QFontInfo &fontInfo) | - | ||||||||||||
| 1252 | { | - | ||||||||||||
| 1253 | return fontInfo.styleName().isEmpty() ? styleStringHelper(fontInfo.weight(), fontInfo.style()) | - | ||||||||||||
| 1254 | : fontInfo.styleName(); | - | ||||||||||||
| 1255 | } | - | ||||||||||||
| 1256 | QFontDatabase::QFontDatabase() | - | ||||||||||||
| 1257 | { | - | ||||||||||||
| 1258 | if (!((__builtin_expect(!!(!(
| 0 | ||||||||||||
| 1259 | QMessageLogger(__FILE__, 14111413, __PRETTY_FUNCTION__).fatal("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 | ||||||||||||
| 1260 | - | |||||||||||||
| 1261 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1262 | createDatabase(); | - | ||||||||||||
| 1263 | d = privateDb(); | - | ||||||||||||
| 1264 | } never executed: end of block | 0 | ||||||||||||
| 1265 | QList<QFontDatabase::WritingSystem> QFontDatabase::writingSystems() const | - | ||||||||||||
| 1266 | { | - | ||||||||||||
| 1267 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1268 | - | |||||||||||||
| 1269 | ::load(); | - | ||||||||||||
| 1270 | - | |||||||||||||
| 1271 | quint64 writingSystemsFound = 0; | - | ||||||||||||
| 1272 | static_assert(bool(WritingSystemsCount < 64), "WritingSystemsCount < 64"); | - | ||||||||||||
| 1273 | - | |||||||||||||
| 1274 | for (int i = 0; i < d->count; ++i) { | - | ||||||||||||
| 1275 | QtFontFamily *family = d->families[i]; | - | ||||||||||||
| 1276 | family->ensurePopulated(); | - | ||||||||||||
| 1277 | - | |||||||||||||
| 1278 | if (family->count == 0) | - | ||||||||||||
| 1279 | continue; | - | ||||||||||||
| 1280 | for (uint x = Latin; x < uint(WritingSystemsCount); ++x) { | - | ||||||||||||
| 1281 | if (family->writingSystems[x] & QtFontFamily::Supported) | - | ||||||||||||
| 1282 | writingSystemsFound |= quint64(1) << x; | - | ||||||||||||
| 1283 | } | - | ||||||||||||
| 1284 | } | - | ||||||||||||
| 1285 | - | |||||||||||||
| 1286 | - | |||||||||||||
| 1287 | locker.unlock(); | - | ||||||||||||
| 1288 | - | |||||||||||||
| 1289 | QList<WritingSystem> list; | - | ||||||||||||
| 1290 | list.reserve(qPopulationCount(writingSystemsFound)); | - | ||||||||||||
| 1291 | for (uint x = Latin ; x < uint(WritingSystemsCount); ++x) { | - | ||||||||||||
| 1292 | if (writingSystemsFound & (quint64(1) << x)) | - | ||||||||||||
| 1293 | list.push_back(WritingSystem(x)); | - | ||||||||||||
| 1294 | } | - | ||||||||||||
| 1295 | return list; | - | ||||||||||||
| 1296 | } | - | ||||||||||||
| 1297 | QList<QFontDatabase::WritingSystem> QFontDatabase::writingSystems(const QString &family) const | - | ||||||||||||
| 1298 | { | - | ||||||||||||
| 1299 | QString familyName, foundryName; | - | ||||||||||||
| 1300 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1301 | - | |||||||||||||
| 1302 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1303 | - | |||||||||||||
| 1304 | ::load(); | - | ||||||||||||
| 1305 | - | |||||||||||||
| 1306 | QList<WritingSystem> list; | - | ||||||||||||
| 1307 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1308 | if (!f || f->count == 0) | - | ||||||||||||
| 1309 | return list; | - | ||||||||||||
| 1310 | - | |||||||||||||
| 1311 | for (int x = Latin; x < WritingSystemsCount; ++x) { | - | ||||||||||||
| 1312 | const WritingSystem writingSystem = WritingSystem(x); | - | ||||||||||||
| 1313 | if (f->writingSystems[writingSystem] & QtFontFamily::Supported) | - | ||||||||||||
| 1314 | list.append(writingSystem); | - | ||||||||||||
| 1315 | } | - | ||||||||||||
| 1316 | return list; | - | ||||||||||||
| 1317 | } | - | ||||||||||||
| 1318 | QStringList QFontDatabase::families(WritingSystem writingSystem) const | - | ||||||||||||
| 1319 | { | - | ||||||||||||
| 1320 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1321 | - | |||||||||||||
| 1322 | ::load(); | - | ||||||||||||
| 1323 | - | |||||||||||||
| 1324 | QStringList flist; | - | ||||||||||||
| 1325 | for (int i = 0; i < d->count; i++) { | - | ||||||||||||
| 1326 | QtFontFamily *f = d->families[i]; | - | ||||||||||||
| 1327 | if (f->populated && f->count == 0) | - | ||||||||||||
| 1328 | continue; | - | ||||||||||||
| 1329 | if (writingSystem != Any) { | - | ||||||||||||
| 1330 | f->ensurePopulated(); | - | ||||||||||||
| 1331 | if (f->writingSystems[writingSystem] != QtFontFamily::Supported) | - | ||||||||||||
| 1332 | continue; | - | ||||||||||||
| 1333 | } | - | ||||||||||||
| 1334 | if (!f->populated || f->count == 1) { | - | ||||||||||||
| 1335 | flist.append(f->name); | - | ||||||||||||
| 1336 | } else { | - | ||||||||||||
| 1337 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1338 | QString str = f->name; | - | ||||||||||||
| 1339 | QString foundry = f->foundries[j]->name; | - | ||||||||||||
| 1340 | if (!foundry.isEmpty()) { | - | ||||||||||||
| 1341 | str += QLatin1String(" ["); | - | ||||||||||||
| 1342 | str += foundry; | - | ||||||||||||
| 1343 | str += QLatin1Char(']'); | - | ||||||||||||
| 1344 | } | - | ||||||||||||
| 1345 | flist.append(str); | - | ||||||||||||
| 1346 | } | - | ||||||||||||
| 1347 | } | - | ||||||||||||
| 1348 | } | - | ||||||||||||
| 1349 | return flist; | - | ||||||||||||
| 1350 | } | - | ||||||||||||
| 1351 | QStringList QFontDatabase::styles(const QString &family) const | - | ||||||||||||
| 1352 | { | - | ||||||||||||
| 1353 | QString familyName, foundryName; | - | ||||||||||||
| 1354 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1355 | - | |||||||||||||
| 1356 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1357 | - | |||||||||||||
| 1358 | ::load(familyName); | - | ||||||||||||
| 1359 | - | |||||||||||||
| 1360 | QStringList l; | - | ||||||||||||
| 1361 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1362 | if (!f) | - | ||||||||||||
| 1363 | return l; | - | ||||||||||||
| 1364 | - | |||||||||||||
| 1365 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
| 1366 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1367 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1368 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1369 | for (int k = 0; k < foundry->count; k++) { | - | ||||||||||||
| 1370 | QtFontStyle::Key ke(foundry->styles[k]->key); | - | ||||||||||||
| 1371 | ke.stretch = 0; | - | ||||||||||||
| 1372 | allStyles.style(ke, foundry->styles[k]->styleName, true); | - | ||||||||||||
| 1373 | } | - | ||||||||||||
| 1374 | } | - | ||||||||||||
| 1375 | } | - | ||||||||||||
| 1376 | - | |||||||||||||
| 1377 | l.reserve(allStyles.count); | - | ||||||||||||
| 1378 | for (int i = 0; i < allStyles.count; i++) { | - | ||||||||||||
| 1379 | l.append(allStyles.styles[i]->styleName.isEmpty() ? | - | ||||||||||||
| 1380 | styleStringHelper(allStyles.styles[i]->key.weight, | - | ||||||||||||
| 1381 | (QFont::Style)allStyles.styles[i]->key.style) : | - | ||||||||||||
| 1382 | allStyles.styles[i]->styleName); | - | ||||||||||||
| 1383 | } | - | ||||||||||||
| 1384 | return l; | - | ||||||||||||
| 1385 | } | - | ||||||||||||
| 1386 | - | |||||||||||||
| 1387 | - | |||||||||||||
| 1388 | - | |||||||||||||
| 1389 | - | |||||||||||||
| 1390 | - | |||||||||||||
| 1391 | - | |||||||||||||
| 1392 | bool QFontDatabase::isFixedPitch(const QString &family, | - | ||||||||||||
| 1393 | const QString &style) const | - | ||||||||||||
| 1394 | { | - | ||||||||||||
| 1395 | (void)style;; | - | ||||||||||||
| 1396 | - | |||||||||||||
| 1397 | QString familyName, foundryName; | - | ||||||||||||
| 1398 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1399 | - | |||||||||||||
| 1400 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1401 | - | |||||||||||||
| 1402 | ::load(familyName); | - | ||||||||||||
| 1403 | - | |||||||||||||
| 1404 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1405 | return (f && f->fixedPitch); | - | ||||||||||||
| 1406 | } | - | ||||||||||||
| 1407 | bool QFontDatabase::isBitmapScalable(const QString &family, | - | ||||||||||||
| 1408 | const QString &style) const | - | ||||||||||||
| 1409 | { | - | ||||||||||||
| 1410 | bool bitmapScalable = false; | - | ||||||||||||
| 1411 | QString familyName, foundryName; | - | ||||||||||||
| 1412 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1413 | - | |||||||||||||
| 1414 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1415 | - | |||||||||||||
| 1416 | ::load(familyName); | - | ||||||||||||
| 1417 | - | |||||||||||||
| 1418 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1419 | if (!f) return bitmapScalable; | - | ||||||||||||
| 1420 | - | |||||||||||||
| 1421 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
| 1422 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1423 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1424 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1425 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
| 1426 | if ((style.isEmpty() || | - | ||||||||||||
| 1427 | foundry->styles[k]->styleName == style || | - | ||||||||||||
| 1428 | foundry->styles[k]->key == styleKey) | - | ||||||||||||
| 1429 | && foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) { | - | ||||||||||||
| 1430 | bitmapScalable = true; | - | ||||||||||||
| 1431 | goto end; | - | ||||||||||||
| 1432 | } | - | ||||||||||||
| 1433 | } | - | ||||||||||||
| 1434 | } | - | ||||||||||||
| 1435 | end: | - | ||||||||||||
| 1436 | return bitmapScalable; | - | ||||||||||||
| 1437 | } | - | ||||||||||||
| 1438 | bool QFontDatabase::isSmoothlyScalable(const QString &family, const QString &style) const | - | ||||||||||||
| 1439 | { | - | ||||||||||||
| 1440 | bool smoothScalable = false; | - | ||||||||||||
| 1441 | QString familyName, foundryName; | - | ||||||||||||
| 1442 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1443 | - | |||||||||||||
| 1444 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1445 | - | |||||||||||||
| 1446 | ::load(familyName); | - | ||||||||||||
| 1447 | - | |||||||||||||
| 1448 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1449 | if (!f) { | - | ||||||||||||
| 1450 | for (int i = 0; i < d->count; i++) { | - | ||||||||||||
| 1451 | if (d->families[i]->matchesFamilyName(familyName)) { | - | ||||||||||||
| 1452 | f = d->families[i]; | - | ||||||||||||
| 1453 | f->ensurePopulated(); | - | ||||||||||||
| 1454 | break; | - | ||||||||||||
| 1455 | } | - | ||||||||||||
| 1456 | } | - | ||||||||||||
| 1457 | } | - | ||||||||||||
| 1458 | if (!f) return smoothScalable; | - | ||||||||||||
| 1459 | - | |||||||||||||
| 1460 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
| 1461 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1462 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1463 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1464 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
| 1465 | if ((style.isEmpty() || | - | ||||||||||||
| 1466 | foundry->styles[k]->styleName == style || | - | ||||||||||||
| 1467 | foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) { | - | ||||||||||||
| 1468 | smoothScalable = true; | - | ||||||||||||
| 1469 | goto end; | - | ||||||||||||
| 1470 | } | - | ||||||||||||
| 1471 | } | - | ||||||||||||
| 1472 | } | - | ||||||||||||
| 1473 | end: | - | ||||||||||||
| 1474 | return smoothScalable; | - | ||||||||||||
| 1475 | } | - | ||||||||||||
| 1476 | - | |||||||||||||
| 1477 | - | |||||||||||||
| 1478 | - | |||||||||||||
| 1479 | - | |||||||||||||
| 1480 | - | |||||||||||||
| 1481 | - | |||||||||||||
| 1482 | - | |||||||||||||
| 1483 | bool QFontDatabase::isScalable(const QString &family, | - | ||||||||||||
| 1484 | const QString &style) const | - | ||||||||||||
| 1485 | { | - | ||||||||||||
| 1486 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1487 | if (isSmoothlyScalable(family, style)) | - | ||||||||||||
| 1488 | return true; | - | ||||||||||||
| 1489 | return isBitmapScalable(family, style); | - | ||||||||||||
| 1490 | } | - | ||||||||||||
| 1491 | QList<int> QFontDatabase::pointSizes(const QString &family, | - | ||||||||||||
| 1492 | const QString &styleName) | - | ||||||||||||
| 1493 | { | - | ||||||||||||
| 1494 | if (QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()) | - | ||||||||||||
| 1495 | return standardSizes(); | - | ||||||||||||
| 1496 | - | |||||||||||||
| 1497 | bool smoothScalable = false; | - | ||||||||||||
| 1498 | QString familyName, foundryName; | - | ||||||||||||
| 1499 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1500 | - | |||||||||||||
| 1501 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1502 | - | |||||||||||||
| 1503 | ::load(familyName); | - | ||||||||||||
| 1504 | - | |||||||||||||
| 1505 | QList<int> sizes; | - | ||||||||||||
| 1506 | - | |||||||||||||
| 1507 | QtFontFamily *fam = d->family(familyName); | - | ||||||||||||
| 1508 | if (!fam) return sizes; | - | ||||||||||||
| 1509 | - | |||||||||||||
| 1510 | - | |||||||||||||
| 1511 | const int dpi = qt_defaultDpiY(); | - | ||||||||||||
| 1512 | - | |||||||||||||
| 1513 | QtFontStyle::Key styleKey(styleName); | - | ||||||||||||
| 1514 | for (int j = 0; j < fam->count; j++) { | - | ||||||||||||
| 1515 | QtFontFoundry *foundry = fam->foundries[j]; | - | ||||||||||||
| 1516 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1517 | QtFontStyle *style = foundry->style(styleKey, styleName); | - | ||||||||||||
| 1518 | if (!style) continue; | - | ||||||||||||
| 1519 | - | |||||||||||||
| 1520 | if (style->smoothScalable) { | - | ||||||||||||
| 1521 | smoothScalable = true; | - | ||||||||||||
| 1522 | goto end; | - | ||||||||||||
| 1523 | } | - | ||||||||||||
| 1524 | for (int l = 0; l < style->count; l++) { | - | ||||||||||||
| 1525 | const QtFontSize *size = style->pixelSizes + l; | - | ||||||||||||
| 1526 | - | |||||||||||||
| 1527 | if (size->pixelSize != 0 && size->pixelSize != 0xffff) { | - | ||||||||||||
| 1528 | const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); | - | ||||||||||||
| 1529 | if (! sizes.contains(pointSize)) | - | ||||||||||||
| 1530 | sizes.append(pointSize); | - | ||||||||||||
| 1531 | } | - | ||||||||||||
| 1532 | } | - | ||||||||||||
| 1533 | } | - | ||||||||||||
| 1534 | } | - | ||||||||||||
| 1535 | end: | - | ||||||||||||
| 1536 | if (smoothScalable) | - | ||||||||||||
| 1537 | return standardSizes(); | - | ||||||||||||
| 1538 | - | |||||||||||||
| 1539 | std::sort(sizes.begin(), sizes.end()); | - | ||||||||||||
| 1540 | return sizes; | - | ||||||||||||
| 1541 | } | - | ||||||||||||
| 1542 | - | |||||||||||||
| 1543 | - | |||||||||||||
| 1544 | - | |||||||||||||
| 1545 | - | |||||||||||||
| 1546 | - | |||||||||||||
| 1547 | - | |||||||||||||
| 1548 | - | |||||||||||||
| 1549 | QFont QFontDatabase::font(const QString &family, const QString &style, | - | ||||||||||||
| 1550 | int pointSize) const | - | ||||||||||||
| 1551 | { | - | ||||||||||||
| 1552 | QString familyName, foundryName; | - | ||||||||||||
| 1553 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1554 | - | |||||||||||||
| 1555 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1556 | - | |||||||||||||
| 1557 | ::load(familyName); | - | ||||||||||||
| 1558 | - | |||||||||||||
| 1559 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
| 1560 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1561 | if (!f) return QGuiApplication::font(); | - | ||||||||||||
| 1562 | - | |||||||||||||
| 1563 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1564 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1565 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1566 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
| 1567 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
| 1568 | } | - | ||||||||||||
| 1569 | } | - | ||||||||||||
| 1570 | - | |||||||||||||
| 1571 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
| 1572 | QtFontStyle *s = bestStyle(&allStyles, styleKey, style); | - | ||||||||||||
| 1573 | - | |||||||||||||
| 1574 | if (!s) | - | ||||||||||||
| 1575 | return QGuiApplication::font(); | - | ||||||||||||
| 1576 | - | |||||||||||||
| 1577 | QFont fnt(family, pointSize, s->key.weight); | - | ||||||||||||
| 1578 | fnt.setStyle((QFont::Style)s->key.style); | - | ||||||||||||
| 1579 | if (!s->styleName.isEmpty()) | - | ||||||||||||
| 1580 | fnt.setStyleName(s->styleName); | - | ||||||||||||
| 1581 | return fnt; | - | ||||||||||||
| 1582 | } | - | ||||||||||||
| 1583 | QList<int> QFontDatabase::smoothSizes(const QString &family, | - | ||||||||||||
| 1584 | const QString &styleName) | - | ||||||||||||
| 1585 | { | - | ||||||||||||
| 1586 | if (QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable()) | - | ||||||||||||
| 1587 | return standardSizes(); | - | ||||||||||||
| 1588 | - | |||||||||||||
| 1589 | bool smoothScalable = false; | - | ||||||||||||
| 1590 | QString familyName, foundryName; | - | ||||||||||||
| 1591 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1592 | - | |||||||||||||
| 1593 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1594 | - | |||||||||||||
| 1595 | ::load(familyName); | - | ||||||||||||
| 1596 | - | |||||||||||||
| 1597 | QList<int> sizes; | - | ||||||||||||
| 1598 | - | |||||||||||||
| 1599 | QtFontFamily *fam = d->family(familyName); | - | ||||||||||||
| 1600 | if (!fam) | - | ||||||||||||
| 1601 | return sizes; | - | ||||||||||||
| 1602 | - | |||||||||||||
| 1603 | const int dpi = qt_defaultDpiY(); | - | ||||||||||||
| 1604 | - | |||||||||||||
| 1605 | QtFontStyle::Key styleKey(styleName); | - | ||||||||||||
| 1606 | for (int j = 0; j < fam->count; j++) { | - | ||||||||||||
| 1607 | QtFontFoundry *foundry = fam->foundries[j]; | - | ||||||||||||
| 1608 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1609 | QtFontStyle *style = foundry->style(styleKey, styleName); | - | ||||||||||||
| 1610 | if (!style) continue; | - | ||||||||||||
| 1611 | - | |||||||||||||
| 1612 | if (style->smoothScalable) { | - | ||||||||||||
| 1613 | smoothScalable = true; | - | ||||||||||||
| 1614 | goto end; | - | ||||||||||||
| 1615 | } | - | ||||||||||||
| 1616 | for (int l = 0; l < style->count; l++) { | - | ||||||||||||
| 1617 | const QtFontSize *size = style->pixelSizes + l; | - | ||||||||||||
| 1618 | - | |||||||||||||
| 1619 | if (size->pixelSize != 0 && size->pixelSize != 0xffff) { | - | ||||||||||||
| 1620 | const uint pointSize = qRound(size->pixelSize * 72.0 / dpi); | - | ||||||||||||
| 1621 | if (! sizes.contains(pointSize)) | - | ||||||||||||
| 1622 | sizes.append(pointSize); | - | ||||||||||||
| 1623 | } | - | ||||||||||||
| 1624 | } | - | ||||||||||||
| 1625 | } | - | ||||||||||||
| 1626 | } | - | ||||||||||||
| 1627 | end: | - | ||||||||||||
| 1628 | if (smoothScalable) | - | ||||||||||||
| 1629 | return QFontDatabase::standardSizes(); | - | ||||||||||||
| 1630 | - | |||||||||||||
| 1631 | std::sort(sizes.begin(), sizes.end()); | - | ||||||||||||
| 1632 | return sizes; | - | ||||||||||||
| 1633 | } | - | ||||||||||||
| 1634 | - | |||||||||||||
| 1635 | - | |||||||||||||
| 1636 | - | |||||||||||||
| 1637 | - | |||||||||||||
| 1638 | - | |||||||||||||
| 1639 | - | |||||||||||||
| 1640 | - | |||||||||||||
| 1641 | QList<int> QFontDatabase::standardSizes() | - | ||||||||||||
| 1642 | { | - | ||||||||||||
| 1643 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->standardSizes(); | - | ||||||||||||
| 1644 | } | - | ||||||||||||
| 1645 | bool QFontDatabase::italic(const QString &family, const QString &style) const | - | ||||||||||||
| 1646 | { | - | ||||||||||||
| 1647 | QString familyName, foundryName; | - | ||||||||||||
| 1648 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1649 | - | |||||||||||||
| 1650 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1651 | - | |||||||||||||
| 1652 | ::load(familyName); | - | ||||||||||||
| 1653 | - | |||||||||||||
| 1654 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
| 1655 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1656 | if (!f) return false; | - | ||||||||||||
| 1657 | - | |||||||||||||
| 1658 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1659 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1660 | if (foundryName.isEmpty() || foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1661 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
| 1662 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
| 1663 | } | - | ||||||||||||
| 1664 | } | - | ||||||||||||
| 1665 | - | |||||||||||||
| 1666 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
| 1667 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||
| 1668 | return s && s->key.style == QFont::StyleItalic; | - | ||||||||||||
| 1669 | } | - | ||||||||||||
| 1670 | bool QFontDatabase::bold(const QString &family, | - | ||||||||||||
| 1671 | const QString &style) const | - | ||||||||||||
| 1672 | { | - | ||||||||||||
| 1673 | QString familyName, foundryName; | - | ||||||||||||
| 1674 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1675 | - | |||||||||||||
| 1676 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1677 | - | |||||||||||||
| 1678 | ::load(familyName); | - | ||||||||||||
| 1679 | - | |||||||||||||
| 1680 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
| 1681 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1682 | if (!f) return false; | - | ||||||||||||
| 1683 | - | |||||||||||||
| 1684 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1685 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1686 | if (foundryName.isEmpty() || | - | ||||||||||||
| 1687 | foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1688 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
| 1689 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
| 1690 | } | - | ||||||||||||
| 1691 | } | - | ||||||||||||
| 1692 | - | |||||||||||||
| 1693 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
| 1694 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||
| 1695 | return s && s->key.weight >= QFont::Bold; | - | ||||||||||||
| 1696 | } | - | ||||||||||||
| 1697 | int QFontDatabase::weight(const QString &family, | - | ||||||||||||
| 1698 | const QString &style) const | - | ||||||||||||
| 1699 | { | - | ||||||||||||
| 1700 | QString familyName, foundryName; | - | ||||||||||||
| 1701 | parseFontName(family, foundryName, familyName); | - | ||||||||||||
| 1702 | - | |||||||||||||
| 1703 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 1704 | - | |||||||||||||
| 1705 | ::load(familyName); | - | ||||||||||||
| 1706 | - | |||||||||||||
| 1707 | QtFontFoundry allStyles(foundryName); | - | ||||||||||||
| 1708 | QtFontFamily *f = d->family(familyName); | - | ||||||||||||
| 1709 | if (!f) return -1; | - | ||||||||||||
| 1710 | - | |||||||||||||
| 1711 | for (int j = 0; j < f->count; j++) { | - | ||||||||||||
| 1712 | QtFontFoundry *foundry = f->foundries[j]; | - | ||||||||||||
| 1713 | if (foundryName.isEmpty() || | - | ||||||||||||
| 1714 | foundry->name.compare(foundryName, Qt::CaseInsensitive) == 0) { | - | ||||||||||||
| 1715 | for (int k = 0; k < foundry->count; k++) | - | ||||||||||||
| 1716 | allStyles.style(foundry->styles[k]->key, foundry->styles[k]->styleName, true); | - | ||||||||||||
| 1717 | } | - | ||||||||||||
| 1718 | } | - | ||||||||||||
| 1719 | - | |||||||||||||
| 1720 | QtFontStyle::Key styleKey(style); | - | ||||||||||||
| 1721 | QtFontStyle *s = allStyles.style(styleKey, style); | - | ||||||||||||
| 1722 | return s ? s->key.weight : -1; | - | ||||||||||||
| 1723 | } | - | ||||||||||||
| 1724 | - | |||||||||||||
| 1725 | - | |||||||||||||
| 1726 | - | |||||||||||||
| 1727 | bool QFontDatabase::hasFamily(const QString &family) const | - | ||||||||||||
| 1728 | { | - | ||||||||||||
| 1729 | QString parsedFamily, foundry; | - | ||||||||||||
| 1730 | parseFontName(family, foundry, parsedFamily); | - | ||||||||||||
| 1731 | const QString familyAlias = resolveFontFamilyAlias(parsedFamily); | - | ||||||||||||
| 1732 | return families().contains(familyAlias, Qt::CaseInsensitive); | - | ||||||||||||
| 1733 | } | - | ||||||||||||
| 1734 | bool QFontDatabase::isPrivateFamily(const QString &family) const | - | ||||||||||||
| 1735 | { | - | ||||||||||||
| 1736 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->isPrivateFontFamily(family); | - | ||||||||||||
| 1737 | } | - | ||||||||||||
| 1738 | - | |||||||||||||
| 1739 | - | |||||||||||||
| 1740 | - | |||||||||||||
| 1741 | - | |||||||||||||
| 1742 | - | |||||||||||||
| 1743 | - | |||||||||||||
| 1744 | QString QFontDatabase::writingSystemName(WritingSystem writingSystem) | - | ||||||||||||
| 1745 | { | - | ||||||||||||
| 1746 | const char *name = 0; | - | ||||||||||||
| 1747 | switch (writingSystem) { | - | ||||||||||||
| 1748 | case Any: | - | ||||||||||||
| 1749 | name = "Any"; | - | ||||||||||||
| 1750 | break; | - | ||||||||||||
| 1751 | case Latin: | - | ||||||||||||
| 1752 | name = "Latin"; | - | ||||||||||||
| 1753 | break; | - | ||||||||||||
| 1754 | case Greek: | - | ||||||||||||
| 1755 | name = "Greek"; | - | ||||||||||||
| 1756 | break; | - | ||||||||||||
| 1757 | case Cyrillic: | - | ||||||||||||
| 1758 | name = "Cyrillic"; | - | ||||||||||||
| 1759 | break; | - | ||||||||||||
| 1760 | case Armenian: | - | ||||||||||||
| 1761 | name = "Armenian"; | - | ||||||||||||
| 1762 | break; | - | ||||||||||||
| 1763 | case Hebrew: | - | ||||||||||||
| 1764 | name = "Hebrew"; | - | ||||||||||||
| 1765 | break; | - | ||||||||||||
| 1766 | case Arabic: | - | ||||||||||||
| 1767 | name = "Arabic"; | - | ||||||||||||
| 1768 | break; | - | ||||||||||||
| 1769 | case Syriac: | - | ||||||||||||
| 1770 | name = "Syriac"; | - | ||||||||||||
| 1771 | break; | - | ||||||||||||
| 1772 | case Thaana: | - | ||||||||||||
| 1773 | name = "Thaana"; | - | ||||||||||||
| 1774 | break; | - | ||||||||||||
| 1775 | case Devanagari: | - | ||||||||||||
| 1776 | name = "Devanagari"; | - | ||||||||||||
| 1777 | break; | - | ||||||||||||
| 1778 | case Bengali: | - | ||||||||||||
| 1779 | name = "Bengali"; | - | ||||||||||||
| 1780 | break; | - | ||||||||||||
| 1781 | case Gurmukhi: | - | ||||||||||||
| 1782 | name = "Gurmukhi"; | - | ||||||||||||
| 1783 | break; | - | ||||||||||||
| 1784 | case Gujarati: | - | ||||||||||||
| 1785 | name = "Gujarati"; | - | ||||||||||||
| 1786 | break; | - | ||||||||||||
| 1787 | case Oriya: | - | ||||||||||||
| 1788 | name = "Oriya"; | - | ||||||||||||
| 1789 | break; | - | ||||||||||||
| 1790 | case Tamil: | - | ||||||||||||
| 1791 | name = "Tamil"; | - | ||||||||||||
| 1792 | break; | - | ||||||||||||
| 1793 | case Telugu: | - | ||||||||||||
| 1794 | name = "Telugu"; | - | ||||||||||||
| 1795 | break; | - | ||||||||||||
| 1796 | case Kannada: | - | ||||||||||||
| 1797 | name = "Kannada"; | - | ||||||||||||
| 1798 | break; | - | ||||||||||||
| 1799 | case Malayalam: | - | ||||||||||||
| 1800 | name = "Malayalam"; | - | ||||||||||||
| 1801 | break; | - | ||||||||||||
| 1802 | case Sinhala: | - | ||||||||||||
| 1803 | name = "Sinhala"; | - | ||||||||||||
| 1804 | break; | - | ||||||||||||
| 1805 | case Thai: | - | ||||||||||||
| 1806 | name = "Thai"; | - | ||||||||||||
| 1807 | break; | - | ||||||||||||
| 1808 | case Lao: | - | ||||||||||||
| 1809 | name = "Lao"; | - | ||||||||||||
| 1810 | break; | - | ||||||||||||
| 1811 | case Tibetan: | - | ||||||||||||
| 1812 | name = "Tibetan"; | - | ||||||||||||
| 1813 | break; | - | ||||||||||||
| 1814 | case Myanmar: | - | ||||||||||||
| 1815 | name = "Myanmar"; | - | ||||||||||||
| 1816 | break; | - | ||||||||||||
| 1817 | case Georgian: | - | ||||||||||||
| 1818 | name = "Georgian"; | - | ||||||||||||
| 1819 | break; | - | ||||||||||||
| 1820 | case Khmer: | - | ||||||||||||
| 1821 | name = "Khmer"; | - | ||||||||||||
| 1822 | break; | - | ||||||||||||
| 1823 | case SimplifiedChinese: | - | ||||||||||||
| 1824 | name = "Simplified Chinese"; | - | ||||||||||||
| 1825 | break; | - | ||||||||||||
| 1826 | case TraditionalChinese: | - | ||||||||||||
| 1827 | name = "Traditional Chinese"; | - | ||||||||||||
| 1828 | break; | - | ||||||||||||
| 1829 | case Japanese: | - | ||||||||||||
| 1830 | name = "Japanese"; | - | ||||||||||||
| 1831 | break; | - | ||||||||||||
| 1832 | case Korean: | - | ||||||||||||
| 1833 | name = "Korean"; | - | ||||||||||||
| 1834 | break; | - | ||||||||||||
| 1835 | case Vietnamese: | - | ||||||||||||
| 1836 | name = "Vietnamese"; | - | ||||||||||||
| 1837 | break; | - | ||||||||||||
| 1838 | case Symbol: | - | ||||||||||||
| 1839 | name = "Symbol"; | - | ||||||||||||
| 1840 | break; | - | ||||||||||||
| 1841 | case Ogham: | - | ||||||||||||
| 1842 | name = "Ogham"; | - | ||||||||||||
| 1843 | break; | - | ||||||||||||
| 1844 | case Runic: | - | ||||||||||||
| 1845 | name = "Runic"; | - | ||||||||||||
| 1846 | break; | - | ||||||||||||
| 1847 | case Nko: | - | ||||||||||||
| 1848 | name = "N'Ko"; | - | ||||||||||||
| 1849 | break; | - | ||||||||||||
| 1850 | default: | - | ||||||||||||
| 1851 | ((!(false)) ? qt_assert_x("QFontDatabase::writingSystemName", "invalid 'writingSystem' parameter",__FILE__,21702172) : qt_noop()); | - | ||||||||||||
| 1852 | break; | - | ||||||||||||
| 1853 | } | - | ||||||||||||
| 1854 | return QCoreApplication::translate("QFontDatabase", name); | - | ||||||||||||
| 1855 | } | - | ||||||||||||
| 1856 | - | |||||||||||||
| 1857 | - | |||||||||||||
| 1858 | - | |||||||||||||
| 1859 | - | |||||||||||||
| 1860 | - | |||||||||||||
| 1861 | QString QFontDatabase::writingSystemSample(WritingSystem writingSystem) | - | ||||||||||||
| 1862 | { | - | ||||||||||||
| 1863 | QString sample; | - | ||||||||||||
| 1864 | switch (writingSystem) { | - | ||||||||||||
| 1865 | case Any: | - | ||||||||||||
| 1866 | case Symbol: | - | ||||||||||||
| 1867 | - | |||||||||||||
| 1868 | sample += QLatin1String("AaBbzZ"); | - | ||||||||||||
| 1869 | break; | - | ||||||||||||
| 1870 | case Latin: | - | ||||||||||||
| 1871 | - | |||||||||||||
| 1872 | - | |||||||||||||
| 1873 | sample = QLatin1String("Aa"); | - | ||||||||||||
| 1874 | sample += QChar(0x00C3); | - | ||||||||||||
| 1875 | sample += QChar(0x00E1); | - | ||||||||||||
| 1876 | sample += QLatin1String("Zz"); | - | ||||||||||||
| 1877 | break; | - | ||||||||||||
| 1878 | case Greek: | - | ||||||||||||
| 1879 | sample += QChar(0x0393); | - | ||||||||||||
| 1880 | sample += QChar(0x03B1); | - | ||||||||||||
| 1881 | sample += QChar(0x03A9); | - | ||||||||||||
| 1882 | sample += QChar(0x03C9); | - | ||||||||||||
| 1883 | break; | - | ||||||||||||
| 1884 | case Cyrillic: | - | ||||||||||||
| 1885 | sample += QChar(0x0414); | - | ||||||||||||
| 1886 | sample += QChar(0x0434); | - | ||||||||||||
| 1887 | sample += QChar(0x0436); | - | ||||||||||||
| 1888 | sample += QChar(0x044f); | - | ||||||||||||
| 1889 | break; | - | ||||||||||||
| 1890 | case Armenian: | - | ||||||||||||
| 1891 | sample += QChar(0x053f); | - | ||||||||||||
| 1892 | sample += QChar(0x054f); | - | ||||||||||||
| 1893 | sample += QChar(0x056f); | - | ||||||||||||
| 1894 | sample += QChar(0x057f); | - | ||||||||||||
| 1895 | break; | - | ||||||||||||
| 1896 | case Hebrew: | - | ||||||||||||
| 1897 | sample += QChar(0x05D0); | - | ||||||||||||
| 1898 | sample += QChar(0x05D1); | - | ||||||||||||
| 1899 | sample += QChar(0x05D2); | - | ||||||||||||
| 1900 | sample += QChar(0x05D3); | - | ||||||||||||
| 1901 | break; | - | ||||||||||||
| 1902 | case Arabic: | - | ||||||||||||
| 1903 | sample += QChar(0x0628); | - | ||||||||||||
| 1904 | sample += QChar(0x0629); | - | ||||||||||||
| 1905 | sample += QChar(0x062A); | - | ||||||||||||
| 1906 | sample += QChar(0x063A); | - | ||||||||||||
| 1907 | break; | - | ||||||||||||
| 1908 | case Syriac: | - | ||||||||||||
| 1909 | sample += QChar(0x0715); | - | ||||||||||||
| 1910 | sample += QChar(0x0725); | - | ||||||||||||
| 1911 | sample += QChar(0x0716); | - | ||||||||||||
| 1912 | sample += QChar(0x0726); | - | ||||||||||||
| 1913 | break; | - | ||||||||||||
| 1914 | case Thaana: | - | ||||||||||||
| 1915 | sample += QChar(0x0784); | - | ||||||||||||
| 1916 | sample += QChar(0x0794); | - | ||||||||||||
| 1917 | sample += QChar(0x078c); | - | ||||||||||||
| 1918 | sample += QChar(0x078d); | - | ||||||||||||
| 1919 | break; | - | ||||||||||||
| 1920 | case Devanagari: | - | ||||||||||||
| 1921 | sample += QChar(0x0905); | - | ||||||||||||
| 1922 | sample += QChar(0x0915); | - | ||||||||||||
| 1923 | sample += QChar(0x0925); | - | ||||||||||||
| 1924 | sample += QChar(0x0935); | - | ||||||||||||
| 1925 | break; | - | ||||||||||||
| 1926 | case Bengali: | - | ||||||||||||
| 1927 | sample += QChar(0x0986); | - | ||||||||||||
| 1928 | sample += QChar(0x0996); | - | ||||||||||||
| 1929 | sample += QChar(0x09a6); | - | ||||||||||||
| 1930 | sample += QChar(0x09b6); | - | ||||||||||||
| 1931 | break; | - | ||||||||||||
| 1932 | case Gurmukhi: | - | ||||||||||||
| 1933 | sample += QChar(0x0a05); | - | ||||||||||||
| 1934 | sample += QChar(0x0a15); | - | ||||||||||||
| 1935 | sample += QChar(0x0a25); | - | ||||||||||||
| 1936 | sample += QChar(0x0a35); | - | ||||||||||||
| 1937 | break; | - | ||||||||||||
| 1938 | case Gujarati: | - | ||||||||||||
| 1939 | sample += QChar(0x0a85); | - | ||||||||||||
| 1940 | sample += QChar(0x0a95); | - | ||||||||||||
| 1941 | sample += QChar(0x0aa5); | - | ||||||||||||
| 1942 | sample += QChar(0x0ab5); | - | ||||||||||||
| 1943 | break; | - | ||||||||||||
| 1944 | case Oriya: | - | ||||||||||||
| 1945 | sample += QChar(0x0b06); | - | ||||||||||||
| 1946 | sample += QChar(0x0b16); | - | ||||||||||||
| 1947 | sample += QChar(0x0b2b); | - | ||||||||||||
| 1948 | sample += QChar(0x0b36); | - | ||||||||||||
| 1949 | break; | - | ||||||||||||
| 1950 | case Tamil: | - | ||||||||||||
| 1951 | sample += QChar(0x0b89); | - | ||||||||||||
| 1952 | sample += QChar(0x0b99); | - | ||||||||||||
| 1953 | sample += QChar(0x0ba9); | - | ||||||||||||
| 1954 | sample += QChar(0x0bb9); | - | ||||||||||||
| 1955 | break; | - | ||||||||||||
| 1956 | case Telugu: | - | ||||||||||||
| 1957 | sample += QChar(0x0c05); | - | ||||||||||||
| 1958 | sample += QChar(0x0c15); | - | ||||||||||||
| 1959 | sample += QChar(0x0c25); | - | ||||||||||||
| 1960 | sample += QChar(0x0c35); | - | ||||||||||||
| 1961 | break; | - | ||||||||||||
| 1962 | case Kannada: | - | ||||||||||||
| 1963 | sample += QChar(0x0c85); | - | ||||||||||||
| 1964 | sample += QChar(0x0c95); | - | ||||||||||||
| 1965 | sample += QChar(0x0ca5); | - | ||||||||||||
| 1966 | sample += QChar(0x0cb5); | - | ||||||||||||
| 1967 | break; | - | ||||||||||||
| 1968 | case Malayalam: | - | ||||||||||||
| 1969 | sample += QChar(0x0d05); | - | ||||||||||||
| 1970 | sample += QChar(0x0d15); | - | ||||||||||||
| 1971 | sample += QChar(0x0d25); | - | ||||||||||||
| 1972 | sample += QChar(0x0d35); | - | ||||||||||||
| 1973 | break; | - | ||||||||||||
| 1974 | case Sinhala: | - | ||||||||||||
| 1975 | sample += QChar(0x0d90); | - | ||||||||||||
| 1976 | sample += QChar(0x0da0); | - | ||||||||||||
| 1977 | sample += QChar(0x0db0); | - | ||||||||||||
| 1978 | sample += QChar(0x0dc0); | - | ||||||||||||
| 1979 | break; | - | ||||||||||||
| 1980 | case Thai: | - | ||||||||||||
| 1981 | sample += QChar(0x0e02); | - | ||||||||||||
| 1982 | sample += QChar(0x0e12); | - | ||||||||||||
| 1983 | sample += QChar(0x0e22); | - | ||||||||||||
| 1984 | sample += QChar(0x0e32); | - | ||||||||||||
| 1985 | break; | - | ||||||||||||
| 1986 | case Lao: | - | ||||||||||||
| 1987 | sample += QChar(0x0e8d); | - | ||||||||||||
| 1988 | sample += QChar(0x0e9d); | - | ||||||||||||
| 1989 | sample += QChar(0x0ead); | - | ||||||||||||
| 1990 | sample += QChar(0x0ebd); | - | ||||||||||||
| 1991 | break; | - | ||||||||||||
| 1992 | case Tibetan: | - | ||||||||||||
| 1993 | sample += QChar(0x0f00); | - | ||||||||||||
| 1994 | sample += QChar(0x0f01); | - | ||||||||||||
| 1995 | sample += QChar(0x0f02); | - | ||||||||||||
| 1996 | sample += QChar(0x0f03); | - | ||||||||||||
| 1997 | break; | - | ||||||||||||
| 1998 | case Myanmar: | - | ||||||||||||
| 1999 | sample += QChar(0x1000); | - | ||||||||||||
| 2000 | sample += QChar(0x1001); | - | ||||||||||||
| 2001 | sample += QChar(0x1002); | - | ||||||||||||
| 2002 | sample += QChar(0x1003); | - | ||||||||||||
| 2003 | break; | - | ||||||||||||
| 2004 | case Georgian: | - | ||||||||||||
| 2005 | sample += QChar(0x10a0); | - | ||||||||||||
| 2006 | sample += QChar(0x10b0); | - | ||||||||||||
| 2007 | sample += QChar(0x10c0); | - | ||||||||||||
| 2008 | sample += QChar(0x10d0); | - | ||||||||||||
| 2009 | break; | - | ||||||||||||
| 2010 | case Khmer: | - | ||||||||||||
| 2011 | sample += QChar(0x1780); | - | ||||||||||||
| 2012 | sample += QChar(0x1790); | - | ||||||||||||
| 2013 | sample += QChar(0x17b0); | - | ||||||||||||
| 2014 | sample += QChar(0x17c0); | - | ||||||||||||
| 2015 | break; | - | ||||||||||||
| 2016 | case SimplifiedChinese: | - | ||||||||||||
| 2017 | sample += QChar(0x4e2d); | - | ||||||||||||
| 2018 | sample += QChar(0x6587); | - | ||||||||||||
| 2019 | sample += QChar(0x8303); | - | ||||||||||||
| 2020 | sample += QChar(0x4f8b); | - | ||||||||||||
| 2021 | break; | - | ||||||||||||
| 2022 | case TraditionalChinese: | - | ||||||||||||
| 2023 | sample += QChar(0x4e2d); | - | ||||||||||||
| 2024 | sample += QChar(0x6587); | - | ||||||||||||
| 2025 | sample += QChar(0x7bc4); | - | ||||||||||||
| 2026 | sample += QChar(0x4f8b); | - | ||||||||||||
| 2027 | break; | - | ||||||||||||
| 2028 | case Japanese: | - | ||||||||||||
| 2029 | sample += QChar(0x30b5); | - | ||||||||||||
| 2030 | sample += QChar(0x30f3); | - | ||||||||||||
| 2031 | sample += QChar(0x30d7); | - | ||||||||||||
| 2032 | sample += QChar(0x30eb); | - | ||||||||||||
| 2033 | sample += QChar(0x3067); | - | ||||||||||||
| 2034 | sample += QChar(0x3059); | - | ||||||||||||
| 2035 | break; | - | ||||||||||||
| 2036 | case Korean: | - | ||||||||||||
| 2037 | sample += QChar(0xac00); | - | ||||||||||||
| 2038 | sample += QChar(0xac11); | - | ||||||||||||
| 2039 | sample += QChar(0xac1a); | - | ||||||||||||
| 2040 | sample += QChar(0xac2f); | - | ||||||||||||
| 2041 | break; | - | ||||||||||||
| 2042 | case Vietnamese: | - | ||||||||||||
| 2043 | { | - | ||||||||||||
| 2044 | static const char vietnameseUtf8[] = { | - | ||||||||||||
| 2045 | char(0xef), char(0xbb), char(0xbf), char(0xe1), char(0xbb), char(0x97), | - | ||||||||||||
| 2046 | char(0xe1), char(0xbb), char(0x99), | - | ||||||||||||
| 2047 | char(0xe1), char(0xbb), char(0x91), | - | ||||||||||||
| 2048 | char(0xe1), char(0xbb), char(0x93), | - | ||||||||||||
| 2049 | }; | - | ||||||||||||
| 2050 | sample += QString::fromUtf8(vietnameseUtf8, sizeof(vietnameseUtf8)); | - | ||||||||||||
| 2051 | break; | - | ||||||||||||
| 2052 | } | - | ||||||||||||
| 2053 | case Ogham: | - | ||||||||||||
| 2054 | sample += QChar(0x1681); | - | ||||||||||||
| 2055 | sample += QChar(0x1682); | - | ||||||||||||
| 2056 | sample += QChar(0x1683); | - | ||||||||||||
| 2057 | sample += QChar(0x1684); | - | ||||||||||||
| 2058 | break; | - | ||||||||||||
| 2059 | case Runic: | - | ||||||||||||
| 2060 | sample += QChar(0x16a0); | - | ||||||||||||
| 2061 | sample += QChar(0x16a1); | - | ||||||||||||
| 2062 | sample += QChar(0x16a2); | - | ||||||||||||
| 2063 | sample += QChar(0x16a3); | - | ||||||||||||
| 2064 | break; | - | ||||||||||||
| 2065 | case Nko: | - | ||||||||||||
| 2066 | sample += QChar(0x7ca); | - | ||||||||||||
| 2067 | sample += QChar(0x7cb); | - | ||||||||||||
| 2068 | sample += QChar(0x7cc); | - | ||||||||||||
| 2069 | sample += QChar(0x7cd); | - | ||||||||||||
| 2070 | break; | - | ||||||||||||
| 2071 | default: | - | ||||||||||||
| 2072 | break; | - | ||||||||||||
| 2073 | } | - | ||||||||||||
| 2074 | return sample; | - | ||||||||||||
| 2075 | } | - | ||||||||||||
| 2076 | - | |||||||||||||
| 2077 | - | |||||||||||||
| 2078 | void QFontDatabase::parseFontName(const QString &name, QString &foundry, QString &family) | - | ||||||||||||
| 2079 | { | - | ||||||||||||
| 2080 | ::parseFontName(name, foundry, family); | - | ||||||||||||
| 2081 | } | - | ||||||||||||
| 2082 | - | |||||||||||||
| 2083 | void QFontDatabase::createDatabase() | - | ||||||||||||
| 2084 | { initializeDb(); } | - | ||||||||||||
| 2085 | - | |||||||||||||
| 2086 | - | |||||||||||||
| 2087 | __attribute__((visibility("default"))) QByteArray qt_fontdata_from_index(int index) | - | ||||||||||||
| 2088 | { | - | ||||||||||||
| 2089 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2090 | return privateDb()->applicationFonts.value(index).data; | - | ||||||||||||
| 2091 | } | - | ||||||||||||
| 2092 | - | |||||||||||||
| 2093 | int QFontDatabasePrivate::addAppFont(const QByteArray &fontData, const QString &fileName) | - | ||||||||||||
| 2094 | { | - | ||||||||||||
| 2095 | QFontDatabasePrivate::ApplicationFont font; | - | ||||||||||||
| 2096 | font.data = fontData; | - | ||||||||||||
| 2097 | font.fileName = fileName; | - | ||||||||||||
| 2098 | - | |||||||||||||
| 2099 | int i; | - | ||||||||||||
| 2100 | for (i = 0; i < applicationFonts.count(); ++i) | - | ||||||||||||
| 2101 | if (applicationFonts.at(i).families.isEmpty()) | - | ||||||||||||
| 2102 | break; | - | ||||||||||||
| 2103 | if (i >= applicationFonts.count()) { | - | ||||||||||||
| 2104 | applicationFonts.append(ApplicationFont()); | - | ||||||||||||
| 2105 | i = applicationFonts.count() - 1; | - | ||||||||||||
| 2106 | } | - | ||||||||||||
| 2107 | - | |||||||||||||
| 2108 | if (font.fileName.isEmpty() && !fontData.isEmpty()) | - | ||||||||||||
| 2109 | font.fileName = QString::fromLatin1(":qmemoryfonts/") + QString::number(i); | - | ||||||||||||
| 2110 | - | |||||||||||||
| 2111 | registerFont(&font); | - | ||||||||||||
| 2112 | if (font.families.isEmpty()) | - | ||||||||||||
| 2113 | return -1; | - | ||||||||||||
| 2114 | - | |||||||||||||
| 2115 | applicationFonts[i] = font; | - | ||||||||||||
| 2116 | - | |||||||||||||
| 2117 | invalidate(); | - | ||||||||||||
| 2118 | return i; | - | ||||||||||||
| 2119 | } | - | ||||||||||||
| 2120 | - | |||||||||||||
| 2121 | bool QFontDatabasePrivate::isApplicationFont(const QString &fileName) | - | ||||||||||||
| 2122 | { | - | ||||||||||||
| 2123 | for (int i = 0; i < applicationFonts.count(); ++i) | - | ||||||||||||
| 2124 | if (applicationFonts.at(i).fileName == fileName) | - | ||||||||||||
| 2125 | return true; | - | ||||||||||||
| 2126 | return false; | - | ||||||||||||
| 2127 | } | - | ||||||||||||
| 2128 | int QFontDatabase::addApplicationFont(const QString &fileName) | - | ||||||||||||
| 2129 | { | - | ||||||||||||
| 2130 | QByteArray data; | - | ||||||||||||
| 2131 | if (!QFileInfo(fileName).isNativePath()) { | - | ||||||||||||
| 2132 | QFile f(fileName); | - | ||||||||||||
| 2133 | if (!f.open(QIODevice::ReadOnly)) | - | ||||||||||||
| 2134 | return -1; | - | ||||||||||||
| 2135 | data = f.readAll(); | - | ||||||||||||
| 2136 | } | - | ||||||||||||
| 2137 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2138 | return privateDb()->addAppFont(data, fileName); | - | ||||||||||||
| 2139 | } | - | ||||||||||||
| 2140 | int QFontDatabase::addApplicationFontFromData(const QByteArray &fontData) | - | ||||||||||||
| 2141 | { | - | ||||||||||||
| 2142 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2143 | return privateDb()->addAppFont(fontData, QString() ); | - | ||||||||||||
| 2144 | } | - | ||||||||||||
| 2145 | QStringList QFontDatabase::applicationFontFamilies(int id) | - | ||||||||||||
| 2146 | { | - | ||||||||||||
| 2147 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2148 | return privateDb()->applicationFonts.value(id).families; | - | ||||||||||||
| 2149 | } | - | ||||||||||||
| 2150 | QFont QFontDatabase::systemFont(QFontDatabase::SystemFont type) | - | ||||||||||||
| 2151 | { | - | ||||||||||||
| 2152 | const QFont *font = 0; | - | ||||||||||||
| 2153 | if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { | - | ||||||||||||
| 2154 | switch (type) { | - | ||||||||||||
| 2155 | case GeneralFont: | - | ||||||||||||
| 2156 | font = theme->font(QPlatformTheme::SystemFont); | - | ||||||||||||
| 2157 | break; | - | ||||||||||||
| 2158 | case FixedFont: | - | ||||||||||||
| 2159 | font = theme->font(QPlatformTheme::FixedFont); | - | ||||||||||||
| 2160 | break; | - | ||||||||||||
| 2161 | case TitleFont: | - | ||||||||||||
| 2162 | font = theme->font(QPlatformTheme::TitleBarFont); | - | ||||||||||||
| 2163 | break; | - | ||||||||||||
| 2164 | case SmallestReadableFont: | - | ||||||||||||
| 2165 | font = theme->font(QPlatformTheme::MiniFont); | - | ||||||||||||
| 2166 | break; | - | ||||||||||||
| 2167 | } | - | ||||||||||||
| 2168 | } | - | ||||||||||||
| 2169 | - | |||||||||||||
| 2170 | if (font) | - | ||||||||||||
| 2171 | return *font; | - | ||||||||||||
| 2172 | else if (QPlatformIntegration *integration = QGuiApplicationPrivate::platformIntegration()) | - | ||||||||||||
| 2173 | return integration->fontDatabase()->defaultFont(); | - | ||||||||||||
| 2174 | else | - | ||||||||||||
| 2175 | return QFont(); | - | ||||||||||||
| 2176 | } | - | ||||||||||||
| 2177 | bool QFontDatabase::removeApplicationFont(int handle) | - | ||||||||||||
| 2178 | { | - | ||||||||||||
| 2179 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2180 | - | |||||||||||||
| 2181 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 2182 | if (handle < 0 || handle >= db->applicationFonts.count()) | - | ||||||||||||
| 2183 | return false; | - | ||||||||||||
| 2184 | - | |||||||||||||
| 2185 | db->applicationFonts[handle] = QFontDatabasePrivate::ApplicationFont(); | - | ||||||||||||
| 2186 | - | |||||||||||||
| 2187 | db->reregisterAppFonts = true; | - | ||||||||||||
| 2188 | db->invalidate(); | - | ||||||||||||
| 2189 | return true; | - | ||||||||||||
| 2190 | } | - | ||||||||||||
| 2191 | bool QFontDatabase::removeAllApplicationFonts() | - | ||||||||||||
| 2192 | { | - | ||||||||||||
| 2193 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2194 | - | |||||||||||||
| 2195 | QFontDatabasePrivate *db = privateDb(); | - | ||||||||||||
| 2196 | if (db->applicationFonts.isEmpty()) | - | ||||||||||||
| 2197 | return false; | - | ||||||||||||
| 2198 | - | |||||||||||||
| 2199 | db->applicationFonts.clear(); | - | ||||||||||||
| 2200 | db->invalidate(); | - | ||||||||||||
| 2201 | return true; | - | ||||||||||||
| 2202 | } | - | ||||||||||||
| 2203 | bool QFontDatabase::supportsThreadedFontRendering() | - | ||||||||||||
| 2204 | { | - | ||||||||||||
| 2205 | return true; | - | ||||||||||||
| 2206 | } | - | ||||||||||||
| 2207 | - | |||||||||||||
| 2208 | - | |||||||||||||
| 2209 | - | |||||||||||||
| 2210 | - | |||||||||||||
| 2211 | - | |||||||||||||
| 2212 | QFontEngine *QFontDatabase::findFont(const QFontDef &request, int script) | - | ||||||||||||
| 2213 | { | - | ||||||||||||
| 2214 | QMutexLocker locker(fontDatabaseMutex()); | - | ||||||||||||
| 2215 | - | |||||||||||||
| 2216 | if (!privateDb()->count
| 0 | ||||||||||||
| 2217 | initializeDb(); never executed: initializeDb(); | 0 | ||||||||||||
| 2218 | - | |||||||||||||
| 2219 | QFontEngine *engine; | - | ||||||||||||
| 2220 | - | |||||||||||||
| 2221 | - | |||||||||||||
| 2222 | - | |||||||||||||
| 2223 | if (qt_enable_test_font
| 0 | ||||||||||||
| 2224 | engine = new QTestFontEngine(request.pixelSize); | - | ||||||||||||
| 2225 | engine->fontDef = request; | - | ||||||||||||
| 2226 | return never executed: engine;return engine;never executed: return engine; | 0 | ||||||||||||
| 2227 | } | - | ||||||||||||
| 2228 | - | |||||||||||||
| 2229 | - | |||||||||||||
| 2230 | QFontCache *fontCache = QFontCache::instance(); | - | ||||||||||||
| 2231 | - | |||||||||||||
| 2232 | - | |||||||||||||
| 2233 | - | |||||||||||||
| 2234 | - | |||||||||||||
| 2235 | bool multi = !(request.styleStrategy & QFont::NoFontMerging); | - | ||||||||||||
| 2236 | QFontCache::Key key(request, script, multi ? 1 : 0); | - | ||||||||||||
| 2237 | engine = fontCache->findEngine(key); | - | ||||||||||||
| 2238 | if (engine
| 0 | ||||||||||||
| 2239 | if (false) QMessageLogger(__FILE__, 26552657, __PRETTY_FUNCTION__).debug("Cache hit level 1"); dead code: QMessageLogger(__FILE__, 2657, __PRETTY_FUNCTION__).debug("Cache hit level 1"); | - | ||||||||||||
| 2240 | return never executed: engine;return engine;never executed: return engine; | 0 | ||||||||||||
| 2241 | } | - | ||||||||||||
| 2242 | - | |||||||||||||
| 2243 | QString family_name, foundry_name; | - | ||||||||||||
| 2244 | - | |||||||||||||
| 2245 | parseFontName(request.family, foundry_name, family_name); | - | ||||||||||||
| 2246 | - | |||||||||||||
| 2247 | QtFontDesc desc; | - | ||||||||||||
| 2248 | QList<int> blackListed; | - | ||||||||||||
| 2249 | int index = match(multi ? QChar::Script_Common : script, request, family_name, foundry_name, &desc, blackListed); | - | ||||||||||||
| 2250 | if (index >= 0
| 0 | ||||||||||||
| 2251 | engine = loadEngine(script, request, desc.family, desc.foundry, desc.style, desc.size); | - | ||||||||||||
| 2252 | if (engine
| 0 | ||||||||||||
| 2253 | initFontDef(desc, request, &engine->fontDef, multi); never executed: initFontDef(desc, request, &engine->fontDef, multi); | 0 | ||||||||||||
| 2254 | else | - | ||||||||||||
| 2255 | blackListed.append(index); never executed: blackListed.append(index); | 0 | ||||||||||||
| 2256 | } else { | - | ||||||||||||
| 2257 | if (false) QMessageLogger(__FILE__, 26732675, __PRETTY_FUNCTION__).debug(" NO MATCH FOUND\n"); dead code: QMessageLogger(__FILE__, 2675, __PRETTY_FUNCTION__).debug(" NO MATCH FOUND\n"); | - | ||||||||||||
| 2258 | } never executed: end of block | 0 | ||||||||||||
| 2259 | - | |||||||||||||
| 2260 | if (!engine
| 0 | ||||||||||||
| 2261 | if (!request.family.isEmpty()
| 0 | ||||||||||||
| 2262 | QFont::StyleHint styleHint = QFont::StyleHint(request.styleHint); | - | ||||||||||||
| 2263 | if (styleHint == QFont::AnyStyle
| 0 | ||||||||||||
| 2264 | styleHint = QFont::TypeWriter; never executed: styleHint = QFont::TypeWriter; | 0 | ||||||||||||
| 2265 | - | |||||||||||||
| 2266 | QStringList fallbacks = request.fallBackFamilies | - | ||||||||||||
| 2267 | + fallbacksForFamily(request.family, | - | ||||||||||||
| 2268 | QFont::Style(request.style), | - | ||||||||||||
| 2269 | styleHint, | - | ||||||||||||
| 2270 | QChar::Script(script)); | - | ||||||||||||
| 2271 | if (script > QChar::Script_Common
| 0 | ||||||||||||
| 2272 | fallbacks += QString(); never executed: fallbacks += QString(); | 0 | ||||||||||||
| 2273 | - | |||||||||||||
| 2274 | for (int i = 0; !engine
| 0 | ||||||||||||
| 2275 | QFontDef def = request; | - | ||||||||||||
| 2276 | def.family = fallbacks.at(i); | - | ||||||||||||
| 2277 | QFontCache::Key key(def, script, multi ? 1 : 0); | - | ||||||||||||
| 2278 | engine = fontCache->findEngine(key); | - | ||||||||||||
| 2279 | if (!engine
| 0 | ||||||||||||
| 2280 | QtFontDesc desc; | - | ||||||||||||
| 2281 | do { | - | ||||||||||||
| 2282 | index = match(multi ? QChar::Script_Common : script, def, def.family, QLatin1String(""), &desc, blackListed); | - | ||||||||||||
| 2283 | if (index >= 0
| 0 | ||||||||||||
| 2284 | QFontDef loadDef = def; | - | ||||||||||||
| 2285 | if (loadDef.family.isEmpty()
| 0 | ||||||||||||
| 2286 | loadDef.family = desc.family->name; never executed: loadDef.family = desc.family->name; | 0 | ||||||||||||
| 2287 | engine = loadEngine(script, loadDef, desc.family, desc.foundry, desc.style, desc.size); | - | ||||||||||||
| 2288 | if (engine
| 0 | ||||||||||||
| 2289 | initFontDef(desc, loadDef, &engine->fontDef, multi); never executed: initFontDef(desc, loadDef, &engine->fontDef, multi); | 0 | ||||||||||||
| 2290 | else | - | ||||||||||||
| 2291 | blackListed.append(index); never executed: blackListed.append(index); | 0 | ||||||||||||
| 2292 | } | - | ||||||||||||
| 2293 | } never executed: while (index >= 0end of block
| 0 | ||||||||||||
| 2294 | } never executed: end of block | 0 | ||||||||||||
| 2295 | } never executed: end of block | 0 | ||||||||||||
| 2296 | } never executed: end of block | 0 | ||||||||||||
| 2297 | - | |||||||||||||
| 2298 | if (!engine
| 0 | ||||||||||||
| 2299 | engine = new QFontEngineBox(request.pixelSize); never executed: engine = new QFontEngineBox(request.pixelSize); | 0 | ||||||||||||
| 2300 | - | |||||||||||||
| 2301 | if (false) QMessageLogger(__FILE__, 27172719, __PRETTY_FUNCTION__).debug("returning box engine"); dead code: QMessageLogger(__FILE__, 2719, __PRETTY_FUNCTION__).debug("returning box engine"); | - | ||||||||||||
| 2302 | } never executed: end of block | 0 | ||||||||||||
| 2303 | - | |||||||||||||
| 2304 | return never executed: engine;return engine;never executed: return engine; | 0 | ||||||||||||
| 2305 | } | - | ||||||||||||
| 2306 | - | |||||||||||||
| 2307 | void QFontDatabase::load(const QFontPrivate *d, int script) | - | ||||||||||||
| 2308 | { | - | ||||||||||||
| 2309 | QFontDef req = d->request; | - | ||||||||||||
| 2310 | - | |||||||||||||
| 2311 | if (req.pixelSize == -1) { | - | ||||||||||||
| 2312 | req.pixelSize = std::floor(((req.pointSize * d->dpi) / 72) * 100 + 0.5) / 100; | - | ||||||||||||
| 2313 | req.pixelSize = qRound(req.pixelSize); | - | ||||||||||||
| 2314 | } | - | ||||||||||||
| 2315 | if (req.pointSize < 0) | - | ||||||||||||
| 2316 | req.pointSize = req.pixelSize*72.0/d->dpi; | - | ||||||||||||
| 2317 | if (req.stretch == 0) | - | ||||||||||||
| 2318 | req.stretch = 100; | - | ||||||||||||
| 2319 | - | |||||||||||||
| 2320 | - | |||||||||||||
| 2321 | const QStringList fallBackFamilies = familyList(req); | - | ||||||||||||
| 2322 | - | |||||||||||||
| 2323 | if (!d->engineData) { | - | ||||||||||||
| 2324 | QFontCache *fontCache = QFontCache::instance(); | - | ||||||||||||
| 2325 | - | |||||||||||||
| 2326 | - | |||||||||||||
| 2327 | - | |||||||||||||
| 2328 | req.family = fallBackFamilies.join(QLatin1Char(',')); | - | ||||||||||||
| 2329 | - | |||||||||||||
| 2330 | d->engineData = fontCache->findEngineData(req); | - | ||||||||||||
| 2331 | if (!d->engineData) { | - | ||||||||||||
| 2332 | - | |||||||||||||
| 2333 | d->engineData = new QFontEngineData; | - | ||||||||||||
| 2334 | fontCache->insertEngineData(req, d->engineData); | - | ||||||||||||
| 2335 | } | - | ||||||||||||
| 2336 | d->engineData->ref.ref(); | - | ||||||||||||
| 2337 | } | - | ||||||||||||
| 2338 | - | |||||||||||||
| 2339 | - | |||||||||||||
| 2340 | if (d->engineData->engines[script]) | - | ||||||||||||
| 2341 | return; | - | ||||||||||||
| 2342 | - | |||||||||||||
| 2343 | QFontEngine *fe = nullptr; | - | ||||||||||||
| 2344 | - | |||||||||||||
| 2345 | req.fallBackFamilies = fallBackFamilies; | - | ||||||||||||
| 2346 | if (!req.fallBackFamilies.isEmpty()) | - | ||||||||||||
| 2347 | req.family = req.fallBackFamilies.takeFirst(); | - | ||||||||||||
| 2348 | - | |||||||||||||
| 2349 | - | |||||||||||||
| 2350 | QStringList family_list; | - | ||||||||||||
| 2351 | - | |||||||||||||
| 2352 | if (!req.family.isEmpty()) { | - | ||||||||||||
| 2353 | - | |||||||||||||
| 2354 | family_list << req.family; | - | ||||||||||||
| 2355 | - | |||||||||||||
| 2356 | - | |||||||||||||
| 2357 | QString defaultFamily = QGuiApplication::font().family(); | - | ||||||||||||
| 2358 | if (! family_list.contains(defaultFamily)) | - | ||||||||||||
| 2359 | family_list << defaultFamily; | - | ||||||||||||
| 2360 | - | |||||||||||||
| 2361 | } | - | ||||||||||||
| 2362 | - | |||||||||||||
| 2363 | - | |||||||||||||
| 2364 | family_list << QString(); | - | ||||||||||||
| 2365 | - | |||||||||||||
| 2366 | QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd(); | - | ||||||||||||
| 2367 | for (; !fe && it != end; ++it) { | - | ||||||||||||
| 2368 | req.family = *it; | - | ||||||||||||
| 2369 | - | |||||||||||||
| 2370 | fe = QFontDatabase::findFont(req, script); | - | ||||||||||||
| 2371 | if (fe) { | - | ||||||||||||
| 2372 | if (fe->type() == QFontEngine::Box && !req.family.isEmpty()) { | - | ||||||||||||
| 2373 | if (fe->ref.load() == 0) | - | ||||||||||||
| 2374 | delete fe; | - | ||||||||||||
| 2375 | fe = 0; | - | ||||||||||||
| 2376 | } else { | - | ||||||||||||
| 2377 | if (d->dpi > 0) | - | ||||||||||||
| 2378 | fe->fontDef.pointSize = qreal(double((fe->fontDef.pixelSize * 72) / d->dpi)); | - | ||||||||||||
| 2379 | } | - | ||||||||||||
| 2380 | } | - | ||||||||||||
| 2381 | - | |||||||||||||
| 2382 | - | |||||||||||||
| 2383 | req.fallBackFamilies.clear(); | - | ||||||||||||
| 2384 | } | - | ||||||||||||
| 2385 | - | |||||||||||||
| 2386 | ((!(fe)) ? qt_assert("fe",__FILE__,28022804) : qt_noop()); | - | ||||||||||||
| 2387 | if (fe->symbol || (d->request.styleStrategy & QFont::NoFontMerging)) { | - | ||||||||||||
| 2388 | for (int i = 0; i < QChar::ScriptCount; ++i) { | - | ||||||||||||
| 2389 | if (!d->engineData->engines[i]) { | - | ||||||||||||
| 2390 | d->engineData->engines[i] = fe; | - | ||||||||||||
| 2391 | fe->ref.ref(); | - | ||||||||||||
| 2392 | } | - | ||||||||||||
| 2393 | } | - | ||||||||||||
| 2394 | } else { | - | ||||||||||||
| 2395 | d->engineData->engines[script] = fe; | - | ||||||||||||
| 2396 | fe->ref.ref(); | - | ||||||||||||
| 2397 | } | - | ||||||||||||
| 2398 | } | - | ||||||||||||
| 2399 | - | |||||||||||||
| 2400 | QString QFontDatabase::resolveFontFamilyAlias(const QString &family) | - | ||||||||||||
| 2401 | { | - | ||||||||||||
| 2402 | return QGuiApplicationPrivate::platformIntegration()->fontDatabase()->resolveFontFamilyAlias(family); | - | ||||||||||||
| 2403 | } | - | ||||||||||||
| 2404 | - | |||||||||||||
| 2405 | - | |||||||||||||
| 2406 | - | |||||||||||||
| Switch to Source code | Preprocessed file |