| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/text/qfont.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qfont.h" | - | ||||||||||||||||||||||||
| 41 | #include "qdebug.h" | - | ||||||||||||||||||||||||
| 42 | #include "qpaintdevice.h" | - | ||||||||||||||||||||||||
| 43 | #include "qfontdatabase.h" | - | ||||||||||||||||||||||||
| 44 | #include "qfontmetrics.h" | - | ||||||||||||||||||||||||
| 45 | #include "qfontinfo.h" | - | ||||||||||||||||||||||||
| 46 | #include "qpainter.h" | - | ||||||||||||||||||||||||
| 47 | #include "qhash.h" | - | ||||||||||||||||||||||||
| 48 | #include "qdatastream.h" | - | ||||||||||||||||||||||||
| 49 | #include "qguiapplication.h" | - | ||||||||||||||||||||||||
| 50 | #include "qstringlist.h" | - | ||||||||||||||||||||||||
| 51 | #include "qscreen.h" | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | #include "qthread.h" | - | ||||||||||||||||||||||||
| 54 | #include "qthreadstorage.h" | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | #include "qfont_p.h" | - | ||||||||||||||||||||||||
| 57 | #include <private/qfontengine_p.h> | - | ||||||||||||||||||||||||
| 58 | #include <private/qpainter_p.h> | - | ||||||||||||||||||||||||
| 59 | #include <private/qtextengine_p.h> | - | ||||||||||||||||||||||||
| 60 | #include <limits.h> | - | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | #include <qpa/qplatformscreen.h> | - | ||||||||||||||||||||||||
| 63 | #include <qpa/qplatformintegration.h> | - | ||||||||||||||||||||||||
| 64 | #include <qpa/qplatformfontdatabase.h> | - | ||||||||||||||||||||||||
| 65 | #include <QtGui/private/qguiapplication_p.h> | - | ||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | #include <QtCore/QMutexLocker> | - | ||||||||||||||||||||||||
| 68 | #include <QtCore/QMutex> | - | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | // #define QFONTCACHE_DEBUG | - | ||||||||||||||||||||||||
| 71 | #ifdef QFONTCACHE_DEBUG | - | ||||||||||||||||||||||||
| 72 | # define FC_DEBUG qDebug | - | ||||||||||||||||||||||||
| 73 | #else | - | ||||||||||||||||||||||||
| 74 | # define FC_DEBUG if (false) qDebug | - | ||||||||||||||||||||||||
| 75 | #endif | - | ||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||
| 77 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | #ifndef QFONTCACHE_DECREASE_TRIGGER_LIMIT | - | ||||||||||||||||||||||||
| 80 | # define QFONTCACHE_DECREASE_TRIGGER_LIMIT 256 | - | ||||||||||||||||||||||||
| 81 | #endif | - | ||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||
| 83 | bool QFontDef::exactMatch(const QFontDef &other) const | - | ||||||||||||||||||||||||
| 84 | { | - | ||||||||||||||||||||||||
| 85 | /* | - | ||||||||||||||||||||||||
| 86 | QFontDef comparison is more complicated than just simple | - | ||||||||||||||||||||||||
| 87 | per-member comparisons. | - | ||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | When comparing point/pixel sizes, either point or pixelsize | - | ||||||||||||||||||||||||
| 90 | could be -1. in This case we have to compare the non negative | - | ||||||||||||||||||||||||
| 91 | size value. | - | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | This test will fail if the point-sizes differ by 1/2 point or | - | ||||||||||||||||||||||||
| 94 | more or they do not round to the same value. We have to do this | - | ||||||||||||||||||||||||
| 95 | since our API still uses 'int' point-sizes in the API, but store | - | ||||||||||||||||||||||||
| 96 | deci-point-sizes internally. | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | To compare the family members, we need to parse the font names | - | ||||||||||||||||||||||||
| 99 | and compare the family/foundry strings separately. This allows | - | ||||||||||||||||||||||||
| 100 | us to compare e.g. "Helvetica" and "Helvetica [Adobe]" with | - | ||||||||||||||||||||||||
| 101 | positive results. | - | ||||||||||||||||||||||||
| 102 | */ | - | ||||||||||||||||||||||||
| 103 | if (pixelSize != -1 && other.pixelSize != -1) {
| 0 | ||||||||||||||||||||||||
| 104 | if (pixelSize != other.pixelSize)
| 0 | ||||||||||||||||||||||||
| 105 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 106 | } else if (pointSize != -1 && other.pointSize != -1) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 107 | if (pointSize != other.pointSize)
| 0 | ||||||||||||||||||||||||
| 108 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 109 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 110 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 111 | } | - | ||||||||||||||||||||||||
| 112 | - | |||||||||||||||||||||||||
| 113 | if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch)
| 0 | ||||||||||||||||||||||||
| 114 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | if (stretch != 0 && other.stretch != 0 && stretch != other.stretch)
| 0 | ||||||||||||||||||||||||
| 117 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | QString this_family, this_foundry, other_family, other_foundry; | - | ||||||||||||||||||||||||
| 120 | QFontDatabase::parseFontName(family, this_foundry, this_family); | - | ||||||||||||||||||||||||
| 121 | QFontDatabase::parseFontName(other.family, other_foundry, other_family); | - | ||||||||||||||||||||||||
| this_family = QFontDatabase::resolveFontFamilyAlias(this_family); | ||||||||||||||||||||||||||
| other_family = QFontDatabase::resolveFontFamilyAlias(other_family); | ||||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | return (styleHint == other.styleHint never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 124 | && styleStrategy == other.styleStrategy never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 125 | && weight == other.weight never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 126 | && style == other.style never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 127 | && this_family == other_family never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 128 | && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 129 | && (this_foundry.isEmpty() never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 130 | || other_foundry.isEmpty() never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 131 | || this_foundry == other_foundry) never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 132 | ); never executed: return (styleHint == other.styleHint && styleStrategy == other.styleStrategy && weight == other.weight && style == other.style && this_family == other_family && (styleName.isEmpty() || other.styleName.isEmpty() || styleName == other.styleName) && (this_foundry.isEmpty() || other_foundry.isEmpty() || this_foundry == other_foundry) ); | 0 | ||||||||||||||||||||||||
| 133 | } | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | extern bool qt_is_gui_used; | - | ||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||
| 137 | Q_GUI_EXPORT int qt_defaultDpiX() | - | ||||||||||||||||||||||||
| 138 | { | - | ||||||||||||||||||||||||
| 139 | if (QCoreApplication::instance()->testAttribute(Qt::AA_Use96Dpi)) | - | ||||||||||||||||||||||||
| 140 | return 96; | - | ||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||
| 142 | if (!qt_is_gui_used) | - | ||||||||||||||||||||||||
| 143 | return 75; | - | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | if (const QScreen *screen = QGuiApplication::primaryScreen()) | - | ||||||||||||||||||||||||
| 146 | return qRound(screen->logicalDotsPerInchX()); | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | //PI has not been initialised, or it is being initialised. Give a default dpi | - | ||||||||||||||||||||||||
| 149 | return 100; | - | ||||||||||||||||||||||||
| 150 | } | - | ||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | Q_GUI_EXPORT int qt_defaultDpiY() | - | ||||||||||||||||||||||||
| 153 | { | - | ||||||||||||||||||||||||
| 154 | if (QCoreApplication::instance()->testAttribute(Qt::AA_Use96Dpi)) | - | ||||||||||||||||||||||||
| 155 | return 96; | - | ||||||||||||||||||||||||
| 156 | - | |||||||||||||||||||||||||
| 157 | if (!qt_is_gui_used) | - | ||||||||||||||||||||||||
| 158 | return 75; | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | if (const QScreen *screen = QGuiApplication::primaryScreen()) | - | ||||||||||||||||||||||||
| 161 | return qRound(screen->logicalDotsPerInchY()); | - | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | //PI has not been initialised, or it is being initialised. Give a default dpi | - | ||||||||||||||||||||||||
| 164 | return 100; | - | ||||||||||||||||||||||||
| 165 | } | - | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | Q_GUI_EXPORT int qt_defaultDpi() | - | ||||||||||||||||||||||||
| 168 | { | - | ||||||||||||||||||||||||
| 169 | return qt_defaultDpiY(); | - | ||||||||||||||||||||||||
| 170 | } | - | ||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||
| 172 | QFontPrivate::QFontPrivate() | - | ||||||||||||||||||||||||
| 173 | : engineData(0), dpi(qt_defaultDpi()), screen(0), | - | ||||||||||||||||||||||||
| 174 | underline(false), overline(false), strikeOut(false), kerning(true), | - | ||||||||||||||||||||||||
| 175 | capital(0), letterSpacingIsAbsolute(false), scFont(0) | - | ||||||||||||||||||||||||
| 176 | { | - | ||||||||||||||||||||||||
| 177 | } | - | ||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||
| 179 | QFontPrivate::QFontPrivate(const QFontPrivate &other) | - | ||||||||||||||||||||||||
| 180 | : request(other.request), engineData(0), dpi(other.dpi), screen(other.screen), | - | ||||||||||||||||||||||||
| 181 | underline(other.underline), overline(other.overline), | - | ||||||||||||||||||||||||
| 182 | strikeOut(other.strikeOut), kerning(other.kerning), | - | ||||||||||||||||||||||||
| 183 | capital(other.capital), letterSpacingIsAbsolute(other.letterSpacingIsAbsolute), | - | ||||||||||||||||||||||||
| 184 | letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing), | - | ||||||||||||||||||||||||
| 185 | scFont(other.scFont) | - | ||||||||||||||||||||||||
| 186 | { | - | ||||||||||||||||||||||||
| 187 | if (scFont && scFont != this) | - | ||||||||||||||||||||||||
| 188 | scFont->ref.ref(); | - | ||||||||||||||||||||||||
| 189 | } | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | QFontPrivate::~QFontPrivate() | - | ||||||||||||||||||||||||
| 192 | { | - | ||||||||||||||||||||||||
| 193 | if (engineData && !engineData->ref.deref()) | - | ||||||||||||||||||||||||
| 194 | delete engineData; | - | ||||||||||||||||||||||||
| 195 | engineData = 0; | - | ||||||||||||||||||||||||
| 196 | if (scFont && scFont != this) | - | ||||||||||||||||||||||||
| 197 | scFont->ref.deref(); | - | ||||||||||||||||||||||||
| 198 | scFont = 0; | - | ||||||||||||||||||||||||
| 199 | } | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | extern QMutex *qt_fontdatabase_mutex(); | - | ||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||
| 203 | #define QT_FONT_ENGINE_FROM_DATA(data, script) data->engines[script] | - | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | QFontEngine *QFontPrivate::engineForScript(int script) const | - | ||||||||||||||||||||||||
| 206 | { | - | ||||||||||||||||||||||||
| 207 | QMutexLocker locker(qt_fontdatabase_mutex()); | - | ||||||||||||||||||||||||
| 208 | if (script <= QChar::Script_Latin) | - | ||||||||||||||||||||||||
| 209 | script = QChar::Script_Common; | - | ||||||||||||||||||||||||
| 210 | if (engineData && engineData->fontCacheId != QFontCache::instance()->id()) { | - | ||||||||||||||||||||||||
| 211 | // throw out engineData that came from a different thread | - | ||||||||||||||||||||||||
| 212 | if (!engineData->ref.deref()) | - | ||||||||||||||||||||||||
| 213 | delete engineData; | - | ||||||||||||||||||||||||
| 214 | engineData = 0; | - | ||||||||||||||||||||||||
| 215 | } | - | ||||||||||||||||||||||||
| 216 | if (!engineData || !QT_FONT_ENGINE_FROM_DATA(engineData, script)) | - | ||||||||||||||||||||||||
| 217 | QFontDatabase::load(this, script); | - | ||||||||||||||||||||||||
| 218 | return QT_FONT_ENGINE_FROM_DATA(engineData, script); | - | ||||||||||||||||||||||||
| 219 | } | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | void QFontPrivate::alterCharForCapitalization(QChar &c) const { | - | ||||||||||||||||||||||||
| 222 | switch (capital) { | - | ||||||||||||||||||||||||
| 223 | case QFont::AllUppercase: | - | ||||||||||||||||||||||||
| 224 | case QFont::SmallCaps: | - | ||||||||||||||||||||||||
| 225 | c = c.toUpper(); | - | ||||||||||||||||||||||||
| 226 | break; | - | ||||||||||||||||||||||||
| 227 | case QFont::AllLowercase: | - | ||||||||||||||||||||||||
| 228 | c = c.toLower(); | - | ||||||||||||||||||||||||
| 229 | break; | - | ||||||||||||||||||||||||
| 230 | case QFont::MixedCase: | - | ||||||||||||||||||||||||
| 231 | break; | - | ||||||||||||||||||||||||
| 232 | } | - | ||||||||||||||||||||||||
| 233 | } | - | ||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||
| 235 | QFontPrivate *QFontPrivate::smallCapsFontPrivate() const | - | ||||||||||||||||||||||||
| 236 | { | - | ||||||||||||||||||||||||
| 237 | if (scFont) | - | ||||||||||||||||||||||||
| 238 | return scFont; | - | ||||||||||||||||||||||||
| 239 | QFont font(const_cast<QFontPrivate *>(this)); | - | ||||||||||||||||||||||||
| 240 | qreal pointSize = font.pointSizeF(); | - | ||||||||||||||||||||||||
| 241 | if (pointSize > 0) | - | ||||||||||||||||||||||||
| 242 | font.setPointSizeF(pointSize * .7); | - | ||||||||||||||||||||||||
| 243 | else | - | ||||||||||||||||||||||||
| 244 | font.setPixelSize((font.pixelSize() * 7 + 5) / 10); | - | ||||||||||||||||||||||||
| 245 | scFont = font.d.data(); | - | ||||||||||||||||||||||||
| 246 | if (scFont != this) | - | ||||||||||||||||||||||||
| 247 | scFont->ref.ref(); | - | ||||||||||||||||||||||||
| 248 | return scFont; | - | ||||||||||||||||||||||||
| 249 | } | - | ||||||||||||||||||||||||
| 250 | - | |||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | void QFontPrivate::resolve(uint mask, const QFontPrivate *other) | - | ||||||||||||||||||||||||
| 253 | { | - | ||||||||||||||||||||||||
| 254 | Q_ASSERT(other != 0); | - | ||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | dpi = other->dpi; | - | ||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||
| 258 | if ((mask & QFont::AllPropertiesResolved) == QFont::AllPropertiesResolved) return; | - | ||||||||||||||||||||||||
| 259 | - | |||||||||||||||||||||||||
| 260 | // assign the unset-bits with the set-bits of the other font def | - | ||||||||||||||||||||||||
| 261 | if (! (mask & QFont::FamilyResolved)) | - | ||||||||||||||||||||||||
| 262 | request.family = other->request.family; | - | ||||||||||||||||||||||||
| 263 | - | |||||||||||||||||||||||||
| 264 | if (! (mask & QFont::StyleNameResolved)) | - | ||||||||||||||||||||||||
| 265 | request.styleName = other->request.styleName; | - | ||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||
| 267 | if (! (mask & QFont::SizeResolved)) { | - | ||||||||||||||||||||||||
| 268 | request.pointSize = other->request.pointSize; | - | ||||||||||||||||||||||||
| 269 | request.pixelSize = other->request.pixelSize; | - | ||||||||||||||||||||||||
| 270 | } | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | if (! (mask & QFont::StyleHintResolved)) | - | ||||||||||||||||||||||||
| 273 | request.styleHint = other->request.styleHint; | - | ||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||
| 275 | if (! (mask & QFont::StyleStrategyResolved)) | - | ||||||||||||||||||||||||
| 276 | request.styleStrategy = other->request.styleStrategy; | - | ||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||
| 278 | if (! (mask & QFont::WeightResolved)) | - | ||||||||||||||||||||||||
| 279 | request.weight = other->request.weight; | - | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | if (! (mask & QFont::StyleResolved)) | - | ||||||||||||||||||||||||
| 282 | request.style = other->request.style; | - | ||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||
| 284 | if (! (mask & QFont::FixedPitchResolved)) | - | ||||||||||||||||||||||||
| 285 | request.fixedPitch = other->request.fixedPitch; | - | ||||||||||||||||||||||||
| 286 | - | |||||||||||||||||||||||||
| 287 | if (! (mask & QFont::StretchResolved)) | - | ||||||||||||||||||||||||
| 288 | request.stretch = other->request.stretch; | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | if (! (mask & QFont::HintingPreferenceResolved)) | - | ||||||||||||||||||||||||
| 291 | request.hintingPreference = other->request.hintingPreference; | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | if (! (mask & QFont::UnderlineResolved)) | - | ||||||||||||||||||||||||
| 294 | underline = other->underline; | - | ||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||
| 296 | if (! (mask & QFont::OverlineResolved)) | - | ||||||||||||||||||||||||
| 297 | overline = other->overline; | - | ||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||
| 299 | if (! (mask & QFont::StrikeOutResolved)) | - | ||||||||||||||||||||||||
| 300 | strikeOut = other->strikeOut; | - | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | if (! (mask & QFont::KerningResolved)) | - | ||||||||||||||||||||||||
| 303 | kerning = other->kerning; | - | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | if (! (mask & QFont::LetterSpacingResolved)) { | - | ||||||||||||||||||||||||
| 306 | letterSpacing = other->letterSpacing; | - | ||||||||||||||||||||||||
| 307 | letterSpacingIsAbsolute = other->letterSpacingIsAbsolute; | - | ||||||||||||||||||||||||
| 308 | } | - | ||||||||||||||||||||||||
| 309 | if (! (mask & QFont::WordSpacingResolved)) | - | ||||||||||||||||||||||||
| 310 | wordSpacing = other->wordSpacing; | - | ||||||||||||||||||||||||
| 311 | if (! (mask & QFont::CapitalizationResolved)) | - | ||||||||||||||||||||||||
| 312 | capital = other->capital; | - | ||||||||||||||||||||||||
| 313 | } | - | ||||||||||||||||||||||||
| 314 | - | |||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | QFontEngineData::QFontEngineData() | - | ||||||||||||||||||||||||
| 319 | : ref(0), fontCacheId(QFontCache::instance()->id()) | - | ||||||||||||||||||||||||
| 320 | { | - | ||||||||||||||||||||||||
| 321 | memset(engines, 0, QChar::ScriptCount * sizeof(QFontEngine *)); | - | ||||||||||||||||||||||||
| 322 | } | - | ||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | QFontEngineData::~QFontEngineData() | - | ||||||||||||||||||||||||
| 325 | { | - | ||||||||||||||||||||||||
| 326 | Q_ASSERT(ref.load() == 0); | - | ||||||||||||||||||||||||
| 327 | for (int i = 0; i < QChar::ScriptCount; ++i) { | - | ||||||||||||||||||||||||
| 328 | if (engines[i]) { | - | ||||||||||||||||||||||||
| 329 | if (!engines[i]->ref.deref()) | - | ||||||||||||||||||||||||
| 330 | delete engines[i]; | - | ||||||||||||||||||||||||
| 331 | engines[i] = 0; | - | ||||||||||||||||||||||||
| 332 | } | - | ||||||||||||||||||||||||
| 333 | } | - | ||||||||||||||||||||||||
| 334 | } | - | ||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | - | |||||||||||||||||||||||||
| 339 | /*! | - | ||||||||||||||||||||||||
| 340 | \class QFont | - | ||||||||||||||||||||||||
| 341 | \reentrant | - | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | \brief The QFont class specifies a font used for drawing text. | - | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | \ingroup painting | - | ||||||||||||||||||||||||
| 346 | \ingroup appearance | - | ||||||||||||||||||||||||
| 347 | \ingroup shared | - | ||||||||||||||||||||||||
| 348 | \ingroup richtext-processing | - | ||||||||||||||||||||||||
| 349 | \inmodule QtGui | - | ||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | When you create a QFont object you specify various attributes that | - | ||||||||||||||||||||||||
| 353 | you want the font to have. Qt will use the font with the specified | - | ||||||||||||||||||||||||
| 354 | attributes, or if no matching font exists, Qt will use the closest | - | ||||||||||||||||||||||||
| 355 | matching installed font. The attributes of the font that is | - | ||||||||||||||||||||||||
| 356 | actually used are retrievable from a QFontInfo object. If the | - | ||||||||||||||||||||||||
| 357 | window system provides an exact match exactMatch() returns \c true. | - | ||||||||||||||||||||||||
| 358 | Use QFontMetrics to get measurements, e.g. the pixel length of a | - | ||||||||||||||||||||||||
| 359 | string using QFontMetrics::width(). | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | Note that a QGuiApplication instance must exist before a QFont can be | - | ||||||||||||||||||||||||
| 362 | used. You can set the application's default font with | - | ||||||||||||||||||||||||
| 363 | QGuiApplication::setFont(). | - | ||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | If a chosen font does not include all the characters that | - | ||||||||||||||||||||||||
| 366 | need to be displayed, QFont will try to find the characters in the | - | ||||||||||||||||||||||||
| 367 | nearest equivalent fonts. When a QPainter draws a character from a | - | ||||||||||||||||||||||||
| 368 | font the QFont will report whether or not it has the character; if | - | ||||||||||||||||||||||||
| 369 | it does not, QPainter will draw an unfilled square. | - | ||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | Create QFonts like this: | - | ||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||
| 373 | \snippet code/src_gui_text_qfont.cpp 0 | - | ||||||||||||||||||||||||
| 374 | - | |||||||||||||||||||||||||
| 375 | The attributes set in the constructor can also be set later, e.g. | - | ||||||||||||||||||||||||
| 376 | setFamily(), setPointSize(), setPointSizeF(), setWeight() and | - | ||||||||||||||||||||||||
| 377 | setItalic(). The remaining attributes must be set after | - | ||||||||||||||||||||||||
| 378 | contstruction, e.g. setBold(), setUnderline(), setOverline(), | - | ||||||||||||||||||||||||
| 379 | setStrikeOut() and setFixedPitch(). QFontInfo objects should be | - | ||||||||||||||||||||||||
| 380 | created \e after the font's attributes have been set. A QFontInfo | - | ||||||||||||||||||||||||
| 381 | object will not change, even if you change the font's | - | ||||||||||||||||||||||||
| 382 | attributes. The corresponding "get" functions, e.g. family(), | - | ||||||||||||||||||||||||
| 383 | pointSize(), etc., return the values that were set, even though | - | ||||||||||||||||||||||||
| 384 | the values used may differ. The actual values are available from a | - | ||||||||||||||||||||||||
| 385 | QFontInfo object. | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | If the requested font family is unavailable you can influence the | - | ||||||||||||||||||||||||
| 388 | \l{#fontmatching}{font matching algorithm} by choosing a | - | ||||||||||||||||||||||||
| 389 | particular \l{QFont::StyleHint} and \l{QFont::StyleStrategy} with | - | ||||||||||||||||||||||||
| 390 | setStyleHint(). The default family (corresponding to the current | - | ||||||||||||||||||||||||
| 391 | style hint) is returned by defaultFamily(). | - | ||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||
| 393 | The font-matching algorithm has a lastResortFamily() and | - | ||||||||||||||||||||||||
| 394 | lastResortFont() in cases where a suitable match cannot be found. | - | ||||||||||||||||||||||||
| 395 | You can provide substitutions for font family names using | - | ||||||||||||||||||||||||
| 396 | insertSubstitution() and insertSubstitutions(). Substitutions can | - | ||||||||||||||||||||||||
| 397 | be removed with removeSubstitutions(). Use substitute() to retrieve | - | ||||||||||||||||||||||||
| 398 | a family's first substitute, or the family name itself if it has | - | ||||||||||||||||||||||||
| 399 | no substitutes. Use substitutes() to retrieve a list of a family's | - | ||||||||||||||||||||||||
| 400 | substitutes (which may be empty). | - | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | Every QFont has a key() which you can use, for example, as the key | - | ||||||||||||||||||||||||
| 403 | in a cache or dictionary. If you want to store a user's font | - | ||||||||||||||||||||||||
| 404 | preferences you could use QSettings, writing the font information | - | ||||||||||||||||||||||||
| 405 | with toString() and reading it back with fromString(). The | - | ||||||||||||||||||||||||
| 406 | operator<<() and operator>>() functions are also available, but | - | ||||||||||||||||||||||||
| 407 | they work on a data stream. | - | ||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | It is possible to set the height of characters shown on the screen | - | ||||||||||||||||||||||||
| 410 | to a specified number of pixels with setPixelSize(); however using | - | ||||||||||||||||||||||||
| 411 | setPointSize() has a similar effect and provides device | - | ||||||||||||||||||||||||
| 412 | independence. | - | ||||||||||||||||||||||||
| 413 | - | |||||||||||||||||||||||||
| 414 | Loading fonts can be expensive, especially on X11. QFont contains | - | ||||||||||||||||||||||||
| 415 | extensive optimizations to make the copying of QFont objects fast, | - | ||||||||||||||||||||||||
| 416 | and to cache the results of the slow window system functions it | - | ||||||||||||||||||||||||
| 417 | depends upon. | - | ||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||
| 419 | \target fontmatching | - | ||||||||||||||||||||||||
| 420 | The font matching algorithm works as follows: | - | ||||||||||||||||||||||||
| 421 | \list 1 | - | ||||||||||||||||||||||||
| 422 | \li The specified font family is searched for. | - | ||||||||||||||||||||||||
| 423 | \li If not found, the styleHint() is used to select a replacement | - | ||||||||||||||||||||||||
| 424 | family. | - | ||||||||||||||||||||||||
| 425 | \li Each replacement font family is searched for. | - | ||||||||||||||||||||||||
| 426 | \li If none of these are found or there was no styleHint(), "helvetica" | - | ||||||||||||||||||||||||
| 427 | will be searched for. | - | ||||||||||||||||||||||||
| 428 | \li If "helvetica" isn't found Qt will try the lastResortFamily(). | - | ||||||||||||||||||||||||
| 429 | \li If the lastResortFamily() isn't found Qt will try the | - | ||||||||||||||||||||||||
| 430 | lastResortFont() which will always return a name of some kind. | - | ||||||||||||||||||||||||
| 431 | \endlist | - | ||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | Note that the actual font matching algorithm varies from platform to platform. | - | ||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||
| 435 | In Windows a request for the "Courier" font is automatically changed to | - | ||||||||||||||||||||||||
| 436 | "Courier New", an improved version of Courier that allows for smooth scaling. | - | ||||||||||||||||||||||||
| 437 | The older "Courier" bitmap font can be selected by setting the PreferBitmap | - | ||||||||||||||||||||||||
| 438 | style strategy (see setStyleStrategy()). | - | ||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||
| 440 | Once a font is found, the remaining attributes are matched in order of | - | ||||||||||||||||||||||||
| 441 | priority: | - | ||||||||||||||||||||||||
| 442 | \list 1 | - | ||||||||||||||||||||||||
| 443 | \li fixedPitch() | - | ||||||||||||||||||||||||
| 444 | \li pointSize() (see below) | - | ||||||||||||||||||||||||
| 445 | \li weight() | - | ||||||||||||||||||||||||
| 446 | \li style() | - | ||||||||||||||||||||||||
| 447 | \endlist | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | If you have a font which matches on family, even if none of the | - | ||||||||||||||||||||||||
| 450 | other attributes match, this font will be chosen in preference to | - | ||||||||||||||||||||||||
| 451 | a font which doesn't match on family but which does match on the | - | ||||||||||||||||||||||||
| 452 | other attributes. This is because font family is the dominant | - | ||||||||||||||||||||||||
| 453 | search criteria. | - | ||||||||||||||||||||||||
| 454 | - | |||||||||||||||||||||||||
| 455 | The point size is defined to match if it is within 20% of the | - | ||||||||||||||||||||||||
| 456 | requested point size. When several fonts match and are only | - | ||||||||||||||||||||||||
| 457 | distinguished by point size, the font with the closest point size | - | ||||||||||||||||||||||||
| 458 | to the one requested will be chosen. | - | ||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||
| 460 | The actual family, font size, weight and other font attributes | - | ||||||||||||||||||||||||
| 461 | used for drawing text will depend on what's available for the | - | ||||||||||||||||||||||||
| 462 | chosen family under the window system. A QFontInfo object can be | - | ||||||||||||||||||||||||
| 463 | used to determine the actual values used for drawing the text. | - | ||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||
| 465 | Examples: | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | \snippet code/src_gui_text_qfont.cpp 1 | - | ||||||||||||||||||||||||
| 468 | If you had both an Adobe and a Cronyx Helvetica, you might get | - | ||||||||||||||||||||||||
| 469 | either. | - | ||||||||||||||||||||||||
| 470 | - | |||||||||||||||||||||||||
| 471 | \snippet code/src_gui_text_qfont.cpp 2 | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | You can specify the foundry you want in the family name. The font f | - | ||||||||||||||||||||||||
| 474 | in the above example will be set to "Helvetica | - | ||||||||||||||||||||||||
| 475 | [Cronyx]". | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | To determine the attributes of the font actually used in the window | - | ||||||||||||||||||||||||
| 478 | system, use a QFontInfo object, e.g. | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | \snippet code/src_gui_text_qfont.cpp 3 | - | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | To find out font metrics use a QFontMetrics object, e.g. | - | ||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | \snippet code/src_gui_text_qfont.cpp 4 | - | ||||||||||||||||||||||||
| 485 | - | |||||||||||||||||||||||||
| 486 | For more general information on fonts, see the | - | ||||||||||||||||||||||||
| 487 | \l{comp.fonts FAQ}{comp.fonts FAQ}. | - | ||||||||||||||||||||||||
| 488 | Information on encodings can be found from | - | ||||||||||||||||||||||||
| 489 | \l{Roman Czyborra's} page. | - | ||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||
| 491 | \sa QFontMetrics, QFontInfo, QFontDatabase, {Character Map Example} | - | ||||||||||||||||||||||||
| 492 | */ | - | ||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||
| 494 | /*! | - | ||||||||||||||||||||||||
| 495 | \internal | - | ||||||||||||||||||||||||
| 496 | \enum QFont::ResolveProperties | - | ||||||||||||||||||||||||
| 497 | - | |||||||||||||||||||||||||
| 498 | This enum describes the properties of a QFont that can be set on a font | - | ||||||||||||||||||||||||
| 499 | individually and then considered resolved. | - | ||||||||||||||||||||||||
| 500 | - | |||||||||||||||||||||||||
| 501 | \value FamilyResolved | - | ||||||||||||||||||||||||
| 502 | \value SizeResolved | - | ||||||||||||||||||||||||
| 503 | \value StyleHintResolved | - | ||||||||||||||||||||||||
| 504 | \value StyleStrategyResolved | - | ||||||||||||||||||||||||
| 505 | \value WeightResolved | - | ||||||||||||||||||||||||
| 506 | \value StyleResolved | - | ||||||||||||||||||||||||
| 507 | \value UnderlineResolved | - | ||||||||||||||||||||||||
| 508 | \value OverlineResolved | - | ||||||||||||||||||||||||
| 509 | \value StrikeOutResolved | - | ||||||||||||||||||||||||
| 510 | \value FixedPitchResolved | - | ||||||||||||||||||||||||
| 511 | \value StretchResolved | - | ||||||||||||||||||||||||
| 512 | \value KerningResolved | - | ||||||||||||||||||||||||
| 513 | \value CapitalizationResolved | - | ||||||||||||||||||||||||
| 514 | \value LetterSpacingResolved | - | ||||||||||||||||||||||||
| 515 | \value WordSpacingResolved | - | ||||||||||||||||||||||||
| 516 | \value CompletelyResolved | - | ||||||||||||||||||||||||
| 517 | */ | - | ||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||
| 519 | /*! | - | ||||||||||||||||||||||||
| 520 | \enum QFont::Style | - | ||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||
| 522 | This enum describes the different styles of glyphs that are used to | - | ||||||||||||||||||||||||
| 523 | display text. | - | ||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||
| 525 | \value StyleNormal Normal glyphs used in unstyled text. | - | ||||||||||||||||||||||||
| 526 | \value StyleItalic Italic glyphs that are specifically designed for | - | ||||||||||||||||||||||||
| 527 | the purpose of representing italicized text. | - | ||||||||||||||||||||||||
| 528 | \value StyleOblique Glyphs with an italic appearance that are typically | - | ||||||||||||||||||||||||
| 529 | based on the unstyled glyphs, but are not fine-tuned | - | ||||||||||||||||||||||||
| 530 | for the purpose of representing italicized text. | - | ||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||
| 532 | \sa Weight | - | ||||||||||||||||||||||||
| 533 | */ | - | ||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||
| 535 | /*! | - | ||||||||||||||||||||||||
| 536 | \fn QFont &QFont::operator=(QFont &&other) | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | Move-assigns \a other to this QFont instance. | - | ||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||
| 540 | \since 5.2 | - | ||||||||||||||||||||||||
| 541 | */ | - | ||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||
| 543 | /*! | - | ||||||||||||||||||||||||
| 544 | Constructs a font from \a font for use on the paint device \a pd. | - | ||||||||||||||||||||||||
| 545 | */ | - | ||||||||||||||||||||||||
| 546 | QFont::QFont(const QFont &font, QPaintDevice *pd) | - | ||||||||||||||||||||||||
| 547 | : resolve_mask(font.resolve_mask) | - | ||||||||||||||||||||||||
| 548 | { | - | ||||||||||||||||||||||||
| 549 | Q_ASSERT(pd != 0); | - | ||||||||||||||||||||||||
| 550 | int dpi = pd->logicalDpiY(); | - | ||||||||||||||||||||||||
| 551 | const int screen = 0; | - | ||||||||||||||||||||||||
| 552 | if (font.d->dpi != dpi || font.d->screen != screen ) {
| 0 | ||||||||||||||||||||||||
| 553 | d = new QFontPrivate(*font.d); | - | ||||||||||||||||||||||||
| 554 | d->dpi = dpi; | - | ||||||||||||||||||||||||
| 555 | d->screen = screen; | - | ||||||||||||||||||||||||
| 556 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 557 | d = font.d.data();; | - | ||||||||||||||||||||||||
| 558 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 559 | } | - | ||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||
| 561 | /*! | - | ||||||||||||||||||||||||
| 562 | \internal | - | ||||||||||||||||||||||||
| 563 | */ | - | ||||||||||||||||||||||||
| 564 | QFont::QFont(QFontPrivate *data) | - | ||||||||||||||||||||||||
| 565 | : d(data), resolve_mask(QFont::AllPropertiesResolved) | - | ||||||||||||||||||||||||
| 566 | { | - | ||||||||||||||||||||||||
| 567 | } | - | ||||||||||||||||||||||||
| 568 | - | |||||||||||||||||||||||||
| 569 | /*! \internal | - | ||||||||||||||||||||||||
| 570 | Detaches the font object from common font data. | - | ||||||||||||||||||||||||
| 571 | */ | - | ||||||||||||||||||||||||
| 572 | void QFont::detach() | - | ||||||||||||||||||||||||
| 573 | { | - | ||||||||||||||||||||||||
| 574 | if (d->ref.load() == 1) { | - | ||||||||||||||||||||||||
| 575 | if (d->engineData && !d->engineData->ref.deref()) | - | ||||||||||||||||||||||||
| 576 | delete d->engineData; | - | ||||||||||||||||||||||||
| 577 | d->engineData = 0; | - | ||||||||||||||||||||||||
| 578 | if (d->scFont && d->scFont != d.data()) | - | ||||||||||||||||||||||||
| 579 | d->scFont->ref.deref(); | - | ||||||||||||||||||||||||
| 580 | d->scFont = 0; | - | ||||||||||||||||||||||||
| 581 | return; | - | ||||||||||||||||||||||||
| 582 | } | - | ||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | d.detach(); | - | ||||||||||||||||||||||||
| 585 | } | - | ||||||||||||||||||||||||
| 586 | - | |||||||||||||||||||||||||
| 587 | /*! | - | ||||||||||||||||||||||||
| 588 | \internal | - | ||||||||||||||||||||||||
| 589 | Detaches the font object from common font attributes data. | - | ||||||||||||||||||||||||
| 590 | Call this instead of QFont::detach() if the only font attributes data | - | ||||||||||||||||||||||||
| 591 | has been changed (underline, letterSpacing, kerning, etc.). | - | ||||||||||||||||||||||||
| 592 | */ | - | ||||||||||||||||||||||||
| 593 | void QFontPrivate::detachButKeepEngineData(QFont *font) | - | ||||||||||||||||||||||||
| 594 | { | - | ||||||||||||||||||||||||
| 595 | if (font->d->ref.load() == 1) | - | ||||||||||||||||||||||||
| 596 | return; | - | ||||||||||||||||||||||||
| 597 | - | |||||||||||||||||||||||||
| 598 | QFontEngineData *engineData = font->d->engineData; | - | ||||||||||||||||||||||||
| 599 | if (engineData) | - | ||||||||||||||||||||||||
| 600 | engineData->ref.ref(); | - | ||||||||||||||||||||||||
| 601 | font->d.detach(); | - | ||||||||||||||||||||||||
| 602 | font->d->engineData = engineData; | - | ||||||||||||||||||||||||
| 603 | } | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | /*! | - | ||||||||||||||||||||||||
| 606 | Constructs a font object that uses the application's default font. | - | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | \sa QGuiApplication::setFont(), QGuiApplication::font() | - | ||||||||||||||||||||||||
| 609 | */ | - | ||||||||||||||||||||||||
| 610 | QFont::QFont() | - | ||||||||||||||||||||||||
| 611 | : d(QGuiApplicationPrivate::instance() ? QGuiApplication::font().d.data() : new QFontPrivate()), resolve_mask(0) | - | ||||||||||||||||||||||||
| 612 | { | - | ||||||||||||||||||||||||
| 613 | } | - | ||||||||||||||||||||||||
| 614 | - | |||||||||||||||||||||||||
| 615 | /*! | - | ||||||||||||||||||||||||
| 616 | Constructs a font object with the specified \a family, \a | - | ||||||||||||||||||||||||
| 617 | pointSize, \a weight and \a italic settings. | - | ||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | If \a pointSize is zero or negative, the point size of the font | - | ||||||||||||||||||||||||
| 620 | is set to a system-dependent default value. Generally, this is | - | ||||||||||||||||||||||||
| 621 | 12 points. | - | ||||||||||||||||||||||||
| 622 | - | |||||||||||||||||||||||||
| 623 | The \a family name may optionally also include a foundry name, | - | ||||||||||||||||||||||||
| 624 | e.g. "Helvetica [Cronyx]". If the \a family is | - | ||||||||||||||||||||||||
| 625 | available from more than one foundry and the foundry isn't | - | ||||||||||||||||||||||||
| 626 | specified, an arbitrary foundry is chosen. If the family isn't | - | ||||||||||||||||||||||||
| 627 | available a family will be set using the \l{QFont}{font matching} | - | ||||||||||||||||||||||||
| 628 | algorithm. | - | ||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||
| 630 | \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(), | - | ||||||||||||||||||||||||
| 631 | setStyleHint(), QGuiApplication::font() | - | ||||||||||||||||||||||||
| 632 | */ | - | ||||||||||||||||||||||||
| 633 | QFont::QFont(const QString &family, int pointSize, int weight, bool italic) | - | ||||||||||||||||||||||||
| 634 | : d(new QFontPrivate()), resolve_mask(QFont::FamilyResolved) | - | ||||||||||||||||||||||||
| 635 | { | - | ||||||||||||||||||||||||
| 636 | if (pointSize <= 0) { | - | ||||||||||||||||||||||||
| 637 | pointSize = 12; | - | ||||||||||||||||||||||||
| 638 | } else { | - | ||||||||||||||||||||||||
| 639 | resolve_mask |= QFont::SizeResolved; | - | ||||||||||||||||||||||||
| 640 | } | - | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | if (weight < 0) { | - | ||||||||||||||||||||||||
| 643 | weight = Normal; | - | ||||||||||||||||||||||||
| 644 | } else { | - | ||||||||||||||||||||||||
| 645 | resolve_mask |= QFont::WeightResolved | QFont::StyleResolved; | - | ||||||||||||||||||||||||
| 646 | } | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | if (italic) | - | ||||||||||||||||||||||||
| 649 | resolve_mask |= QFont::StyleResolved; | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | d->request.family = family; | - | ||||||||||||||||||||||||
| 652 | d->request.pointSize = qreal(pointSize); | - | ||||||||||||||||||||||||
| 653 | d->request.pixelSize = -1; | - | ||||||||||||||||||||||||
| 654 | d->request.weight = weight; | - | ||||||||||||||||||||||||
| 655 | d->request.style = italic ? QFont::StyleItalic : QFont::StyleNormal; | - | ||||||||||||||||||||||||
| 656 | } | - | ||||||||||||||||||||||||
| 657 | - | |||||||||||||||||||||||||
| 658 | /*! | - | ||||||||||||||||||||||||
| 659 | Constructs a font that is a copy of \a font. | - | ||||||||||||||||||||||||
| 660 | */ | - | ||||||||||||||||||||||||
| 661 | QFont::QFont(const QFont &font) | - | ||||||||||||||||||||||||
| 662 | : d(font.d.data()),), resolve_mask(font.resolve_mask) | - | ||||||||||||||||||||||||
| 663 | { | - | ||||||||||||||||||||||||
| 664 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 665 | - | |||||||||||||||||||||||||
| 666 | /*! | - | ||||||||||||||||||||||||
| 667 | Destroys the font object and frees all allocated resources. | - | ||||||||||||||||||||||||
| 668 | */ | - | ||||||||||||||||||||||||
| 669 | QFont::~QFont() | - | ||||||||||||||||||||||||
| 670 | { | - | ||||||||||||||||||||||||
| 671 | } | - | ||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||
| 673 | /*! | - | ||||||||||||||||||||||||
| 674 | Assigns \a font to this font and returns a reference to it. | - | ||||||||||||||||||||||||
| 675 | */ | - | ||||||||||||||||||||||||
| 676 | QFont &QFont::operator=(const QFont &font) | - | ||||||||||||||||||||||||
| 677 | { | - | ||||||||||||||||||||||||
| 678 | d = font.d.data();; | - | ||||||||||||||||||||||||
| 679 | resolve_mask = font.resolve_mask; | - | ||||||||||||||||||||||||
| 680 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
| 681 | } | - | ||||||||||||||||||||||||
| 682 | - | |||||||||||||||||||||||||
| 683 | /*! | - | ||||||||||||||||||||||||
| 684 | \fn void QFont::swap(QFont &other) | - | ||||||||||||||||||||||||
| 685 | \since 5.0 | - | ||||||||||||||||||||||||
| 686 | - | |||||||||||||||||||||||||
| 687 | Swaps this font instance with \a other. This function is very fast | - | ||||||||||||||||||||||||
| 688 | and never fails. | - | ||||||||||||||||||||||||
| 689 | */ | - | ||||||||||||||||||||||||
| 690 | - | |||||||||||||||||||||||||
| 691 | /*! | - | ||||||||||||||||||||||||
| 692 | Returns the requested font family name, i.e. the name set in the | - | ||||||||||||||||||||||||
| 693 | constructor or the last setFont() call. | - | ||||||||||||||||||||||||
| 694 | - | |||||||||||||||||||||||||
| 695 | \sa setFamily(), substitutes(), substitute() | - | ||||||||||||||||||||||||
| 696 | */ | - | ||||||||||||||||||||||||
| 697 | QString QFont::family() const | - | ||||||||||||||||||||||||
| 698 | { | - | ||||||||||||||||||||||||
| 699 | return d->request.family; | - | ||||||||||||||||||||||||
| 700 | } | - | ||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||
| 702 | /*! | - | ||||||||||||||||||||||||
| 703 | Sets the family name of the font. The name is case insensitive and | - | ||||||||||||||||||||||||
| 704 | may include a foundry name. | - | ||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||
| 706 | The \a family name may optionally also include a foundry name, | - | ||||||||||||||||||||||||
| 707 | e.g. "Helvetica [Cronyx]". If the \a family is | - | ||||||||||||||||||||||||
| 708 | available from more than one foundry and the foundry isn't | - | ||||||||||||||||||||||||
| 709 | specified, an arbitrary foundry is chosen. If the family isn't | - | ||||||||||||||||||||||||
| 710 | available a family will be set using the \l{QFont}{font matching} | - | ||||||||||||||||||||||||
| 711 | algorithm. | - | ||||||||||||||||||||||||
| 712 | - | |||||||||||||||||||||||||
| 713 | \sa family(), setStyleHint(), QFontInfo | - | ||||||||||||||||||||||||
| 714 | */ | - | ||||||||||||||||||||||||
| 715 | void QFont::setFamily(const QString &family) | - | ||||||||||||||||||||||||
| 716 | { | - | ||||||||||||||||||||||||
| 717 | if ((resolve_mask & QFont::FamilyResolved) && d->request.family == family) | - | ||||||||||||||||||||||||
| 718 | return; | - | ||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||
| 720 | detach(); | - | ||||||||||||||||||||||||
| 721 | - | |||||||||||||||||||||||||
| 722 | d->request.family = family; | - | ||||||||||||||||||||||||
| 723 | - | |||||||||||||||||||||||||
| 724 | resolve_mask |= QFont::FamilyResolved; | - | ||||||||||||||||||||||||
| 725 | } | - | ||||||||||||||||||||||||
| 726 | - | |||||||||||||||||||||||||
| 727 | /*! | - | ||||||||||||||||||||||||
| 728 | \since 4.8 | - | ||||||||||||||||||||||||
| 729 | - | |||||||||||||||||||||||||
| 730 | Returns the requested font style name, it will be used to match the | - | ||||||||||||||||||||||||
| 731 | font with irregular styles (that can't be normalized in other style | - | ||||||||||||||||||||||||
| 732 | properties). It depends on system font support, thus only works for | - | ||||||||||||||||||||||||
| 733 | \macos and X11 so far. On Windows irregular styles will be added | - | ||||||||||||||||||||||||
| 734 | as separate font families so there is no need for this. | - | ||||||||||||||||||||||||
| 735 | - | |||||||||||||||||||||||||
| 736 | \sa setFamily(), setStyle() | - | ||||||||||||||||||||||||
| 737 | */ | - | ||||||||||||||||||||||||
| 738 | QString QFont::styleName() const | - | ||||||||||||||||||||||||
| 739 | { | - | ||||||||||||||||||||||||
| 740 | return d->request.styleName; | - | ||||||||||||||||||||||||
| 741 | } | - | ||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||
| 743 | /*! | - | ||||||||||||||||||||||||
| 744 | \since 4.8 | - | ||||||||||||||||||||||||
| 745 | - | |||||||||||||||||||||||||
| 746 | Sets the style name of the font to \a styleName. When set, other style properties | - | ||||||||||||||||||||||||
| 747 | like \l style() and \l weight() will be ignored for font matching. | - | ||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||
| 749 | \sa styleName() | - | ||||||||||||||||||||||||
| 750 | */ | - | ||||||||||||||||||||||||
| 751 | void QFont::setStyleName(const QString &styleName) | - | ||||||||||||||||||||||||
| 752 | { | - | ||||||||||||||||||||||||
| 753 | if ((resolve_mask & QFont::StyleNameResolved) && d->request.styleName == styleName) | - | ||||||||||||||||||||||||
| 754 | return; | - | ||||||||||||||||||||||||
| 755 | - | |||||||||||||||||||||||||
| 756 | detach(); | - | ||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||
| 758 | d->request.styleName = styleName; | - | ||||||||||||||||||||||||
| 759 | resolve_mask |= QFont::StyleNameResolved; | - | ||||||||||||||||||||||||
| 760 | } | - | ||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||
| 762 | /*! | - | ||||||||||||||||||||||||
| 763 | Returns the point size of the font. Returns -1 if the font size | - | ||||||||||||||||||||||||
| 764 | was specified in pixels. | - | ||||||||||||||||||||||||
| 765 | - | |||||||||||||||||||||||||
| 766 | \sa setPointSize(), pointSizeF() | - | ||||||||||||||||||||||||
| 767 | */ | - | ||||||||||||||||||||||||
| 768 | int QFont::pointSize() const | - | ||||||||||||||||||||||||
| 769 | { | - | ||||||||||||||||||||||||
| 770 | return qRound(d->request.pointSize); | - | ||||||||||||||||||||||||
| 771 | } | - | ||||||||||||||||||||||||
| 772 | - | |||||||||||||||||||||||||
| 773 | /*! | - | ||||||||||||||||||||||||
| 774 | \since 4.8 | - | ||||||||||||||||||||||||
| 775 | - | |||||||||||||||||||||||||
| 776 | \enum QFont::HintingPreference | - | ||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||
| 778 | This enum describes the different levels of hinting that can be applied | - | ||||||||||||||||||||||||
| 779 | to glyphs to improve legibility on displays where it might be warranted | - | ||||||||||||||||||||||||
| 780 | by the density of pixels. | - | ||||||||||||||||||||||||
| 781 | - | |||||||||||||||||||||||||
| 782 | \value PreferDefaultHinting Use the default hinting level for the target platform. | - | ||||||||||||||||||||||||
| 783 | \value PreferNoHinting If possible, render text without hinting the outlines | - | ||||||||||||||||||||||||
| 784 | of the glyphs. The text layout will be typographically accurate and | - | ||||||||||||||||||||||||
| 785 | scalable, using the same metrics as are used e.g. when printing. | - | ||||||||||||||||||||||||
| 786 | \value PreferVerticalHinting If possible, render text with no horizontal hinting, | - | ||||||||||||||||||||||||
| 787 | but align glyphs to the pixel grid in the vertical direction. The text will appear | - | ||||||||||||||||||||||||
| 788 | crisper on displays where the density is too low to give an accurate rendering | - | ||||||||||||||||||||||||
| 789 | of the glyphs. But since the horizontal metrics of the glyphs are unhinted, the text's | - | ||||||||||||||||||||||||
| 790 | layout will be scalable to higher density devices (such as printers) without impacting | - | ||||||||||||||||||||||||
| 791 | details such as line breaks. | - | ||||||||||||||||||||||||
| 792 | \value PreferFullHinting If possible, render text with hinting in both horizontal and | - | ||||||||||||||||||||||||
| 793 | vertical directions. The text will be altered to optimize legibility on the target | - | ||||||||||||||||||||||||
| 794 | device, but since the metrics will depend on the target size of the text, the positions | - | ||||||||||||||||||||||||
| 795 | of glyphs, line breaks, and other typographical detail will not scale, meaning that a | - | ||||||||||||||||||||||||
| 796 | text layout may look different on devices with different pixel densities. | - | ||||||||||||||||||||||||
| 797 | - | |||||||||||||||||||||||||
| 798 | Please note that this enum only describes a preference, as the full range of hinting levels | - | ||||||||||||||||||||||||
| 799 | are not supported on all of Qt's supported platforms. The following table details the effect | - | ||||||||||||||||||||||||
| 800 | of a given hinting preference on a selected set of target platforms. | - | ||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||
| 802 | \table | - | ||||||||||||||||||||||||
| 803 | \header | - | ||||||||||||||||||||||||
| 804 | \li | - | ||||||||||||||||||||||||
| 805 | \li PreferDefaultHinting | - | ||||||||||||||||||||||||
| 806 | \li PreferNoHinting | - | ||||||||||||||||||||||||
| 807 | \li PreferVerticalHinting | - | ||||||||||||||||||||||||
| 808 | \li PreferFullHinting | - | ||||||||||||||||||||||||
| 809 | \row | - | ||||||||||||||||||||||||
| 810 | \li Windows Vista (w/o Platform Update) and earlier | - | ||||||||||||||||||||||||
| 811 | \li Full hinting | - | ||||||||||||||||||||||||
| 812 | \li Full hinting | - | ||||||||||||||||||||||||
| 813 | \li Full hinting | - | ||||||||||||||||||||||||
| 814 | \li Full hinting | - | ||||||||||||||||||||||||
| 815 | \row | - | ||||||||||||||||||||||||
| 816 | \li Windows 7 and Windows Vista (w/Platform Update) and DirectWrite enabled in Qt | - | ||||||||||||||||||||||||
| 817 | \li Full hinting | - | ||||||||||||||||||||||||
| 818 | \li Vertical hinting | - | ||||||||||||||||||||||||
| 819 | \li Vertical hinting | - | ||||||||||||||||||||||||
| 820 | \li Full hinting | - | ||||||||||||||||||||||||
| 821 | \row | - | ||||||||||||||||||||||||
| 822 | \li FreeType | - | ||||||||||||||||||||||||
| 823 | \li Operating System setting | - | ||||||||||||||||||||||||
| 824 | \li No hinting | - | ||||||||||||||||||||||||
| 825 | \li Vertical hinting (light) | - | ||||||||||||||||||||||||
| 826 | \li Full hinting | - | ||||||||||||||||||||||||
| 827 | \row | - | ||||||||||||||||||||||||
| 828 | \li Cocoa on \macos | - | ||||||||||||||||||||||||
| 829 | \li No hinting | - | ||||||||||||||||||||||||
| 830 | \li No hinting | - | ||||||||||||||||||||||||
| 831 | \li No hinting | - | ||||||||||||||||||||||||
| 832 | \li No hinting | - | ||||||||||||||||||||||||
| 833 | \endtable | - | ||||||||||||||||||||||||
| 834 | - | |||||||||||||||||||||||||
| 835 | \note Please be aware that altering the hinting preference on Windows is available through | - | ||||||||||||||||||||||||
| 836 | the DirectWrite font engine. This is available on Windows Vista after installing the platform | - | ||||||||||||||||||||||||
| 837 | update, and on Windows 7. In order to use this extension, configure Qt using -directwrite. | - | ||||||||||||||||||||||||
| 838 | The target application will then depend on the availability of DirectWrite on the target | - | ||||||||||||||||||||||||
| 839 | system. | - | ||||||||||||||||||||||||
| 840 | - | |||||||||||||||||||||||||
| 841 | */ | - | ||||||||||||||||||||||||
| 842 | - | |||||||||||||||||||||||||
| 843 | /*! | - | ||||||||||||||||||||||||
| 844 | \since 4.8 | - | ||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||
| 846 | Set the preference for the hinting level of the glyphs to \a hintingPreference. This is a hint | - | ||||||||||||||||||||||||
| 847 | to the underlying font rendering system to use a certain level of hinting, and has varying | - | ||||||||||||||||||||||||
| 848 | support across platforms. See the table in the documentation for QFont::HintingPreference for | - | ||||||||||||||||||||||||
| 849 | more details. | - | ||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||
| 851 | The default hinting preference is QFont::PreferDefaultHinting. | - | ||||||||||||||||||||||||
| 852 | */ | - | ||||||||||||||||||||||||
| 853 | void QFont::setHintingPreference(HintingPreference hintingPreference) | - | ||||||||||||||||||||||||
| 854 | { | - | ||||||||||||||||||||||||
| 855 | if ((resolve_mask & QFont::HintingPreferenceResolved) && d->request.hintingPreference == hintingPreference) | - | ||||||||||||||||||||||||
| 856 | return; | - | ||||||||||||||||||||||||
| 857 | - | |||||||||||||||||||||||||
| 858 | detach(); | - | ||||||||||||||||||||||||
| 859 | - | |||||||||||||||||||||||||
| 860 | d->request.hintingPreference = hintingPreference; | - | ||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||
| 862 | resolve_mask |= QFont::HintingPreferenceResolved; | - | ||||||||||||||||||||||||
| 863 | } | - | ||||||||||||||||||||||||
| 864 | - | |||||||||||||||||||||||||
| 865 | /*! | - | ||||||||||||||||||||||||
| 866 | \since 4.8 | - | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | Returns the currently preferred hinting level for glyphs rendered with this font. | - | ||||||||||||||||||||||||
| 869 | */ | - | ||||||||||||||||||||||||
| 870 | QFont::HintingPreference QFont::hintingPreference() const | - | ||||||||||||||||||||||||
| 871 | { | - | ||||||||||||||||||||||||
| 872 | return QFont::HintingPreference(d->request.hintingPreference); | - | ||||||||||||||||||||||||
| 873 | } | - | ||||||||||||||||||||||||
| 874 | - | |||||||||||||||||||||||||
| 875 | /*! | - | ||||||||||||||||||||||||
| 876 | Sets the point size to \a pointSize. The point size must be | - | ||||||||||||||||||||||||
| 877 | greater than zero. | - | ||||||||||||||||||||||||
| 878 | - | |||||||||||||||||||||||||
| 879 | \sa pointSize(), setPointSizeF() | - | ||||||||||||||||||||||||
| 880 | */ | - | ||||||||||||||||||||||||
| 881 | void QFont::setPointSize(int pointSize) | - | ||||||||||||||||||||||||
| 882 | { | - | ||||||||||||||||||||||||
| 883 | if (pointSize <= 0) { | - | ||||||||||||||||||||||||
| 884 | qWarning("QFont::setPointSize: Point size <= 0 (%d), must be greater than 0", pointSize); | - | ||||||||||||||||||||||||
| 885 | return; | - | ||||||||||||||||||||||||
| 886 | } | - | ||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | if ((resolve_mask & QFont::SizeResolved) && d->request.pointSize == qreal(pointSize)) | - | ||||||||||||||||||||||||
| 889 | return; | - | ||||||||||||||||||||||||
| 890 | - | |||||||||||||||||||||||||
| 891 | detach(); | - | ||||||||||||||||||||||||
| 892 | - | |||||||||||||||||||||||||
| 893 | d->request.pointSize = qreal(pointSize); | - | ||||||||||||||||||||||||
| 894 | d->request.pixelSize = -1; | - | ||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||
| 896 | resolve_mask |= QFont::SizeResolved; | - | ||||||||||||||||||||||||
| 897 | } | - | ||||||||||||||||||||||||
| 898 | - | |||||||||||||||||||||||||
| 899 | /*! | - | ||||||||||||||||||||||||
| 900 | Sets the point size to \a pointSize. The point size must be | - | ||||||||||||||||||||||||
| 901 | greater than zero. The requested precision may not be achieved on | - | ||||||||||||||||||||||||
| 902 | all platforms. | - | ||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||
| 904 | \sa pointSizeF(), setPointSize(), setPixelSize() | - | ||||||||||||||||||||||||
| 905 | */ | - | ||||||||||||||||||||||||
| 906 | void QFont::setPointSizeF(qreal pointSize) | - | ||||||||||||||||||||||||
| 907 | { | - | ||||||||||||||||||||||||
| 908 | if (pointSize <= 0) { | - | ||||||||||||||||||||||||
| 909 | qWarning("QFont::setPointSizeF: Point size <= 0 (%f), must be greater than 0", pointSize); | - | ||||||||||||||||||||||||
| 910 | return; | - | ||||||||||||||||||||||||
| 911 | } | - | ||||||||||||||||||||||||
| 912 | - | |||||||||||||||||||||||||
| 913 | if ((resolve_mask & QFont::SizeResolved) && d->request.pointSize == pointSize) | - | ||||||||||||||||||||||||
| 914 | return; | - | ||||||||||||||||||||||||
| 915 | - | |||||||||||||||||||||||||
| 916 | detach(); | - | ||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | d->request.pointSize = pointSize; | - | ||||||||||||||||||||||||
| 919 | d->request.pixelSize = -1; | - | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | resolve_mask |= QFont::SizeResolved; | - | ||||||||||||||||||||||||
| 922 | } | - | ||||||||||||||||||||||||
| 923 | - | |||||||||||||||||||||||||
| 924 | /*! | - | ||||||||||||||||||||||||
| 925 | Returns the point size of the font. Returns -1 if the font size was | - | ||||||||||||||||||||||||
| 926 | specified in pixels. | - | ||||||||||||||||||||||||
| 927 | - | |||||||||||||||||||||||||
| 928 | \sa pointSize(), setPointSizeF(), pixelSize(), QFontInfo::pointSize(), QFontInfo::pixelSize() | - | ||||||||||||||||||||||||
| 929 | */ | - | ||||||||||||||||||||||||
| 930 | qreal QFont::pointSizeF() const | - | ||||||||||||||||||||||||
| 931 | { | - | ||||||||||||||||||||||||
| 932 | return d->request.pointSize; | - | ||||||||||||||||||||||||
| 933 | } | - | ||||||||||||||||||||||||
| 934 | - | |||||||||||||||||||||||||
| 935 | /*! | - | ||||||||||||||||||||||||
| 936 | Sets the font size to \a pixelSize pixels. | - | ||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||
| 938 | Using this function makes the font device dependent. Use | - | ||||||||||||||||||||||||
| 939 | setPointSize() or setPointSizeF() to set the size of the font | - | ||||||||||||||||||||||||
| 940 | in a device independent manner. | - | ||||||||||||||||||||||||
| 941 | - | |||||||||||||||||||||||||
| 942 | \sa pixelSize() | - | ||||||||||||||||||||||||
| 943 | */ | - | ||||||||||||||||||||||||
| 944 | void QFont::setPixelSize(int pixelSize) | - | ||||||||||||||||||||||||
| 945 | { | - | ||||||||||||||||||||||||
| 946 | if (pixelSize <= 0) { | - | ||||||||||||||||||||||||
| 947 | qWarning("QFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize); | - | ||||||||||||||||||||||||
| 948 | return; | - | ||||||||||||||||||||||||
| 949 | } | - | ||||||||||||||||||||||||
| 950 | - | |||||||||||||||||||||||||
| 951 | if ((resolve_mask & QFont::SizeResolved) && d->request.pixelSize == qreal(pixelSize)) | - | ||||||||||||||||||||||||
| 952 | return; | - | ||||||||||||||||||||||||
| 953 | - | |||||||||||||||||||||||||
| 954 | detach(); | - | ||||||||||||||||||||||||
| 955 | - | |||||||||||||||||||||||||
| 956 | d->request.pixelSize = pixelSize; | - | ||||||||||||||||||||||||
| 957 | d->request.pointSize = -1; | - | ||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||
| 959 | resolve_mask |= QFont::SizeResolved; | - | ||||||||||||||||||||||||
| 960 | } | - | ||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||
| 962 | /*! | - | ||||||||||||||||||||||||
| 963 | Returns the pixel size of the font if it was set with | - | ||||||||||||||||||||||||
| 964 | setPixelSize(). Returns -1 if the size was set with setPointSize() | - | ||||||||||||||||||||||||
| 965 | or setPointSizeF(). | - | ||||||||||||||||||||||||
| 966 | - | |||||||||||||||||||||||||
| 967 | \sa setPixelSize(), pointSize(), QFontInfo::pointSize(), QFontInfo::pixelSize() | - | ||||||||||||||||||||||||
| 968 | */ | - | ||||||||||||||||||||||||
| 969 | int QFont::pixelSize() const | - | ||||||||||||||||||||||||
| 970 | { | - | ||||||||||||||||||||||||
| 971 | return d->request.pixelSize; | - | ||||||||||||||||||||||||
| 972 | } | - | ||||||||||||||||||||||||
| 973 | - | |||||||||||||||||||||||||
| 974 | /*! | - | ||||||||||||||||||||||||
| 975 | \fn bool QFont::italic() const | - | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | Returns \c true if the style() of the font is not QFont::StyleNormal | - | ||||||||||||||||||||||||
| 978 | - | |||||||||||||||||||||||||
| 979 | \sa setItalic(), style() | - | ||||||||||||||||||||||||
| 980 | */ | - | ||||||||||||||||||||||||
| 981 | - | |||||||||||||||||||||||||
| 982 | /*! | - | ||||||||||||||||||||||||
| 983 | \fn void QFont::setItalic(bool enable) | - | ||||||||||||||||||||||||
| 984 | - | |||||||||||||||||||||||||
| 985 | Sets the style() of the font to QFont::StyleItalic if \a enable is true; | - | ||||||||||||||||||||||||
| 986 | otherwise the style is set to QFont::StyleNormal. | - | ||||||||||||||||||||||||
| 987 | - | |||||||||||||||||||||||||
| 988 | \sa italic(), QFontInfo | - | ||||||||||||||||||||||||
| 989 | */ | - | ||||||||||||||||||||||||
| 990 | - | |||||||||||||||||||||||||
| 991 | /*! | - | ||||||||||||||||||||||||
| 992 | Returns the style of the font. | - | ||||||||||||||||||||||||
| 993 | - | |||||||||||||||||||||||||
| 994 | \sa setStyle() | - | ||||||||||||||||||||||||
| 995 | */ | - | ||||||||||||||||||||||||
| 996 | QFont::Style QFont::style() const | - | ||||||||||||||||||||||||
| 997 | { | - | ||||||||||||||||||||||||
| 998 | return (QFont::Style)d->request.style; | - | ||||||||||||||||||||||||
| 999 | } | - | ||||||||||||||||||||||||
| 1000 | - | |||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||
| 1002 | /*! | - | ||||||||||||||||||||||||
| 1003 | Sets the style of the font to \a style. | - | ||||||||||||||||||||||||
| 1004 | - | |||||||||||||||||||||||||
| 1005 | \sa italic(), QFontInfo | - | ||||||||||||||||||||||||
| 1006 | */ | - | ||||||||||||||||||||||||
| 1007 | void QFont::setStyle(Style style) | - | ||||||||||||||||||||||||
| 1008 | { | - | ||||||||||||||||||||||||
| 1009 | if ((resolve_mask & QFont::StyleResolved) && d->request.style == style) | - | ||||||||||||||||||||||||
| 1010 | return; | - | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | detach(); | - | ||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||
| 1014 | d->request.style = style; | - | ||||||||||||||||||||||||
| 1015 | resolve_mask |= QFont::StyleResolved; | - | ||||||||||||||||||||||||
| 1016 | } | - | ||||||||||||||||||||||||
| 1017 | - | |||||||||||||||||||||||||
| 1018 | /*! | - | ||||||||||||||||||||||||
| 1019 | Returns the weight of the font, using the same scale as the | - | ||||||||||||||||||||||||
| 1020 | \l{QFont::Weight} enumeration. | - | ||||||||||||||||||||||||
| 1021 | - | |||||||||||||||||||||||||
| 1022 | \sa setWeight(), Weight, QFontInfo | - | ||||||||||||||||||||||||
| 1023 | */ | - | ||||||||||||||||||||||||
| 1024 | int QFont::weight() const | - | ||||||||||||||||||||||||
| 1025 | { | - | ||||||||||||||||||||||||
| 1026 | return d->request.weight; | - | ||||||||||||||||||||||||
| 1027 | } | - | ||||||||||||||||||||||||
| 1028 | - | |||||||||||||||||||||||||
| 1029 | /*! | - | ||||||||||||||||||||||||
| 1030 | \enum QFont::Weight | - | ||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||
| 1032 | Qt uses a weighting scale from 0 to 99 similar to, but not the | - | ||||||||||||||||||||||||
| 1033 | same as, the scales used in Windows or CSS. A weight of 0 will be | - | ||||||||||||||||||||||||
| 1034 | thin, whilst 99 will be extremely black. | - | ||||||||||||||||||||||||
| 1035 | - | |||||||||||||||||||||||||
| 1036 | This enum contains the predefined font weights: | - | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | \value Thin 0 | - | ||||||||||||||||||||||||
| 1039 | \value ExtraLight 12 | - | ||||||||||||||||||||||||
| 1040 | \value Light 25 | - | ||||||||||||||||||||||||
| 1041 | \value Normal 50 | - | ||||||||||||||||||||||||
| 1042 | \value Medium 57 | - | ||||||||||||||||||||||||
| 1043 | \value DemiBold 63 | - | ||||||||||||||||||||||||
| 1044 | \value Bold 75 | - | ||||||||||||||||||||||||
| 1045 | \value ExtraBold 81 | - | ||||||||||||||||||||||||
| 1046 | \value Black 87 | - | ||||||||||||||||||||||||
| 1047 | */ | - | ||||||||||||||||||||||||
| 1048 | - | |||||||||||||||||||||||||
| 1049 | /*! | - | ||||||||||||||||||||||||
| 1050 | Sets the weight of the font to \a weight, using the scale defined by | - | ||||||||||||||||||||||||
| 1051 | \l QFont::Weight enumeration. | - | ||||||||||||||||||||||||
| 1052 | - | |||||||||||||||||||||||||
| 1053 | \sa weight(), QFontInfo | - | ||||||||||||||||||||||||
| 1054 | */ | - | ||||||||||||||||||||||||
| 1055 | void QFont::setWeight(int weight) | - | ||||||||||||||||||||||||
| 1056 | { | - | ||||||||||||||||||||||||
| 1057 | Q_ASSERT_X(weight >= 0 && weight <= 99, "QFont::setWeight", "Weight must be between 0 and 99"); | - | ||||||||||||||||||||||||
| 1058 | - | |||||||||||||||||||||||||
| 1059 | if ((resolve_mask & QFont::WeightResolved) && d->request.weight == weight) | - | ||||||||||||||||||||||||
| 1060 | return; | - | ||||||||||||||||||||||||
| 1061 | - | |||||||||||||||||||||||||
| 1062 | detach(); | - | ||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||
| 1064 | d->request.weight = weight; | - | ||||||||||||||||||||||||
| 1065 | resolve_mask |= QFont::WeightResolved; | - | ||||||||||||||||||||||||
| 1066 | } | - | ||||||||||||||||||||||||
| 1067 | - | |||||||||||||||||||||||||
| 1068 | /*! | - | ||||||||||||||||||||||||
| 1069 | \fn bool QFont::bold() const | - | ||||||||||||||||||||||||
| 1070 | - | |||||||||||||||||||||||||
| 1071 | Returns \c true if weight() is a value greater than | - | ||||||||||||||||||||||||
| 1072 | \l{Weight}{QFont::Medium}; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||
| 1074 | \sa weight(), setBold(), QFontInfo::bold() | - | ||||||||||||||||||||||||
| 1075 | */ | - | ||||||||||||||||||||||||
| 1076 | - | |||||||||||||||||||||||||
| 1077 | /*! | - | ||||||||||||||||||||||||
| 1078 | \fn void QFont::setBold(bool enable) | - | ||||||||||||||||||||||||
| 1079 | - | |||||||||||||||||||||||||
| 1080 | If \a enable is true sets the font's weight to | - | ||||||||||||||||||||||||
| 1081 | \l{Weight}{QFont::Bold}; | - | ||||||||||||||||||||||||
| 1082 | otherwise sets the weight to \l{Weight}{QFont::Normal}. | - | ||||||||||||||||||||||||
| 1083 | - | |||||||||||||||||||||||||
| 1084 | For finer boldness control use setWeight(). | - | ||||||||||||||||||||||||
| 1085 | - | |||||||||||||||||||||||||
| 1086 | \sa bold(), setWeight() | - | ||||||||||||||||||||||||
| 1087 | */ | - | ||||||||||||||||||||||||
| 1088 | - | |||||||||||||||||||||||||
| 1089 | /*! | - | ||||||||||||||||||||||||
| 1090 | Returns \c true if underline has been set; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1091 | - | |||||||||||||||||||||||||
| 1092 | \sa setUnderline() | - | ||||||||||||||||||||||||
| 1093 | */ | - | ||||||||||||||||||||||||
| 1094 | bool QFont::underline() const | - | ||||||||||||||||||||||||
| 1095 | { | - | ||||||||||||||||||||||||
| 1096 | return d->underline; | - | ||||||||||||||||||||||||
| 1097 | } | - | ||||||||||||||||||||||||
| 1098 | - | |||||||||||||||||||||||||
| 1099 | /*! | - | ||||||||||||||||||||||||
| 1100 | If \a enable is true, sets underline on; otherwise sets underline | - | ||||||||||||||||||||||||
| 1101 | off. | - | ||||||||||||||||||||||||
| 1102 | - | |||||||||||||||||||||||||
| 1103 | \sa underline(), QFontInfo | - | ||||||||||||||||||||||||
| 1104 | */ | - | ||||||||||||||||||||||||
| 1105 | void QFont::setUnderline(bool enable) | - | ||||||||||||||||||||||||
| 1106 | { | - | ||||||||||||||||||||||||
| 1107 | if ((resolve_mask & QFont::UnderlineResolved) && d->underline == enable) | - | ||||||||||||||||||||||||
| 1108 | return; | - | ||||||||||||||||||||||||
| 1109 | - | |||||||||||||||||||||||||
| 1110 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1111 | - | |||||||||||||||||||||||||
| 1112 | d->underline = enable; | - | ||||||||||||||||||||||||
| 1113 | resolve_mask |= QFont::UnderlineResolved; | - | ||||||||||||||||||||||||
| 1114 | } | - | ||||||||||||||||||||||||
| 1115 | - | |||||||||||||||||||||||||
| 1116 | /*! | - | ||||||||||||||||||||||||
| 1117 | Returns \c true if overline has been set; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||
| 1119 | \sa setOverline() | - | ||||||||||||||||||||||||
| 1120 | */ | - | ||||||||||||||||||||||||
| 1121 | bool QFont::overline() const | - | ||||||||||||||||||||||||
| 1122 | { | - | ||||||||||||||||||||||||
| 1123 | return d->overline; | - | ||||||||||||||||||||||||
| 1124 | } | - | ||||||||||||||||||||||||
| 1125 | - | |||||||||||||||||||||||||
| 1126 | /*! | - | ||||||||||||||||||||||||
| 1127 | If \a enable is true, sets overline on; otherwise sets overline off. | - | ||||||||||||||||||||||||
| 1128 | - | |||||||||||||||||||||||||
| 1129 | \sa overline(), QFontInfo | - | ||||||||||||||||||||||||
| 1130 | */ | - | ||||||||||||||||||||||||
| 1131 | void QFont::setOverline(bool enable) | - | ||||||||||||||||||||||||
| 1132 | { | - | ||||||||||||||||||||||||
| 1133 | if ((resolve_mask & QFont::OverlineResolved) && d->overline == enable) | - | ||||||||||||||||||||||||
| 1134 | return; | - | ||||||||||||||||||||||||
| 1135 | - | |||||||||||||||||||||||||
| 1136 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1137 | - | |||||||||||||||||||||||||
| 1138 | d->overline = enable; | - | ||||||||||||||||||||||||
| 1139 | resolve_mask |= QFont::OverlineResolved; | - | ||||||||||||||||||||||||
| 1140 | } | - | ||||||||||||||||||||||||
| 1141 | - | |||||||||||||||||||||||||
| 1142 | /*! | - | ||||||||||||||||||||||||
| 1143 | Returns \c true if strikeout has been set; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1144 | - | |||||||||||||||||||||||||
| 1145 | \sa setStrikeOut() | - | ||||||||||||||||||||||||
| 1146 | */ | - | ||||||||||||||||||||||||
| 1147 | bool QFont::strikeOut() const | - | ||||||||||||||||||||||||
| 1148 | { | - | ||||||||||||||||||||||||
| 1149 | return d->strikeOut; | - | ||||||||||||||||||||||||
| 1150 | } | - | ||||||||||||||||||||||||
| 1151 | - | |||||||||||||||||||||||||
| 1152 | /*! | - | ||||||||||||||||||||||||
| 1153 | If \a enable is true, sets strikeout on; otherwise sets strikeout | - | ||||||||||||||||||||||||
| 1154 | off. | - | ||||||||||||||||||||||||
| 1155 | - | |||||||||||||||||||||||||
| 1156 | \sa strikeOut(), QFontInfo | - | ||||||||||||||||||||||||
| 1157 | */ | - | ||||||||||||||||||||||||
| 1158 | void QFont::setStrikeOut(bool enable) | - | ||||||||||||||||||||||||
| 1159 | { | - | ||||||||||||||||||||||||
| 1160 | if ((resolve_mask & QFont::StrikeOutResolved) && d->strikeOut == enable) | - | ||||||||||||||||||||||||
| 1161 | return; | - | ||||||||||||||||||||||||
| 1162 | - | |||||||||||||||||||||||||
| 1163 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1164 | - | |||||||||||||||||||||||||
| 1165 | d->strikeOut = enable; | - | ||||||||||||||||||||||||
| 1166 | resolve_mask |= QFont::StrikeOutResolved; | - | ||||||||||||||||||||||||
| 1167 | } | - | ||||||||||||||||||||||||
| 1168 | - | |||||||||||||||||||||||||
| 1169 | /*! | - | ||||||||||||||||||||||||
| 1170 | Returns \c true if fixed pitch has been set; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||
| 1172 | \sa setFixedPitch(), QFontInfo::fixedPitch() | - | ||||||||||||||||||||||||
| 1173 | */ | - | ||||||||||||||||||||||||
| 1174 | bool QFont::fixedPitch() const | - | ||||||||||||||||||||||||
| 1175 | { | - | ||||||||||||||||||||||||
| 1176 | return d->request.fixedPitch; | - | ||||||||||||||||||||||||
| 1177 | } | - | ||||||||||||||||||||||||
| 1178 | - | |||||||||||||||||||||||||
| 1179 | /*! | - | ||||||||||||||||||||||||
| 1180 | If \a enable is true, sets fixed pitch on; otherwise sets fixed | - | ||||||||||||||||||||||||
| 1181 | pitch off. | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | \sa fixedPitch(), QFontInfo | - | ||||||||||||||||||||||||
| 1184 | */ | - | ||||||||||||||||||||||||
| 1185 | void QFont::setFixedPitch(bool enable) | - | ||||||||||||||||||||||||
| 1186 | { | - | ||||||||||||||||||||||||
| 1187 | if ((resolve_mask & QFont::FixedPitchResolved) && d->request.fixedPitch == enable) | - | ||||||||||||||||||||||||
| 1188 | return; | - | ||||||||||||||||||||||||
| 1189 | - | |||||||||||||||||||||||||
| 1190 | detach(); | - | ||||||||||||||||||||||||
| 1191 | - | |||||||||||||||||||||||||
| 1192 | d->request.fixedPitch = enable; | - | ||||||||||||||||||||||||
| 1193 | d->request.ignorePitch = false; | - | ||||||||||||||||||||||||
| 1194 | resolve_mask |= QFont::FixedPitchResolved; | - | ||||||||||||||||||||||||
| 1195 | } | - | ||||||||||||||||||||||||
| 1196 | - | |||||||||||||||||||||||||
| 1197 | /*! | - | ||||||||||||||||||||||||
| 1198 | Returns \c true if kerning should be used when drawing text with this font. | - | ||||||||||||||||||||||||
| 1199 | - | |||||||||||||||||||||||||
| 1200 | \sa setKerning() | - | ||||||||||||||||||||||||
| 1201 | */ | - | ||||||||||||||||||||||||
| 1202 | bool QFont::kerning() const | - | ||||||||||||||||||||||||
| 1203 | { | - | ||||||||||||||||||||||||
| 1204 | return d->kerning; | - | ||||||||||||||||||||||||
| 1205 | } | - | ||||||||||||||||||||||||
| 1206 | - | |||||||||||||||||||||||||
| 1207 | /*! | - | ||||||||||||||||||||||||
| 1208 | Enables kerning for this font if \a enable is true; otherwise | - | ||||||||||||||||||||||||
| 1209 | disables it. By default, kerning is enabled. | - | ||||||||||||||||||||||||
| 1210 | - | |||||||||||||||||||||||||
| 1211 | When kerning is enabled, glyph metrics do not add up anymore, | - | ||||||||||||||||||||||||
| 1212 | even for Latin text. In other words, the assumption that | - | ||||||||||||||||||||||||
| 1213 | width('a') + width('b') is equal to width("ab") is not | - | ||||||||||||||||||||||||
| 1214 | necessarily true. | - | ||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||
| 1216 | \sa kerning(), QFontMetrics | - | ||||||||||||||||||||||||
| 1217 | */ | - | ||||||||||||||||||||||||
| 1218 | void QFont::setKerning(bool enable) | - | ||||||||||||||||||||||||
| 1219 | { | - | ||||||||||||||||||||||||
| 1220 | if ((resolve_mask & QFont::KerningResolved) && d->kerning == enable) | - | ||||||||||||||||||||||||
| 1221 | return; | - | ||||||||||||||||||||||||
| 1222 | - | |||||||||||||||||||||||||
| 1223 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1224 | - | |||||||||||||||||||||||||
| 1225 | d->kerning = enable; | - | ||||||||||||||||||||||||
| 1226 | resolve_mask |= QFont::KerningResolved; | - | ||||||||||||||||||||||||
| 1227 | } | - | ||||||||||||||||||||||||
| 1228 | - | |||||||||||||||||||||||||
| 1229 | /*! | - | ||||||||||||||||||||||||
| 1230 | Returns the StyleStrategy. | - | ||||||||||||||||||||||||
| 1231 | - | |||||||||||||||||||||||||
| 1232 | The style strategy affects the \l{QFont}{font matching} algorithm. | - | ||||||||||||||||||||||||
| 1233 | See \l QFont::StyleStrategy for the list of available strategies. | - | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | \sa setStyleHint(), QFont::StyleHint | - | ||||||||||||||||||||||||
| 1236 | */ | - | ||||||||||||||||||||||||
| 1237 | QFont::StyleStrategy QFont::styleStrategy() const | - | ||||||||||||||||||||||||
| 1238 | { | - | ||||||||||||||||||||||||
| 1239 | return (StyleStrategy) d->request.styleStrategy; | - | ||||||||||||||||||||||||
| 1240 | } | - | ||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | /*! | - | ||||||||||||||||||||||||
| 1243 | Returns the StyleHint. | - | ||||||||||||||||||||||||
| 1244 | - | |||||||||||||||||||||||||
| 1245 | The style hint affects the \l{QFont}{font matching} algorithm. | - | ||||||||||||||||||||||||
| 1246 | See \l QFont::StyleHint for the list of available hints. | - | ||||||||||||||||||||||||
| 1247 | - | |||||||||||||||||||||||||
| 1248 | \sa setStyleHint(), QFont::StyleStrategy, QFontInfo::styleHint() | - | ||||||||||||||||||||||||
| 1249 | */ | - | ||||||||||||||||||||||||
| 1250 | QFont::StyleHint QFont::styleHint() const | - | ||||||||||||||||||||||||
| 1251 | { | - | ||||||||||||||||||||||||
| 1252 | return (StyleHint) d->request.styleHint; | - | ||||||||||||||||||||||||
| 1253 | } | - | ||||||||||||||||||||||||
| 1254 | - | |||||||||||||||||||||||||
| 1255 | /*! | - | ||||||||||||||||||||||||
| 1256 | \enum QFont::StyleHint | - | ||||||||||||||||||||||||
| 1257 | - | |||||||||||||||||||||||||
| 1258 | Style hints are used by the \l{QFont}{font matching} algorithm to | - | ||||||||||||||||||||||||
| 1259 | find an appropriate default family if a selected font family is | - | ||||||||||||||||||||||||
| 1260 | not available. | - | ||||||||||||||||||||||||
| 1261 | - | |||||||||||||||||||||||||
| 1262 | \value AnyStyle leaves the font matching algorithm to choose the | - | ||||||||||||||||||||||||
| 1263 | family. This is the default. | - | ||||||||||||||||||||||||
| 1264 | - | |||||||||||||||||||||||||
| 1265 | \value SansSerif the font matcher prefer sans serif fonts. | - | ||||||||||||||||||||||||
| 1266 | \value Helvetica is a synonym for \c SansSerif. | - | ||||||||||||||||||||||||
| 1267 | - | |||||||||||||||||||||||||
| 1268 | \value Serif the font matcher prefers serif fonts. | - | ||||||||||||||||||||||||
| 1269 | \value Times is a synonym for \c Serif. | - | ||||||||||||||||||||||||
| 1270 | - | |||||||||||||||||||||||||
| 1271 | \value TypeWriter the font matcher prefers fixed pitch fonts. | - | ||||||||||||||||||||||||
| 1272 | \value Courier a synonym for \c TypeWriter. | - | ||||||||||||||||||||||||
| 1273 | - | |||||||||||||||||||||||||
| 1274 | \value OldEnglish the font matcher prefers decorative fonts. | - | ||||||||||||||||||||||||
| 1275 | \value Decorative is a synonym for \c OldEnglish. | - | ||||||||||||||||||||||||
| 1276 | - | |||||||||||||||||||||||||
| 1277 | \value Monospace the font matcher prefers fonts that map to the | - | ||||||||||||||||||||||||
| 1278 | CSS generic font-family 'monospace'. | - | ||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||
| 1280 | \value Fantasy the font matcher prefers fonts that map to the | - | ||||||||||||||||||||||||
| 1281 | CSS generic font-family 'fantasy'. | - | ||||||||||||||||||||||||
| 1282 | - | |||||||||||||||||||||||||
| 1283 | \value Cursive the font matcher prefers fonts that map to the | - | ||||||||||||||||||||||||
| 1284 | CSS generic font-family 'cursive'. | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | \value System the font matcher prefers system fonts. | - | ||||||||||||||||||||||||
| 1287 | */ | - | ||||||||||||||||||||||||
| 1288 | - | |||||||||||||||||||||||||
| 1289 | /*! | - | ||||||||||||||||||||||||
| 1290 | \enum QFont::StyleStrategy | - | ||||||||||||||||||||||||
| 1291 | - | |||||||||||||||||||||||||
| 1292 | The style strategy tells the \l{QFont}{font matching} algorithm | - | ||||||||||||||||||||||||
| 1293 | what type of fonts should be used to find an appropriate default | - | ||||||||||||||||||||||||
| 1294 | family. | - | ||||||||||||||||||||||||
| 1295 | - | |||||||||||||||||||||||||
| 1296 | The following strategies are available: | - | ||||||||||||||||||||||||
| 1297 | - | |||||||||||||||||||||||||
| 1298 | \value PreferDefault the default style strategy. It does not prefer | - | ||||||||||||||||||||||||
| 1299 | any type of font. | - | ||||||||||||||||||||||||
| 1300 | \value PreferBitmap prefers bitmap fonts (as opposed to outline | - | ||||||||||||||||||||||||
| 1301 | fonts). | - | ||||||||||||||||||||||||
| 1302 | \value PreferDevice prefers device fonts. | - | ||||||||||||||||||||||||
| 1303 | \value PreferOutline prefers outline fonts (as opposed to bitmap fonts). | - | ||||||||||||||||||||||||
| 1304 | \value ForceOutline forces the use of outline fonts. | - | ||||||||||||||||||||||||
| 1305 | \value NoAntialias don't antialias the fonts. | - | ||||||||||||||||||||||||
| 1306 | \value NoSubpixelAntialias avoid subpixel antialiasing on the fonts if possible. | - | ||||||||||||||||||||||||
| 1307 | \value PreferAntialias antialias if possible. | - | ||||||||||||||||||||||||
| 1308 | \value OpenGLCompatible forces the use of OpenGL compatible | - | ||||||||||||||||||||||||
| 1309 | fonts. | - | ||||||||||||||||||||||||
| 1310 | \value NoFontMerging If the font selected for a certain writing system | - | ||||||||||||||||||||||||
| 1311 | does not contain a character requested to draw, then Qt automatically chooses a similar | - | ||||||||||||||||||||||||
| 1312 | looking font that contains the character. The NoFontMerging flag disables this feature. | - | ||||||||||||||||||||||||
| 1313 | Please note that enabling this flag will not prevent Qt from automatically picking a | - | ||||||||||||||||||||||||
| 1314 | suitable font when the selected font does not support the writing system of the text. | - | ||||||||||||||||||||||||
| 1315 | - | |||||||||||||||||||||||||
| 1316 | Any of these may be OR-ed with one of these flags: | - | ||||||||||||||||||||||||
| 1317 | - | |||||||||||||||||||||||||
| 1318 | \value PreferMatch prefer an exact match. The font matcher will try to | - | ||||||||||||||||||||||||
| 1319 | use the exact font size that has been specified. | - | ||||||||||||||||||||||||
| 1320 | \value PreferQuality prefer the best quality font. The font matcher | - | ||||||||||||||||||||||||
| 1321 | will use the nearest standard point size that the font | - | ||||||||||||||||||||||||
| 1322 | supports. | - | ||||||||||||||||||||||||
| 1323 | \value ForceIntegerMetrics forces the use of integer values in font engines that support fractional | - | ||||||||||||||||||||||||
| 1324 | font metrics. | - | ||||||||||||||||||||||||
| 1325 | */ | - | ||||||||||||||||||||||||
| 1326 | - | |||||||||||||||||||||||||
| 1327 | /*! | - | ||||||||||||||||||||||||
| 1328 | Sets the style hint and strategy to \a hint and \a strategy, | - | ||||||||||||||||||||||||
| 1329 | respectively. | - | ||||||||||||||||||||||||
| 1330 | - | |||||||||||||||||||||||||
| 1331 | If these aren't set explicitly the style hint will default to | - | ||||||||||||||||||||||||
| 1332 | \c AnyStyle and the style strategy to \c PreferDefault. | - | ||||||||||||||||||||||||
| 1333 | - | |||||||||||||||||||||||||
| 1334 | Qt does not support style hints on X11 since this information | - | ||||||||||||||||||||||||
| 1335 | is not provided by the window system. | - | ||||||||||||||||||||||||
| 1336 | - | |||||||||||||||||||||||||
| 1337 | \sa StyleHint, styleHint(), StyleStrategy, styleStrategy(), QFontInfo | - | ||||||||||||||||||||||||
| 1338 | */ | - | ||||||||||||||||||||||||
| 1339 | void QFont::setStyleHint(StyleHint hint, StyleStrategy strategy) | - | ||||||||||||||||||||||||
| 1340 | { | - | ||||||||||||||||||||||||
| 1341 | if ((resolve_mask & (QFont::StyleHintResolved | QFont::StyleStrategyResolved)) && | - | ||||||||||||||||||||||||
| 1342 | (StyleHint) d->request.styleHint == hint && | - | ||||||||||||||||||||||||
| 1343 | (StyleStrategy) d->request.styleStrategy == strategy) | - | ||||||||||||||||||||||||
| 1344 | return; | - | ||||||||||||||||||||||||
| 1345 | - | |||||||||||||||||||||||||
| 1346 | detach(); | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | d->request.styleHint = hint; | - | ||||||||||||||||||||||||
| 1349 | d->request.styleStrategy = strategy; | - | ||||||||||||||||||||||||
| 1350 | resolve_mask |= QFont::StyleHintResolved; | - | ||||||||||||||||||||||||
| 1351 | resolve_mask |= QFont::StyleStrategyResolved; | - | ||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||
| 1353 | } | - | ||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||
| 1355 | /*! | - | ||||||||||||||||||||||||
| 1356 | Sets the style strategy for the font to \a s. | - | ||||||||||||||||||||||||
| 1357 | - | |||||||||||||||||||||||||
| 1358 | \sa QFont::StyleStrategy | - | ||||||||||||||||||||||||
| 1359 | */ | - | ||||||||||||||||||||||||
| 1360 | void QFont::setStyleStrategy(StyleStrategy s) | - | ||||||||||||||||||||||||
| 1361 | { | - | ||||||||||||||||||||||||
| 1362 | if ((resolve_mask & QFont::StyleStrategyResolved) && | - | ||||||||||||||||||||||||
| 1363 | s == (StyleStrategy)d->request.styleStrategy) | - | ||||||||||||||||||||||||
| 1364 | return; | - | ||||||||||||||||||||||||
| 1365 | - | |||||||||||||||||||||||||
| 1366 | detach(); | - | ||||||||||||||||||||||||
| 1367 | - | |||||||||||||||||||||||||
| 1368 | d->request.styleStrategy = s; | - | ||||||||||||||||||||||||
| 1369 | resolve_mask |= QFont::StyleStrategyResolved; | - | ||||||||||||||||||||||||
| 1370 | } | - | ||||||||||||||||||||||||
| 1371 | - | |||||||||||||||||||||||||
| 1372 | - | |||||||||||||||||||||||||
| 1373 | /*! | - | ||||||||||||||||||||||||
| 1374 | \enum QFont::Stretch | - | ||||||||||||||||||||||||
| 1375 | - | |||||||||||||||||||||||||
| 1376 | Predefined stretch values that follow the CSS naming convention. The higher | - | ||||||||||||||||||||||||
| 1377 | the value, the more stretched the text is. | - | ||||||||||||||||||||||||
| 1378 | - | |||||||||||||||||||||||||
| 1379 | \value UltraCondensed 50 | - | ||||||||||||||||||||||||
| 1380 | \value ExtraCondensed 62 | - | ||||||||||||||||||||||||
| 1381 | \value Condensed 75 | - | ||||||||||||||||||||||||
| 1382 | \value SemiCondensed 87 | - | ||||||||||||||||||||||||
| 1383 | \value Unstretched 100 | - | ||||||||||||||||||||||||
| 1384 | \value SemiExpanded 112 | - | ||||||||||||||||||||||||
| 1385 | \value Expanded 125 | - | ||||||||||||||||||||||||
| 1386 | \value ExtraExpanded 150 | - | ||||||||||||||||||||||||
| 1387 | \value UltraExpanded 200 | - | ||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||
| 1389 | \sa setStretch(), stretch() | - | ||||||||||||||||||||||||
| 1390 | */ | - | ||||||||||||||||||||||||
| 1391 | - | |||||||||||||||||||||||||
| 1392 | /*! | - | ||||||||||||||||||||||||
| 1393 | Returns the stretch factor for the font. | - | ||||||||||||||||||||||||
| 1394 | - | |||||||||||||||||||||||||
| 1395 | \sa setStretch() | - | ||||||||||||||||||||||||
| 1396 | */ | - | ||||||||||||||||||||||||
| 1397 | int QFont::stretch() const | - | ||||||||||||||||||||||||
| 1398 | { | - | ||||||||||||||||||||||||
| 1399 | return d->request.stretch; | - | ||||||||||||||||||||||||
| 1400 | } | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | /*! | - | ||||||||||||||||||||||||
| 1403 | Sets the stretch factor for the font. | - | ||||||||||||||||||||||||
| 1404 | - | |||||||||||||||||||||||||
| 1405 | The stretch factor changes the width of all characters in the font | - | ||||||||||||||||||||||||
| 1406 | by \a factor percent. For example, setting \a factor to 150 | - | ||||||||||||||||||||||||
| 1407 | results in all characters in the font being 1.5 times (ie. 150%) | - | ||||||||||||||||||||||||
| 1408 | wider. The default stretch factor is 100. The minimum stretch | - | ||||||||||||||||||||||||
| 1409 | factor is 1, and the maximum stretch factor is 4000. | - | ||||||||||||||||||||||||
| 1410 | - | |||||||||||||||||||||||||
| 1411 | The stretch factor is only applied to outline fonts. The stretch | - | ||||||||||||||||||||||||
| 1412 | factor is ignored for bitmap fonts. | - | ||||||||||||||||||||||||
| 1413 | - | |||||||||||||||||||||||||
| 1414 | \sa stretch(), QFont::Stretch | - | ||||||||||||||||||||||||
| 1415 | */ | - | ||||||||||||||||||||||||
| 1416 | void QFont::setStretch(int factor) | - | ||||||||||||||||||||||||
| 1417 | { | - | ||||||||||||||||||||||||
| 1418 | if (factor < 1 || factor > 4000) { | - | ||||||||||||||||||||||||
| 1419 | qWarning("QFont::setStretch: Parameter '%d' out of range", factor); | - | ||||||||||||||||||||||||
| 1420 | return; | - | ||||||||||||||||||||||||
| 1421 | } | - | ||||||||||||||||||||||||
| 1422 | - | |||||||||||||||||||||||||
| 1423 | if ((resolve_mask & QFont::StretchResolved) && | - | ||||||||||||||||||||||||
| 1424 | d->request.stretch == (uint)factor) | - | ||||||||||||||||||||||||
| 1425 | return; | - | ||||||||||||||||||||||||
| 1426 | - | |||||||||||||||||||||||||
| 1427 | detach(); | - | ||||||||||||||||||||||||
| 1428 | - | |||||||||||||||||||||||||
| 1429 | d->request.stretch = (uint)factor; | - | ||||||||||||||||||||||||
| 1430 | resolve_mask |= QFont::StretchResolved; | - | ||||||||||||||||||||||||
| 1431 | } | - | ||||||||||||||||||||||||
| 1432 | - | |||||||||||||||||||||||||
| 1433 | /*! | - | ||||||||||||||||||||||||
| 1434 | \enum QFont::SpacingType | - | ||||||||||||||||||||||||
| 1435 | \since 4.4 | - | ||||||||||||||||||||||||
| 1436 | - | |||||||||||||||||||||||||
| 1437 | \value PercentageSpacing A value of 100 will keep the spacing unchanged; a value of 200 will enlarge the | - | ||||||||||||||||||||||||
| 1438 | spacing after a character by the width of the character itself. | - | ||||||||||||||||||||||||
| 1439 | \value AbsoluteSpacing A positive value increases the letter spacing by the corresponding pixels; a negative | - | ||||||||||||||||||||||||
| 1440 | value decreases the spacing. | - | ||||||||||||||||||||||||
| 1441 | */ | - | ||||||||||||||||||||||||
| 1442 | - | |||||||||||||||||||||||||
| 1443 | /*! | - | ||||||||||||||||||||||||
| 1444 | \since 4.4 | - | ||||||||||||||||||||||||
| 1445 | Returns the letter spacing for the font. | - | ||||||||||||||||||||||||
| 1446 | - | |||||||||||||||||||||||||
| 1447 | \sa setLetterSpacing(), letterSpacingType(), setWordSpacing() | - | ||||||||||||||||||||||||
| 1448 | */ | - | ||||||||||||||||||||||||
| 1449 | qreal QFont::letterSpacing() const | - | ||||||||||||||||||||||||
| 1450 | { | - | ||||||||||||||||||||||||
| 1451 | return d->letterSpacing.toReal(); | - | ||||||||||||||||||||||||
| 1452 | } | - | ||||||||||||||||||||||||
| 1453 | - | |||||||||||||||||||||||||
| 1454 | /*! | - | ||||||||||||||||||||||||
| 1455 | \since 4.4 | - | ||||||||||||||||||||||||
| 1456 | Sets the letter spacing for the font to \a spacing and the type | - | ||||||||||||||||||||||||
| 1457 | of spacing to \a type. | - | ||||||||||||||||||||||||
| 1458 | - | |||||||||||||||||||||||||
| 1459 | Letter spacing changes the default spacing between individual | - | ||||||||||||||||||||||||
| 1460 | letters in the font. The spacing between the letters can be | - | ||||||||||||||||||||||||
| 1461 | made smaller as well as larger either in percentage of the | - | ||||||||||||||||||||||||
| 1462 | character width or in pixels, depending on the selected spacing type. | - | ||||||||||||||||||||||||
| 1463 | - | |||||||||||||||||||||||||
| 1464 | \sa letterSpacing(), letterSpacingType(), setWordSpacing() | - | ||||||||||||||||||||||||
| 1465 | */ | - | ||||||||||||||||||||||||
| 1466 | void QFont::setLetterSpacing(SpacingType type, qreal spacing) | - | ||||||||||||||||||||||||
| 1467 | { | - | ||||||||||||||||||||||||
| 1468 | const QFixed newSpacing = QFixed::fromReal(spacing); | - | ||||||||||||||||||||||||
| 1469 | const bool absoluteSpacing = type == AbsoluteSpacing; | - | ||||||||||||||||||||||||
| 1470 | if ((resolve_mask & QFont::LetterSpacingResolved) && | - | ||||||||||||||||||||||||
| 1471 | d->letterSpacingIsAbsolute == absoluteSpacing && | - | ||||||||||||||||||||||||
| 1472 | d->letterSpacing == newSpacing) | - | ||||||||||||||||||||||||
| 1473 | return; | - | ||||||||||||||||||||||||
| 1474 | - | |||||||||||||||||||||||||
| 1475 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||
| 1477 | d->letterSpacing = newSpacing; | - | ||||||||||||||||||||||||
| 1478 | d->letterSpacingIsAbsolute = absoluteSpacing; | - | ||||||||||||||||||||||||
| 1479 | resolve_mask |= QFont::LetterSpacingResolved; | - | ||||||||||||||||||||||||
| 1480 | } | - | ||||||||||||||||||||||||
| 1481 | - | |||||||||||||||||||||||||
| 1482 | /*! | - | ||||||||||||||||||||||||
| 1483 | \since 4.4 | - | ||||||||||||||||||||||||
| 1484 | Returns the spacing type used for letter spacing. | - | ||||||||||||||||||||||||
| 1485 | - | |||||||||||||||||||||||||
| 1486 | \sa letterSpacing(), setLetterSpacing(), setWordSpacing() | - | ||||||||||||||||||||||||
| 1487 | */ | - | ||||||||||||||||||||||||
| 1488 | QFont::SpacingType QFont::letterSpacingType() const | - | ||||||||||||||||||||||||
| 1489 | { | - | ||||||||||||||||||||||||
| 1490 | return d->letterSpacingIsAbsolute ? AbsoluteSpacing : PercentageSpacing; | - | ||||||||||||||||||||||||
| 1491 | } | - | ||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||
| 1493 | /*! | - | ||||||||||||||||||||||||
| 1494 | \since 4.4 | - | ||||||||||||||||||||||||
| 1495 | Returns the word spacing for the font. | - | ||||||||||||||||||||||||
| 1496 | - | |||||||||||||||||||||||||
| 1497 | \sa setWordSpacing(), setLetterSpacing() | - | ||||||||||||||||||||||||
| 1498 | */ | - | ||||||||||||||||||||||||
| 1499 | qreal QFont::wordSpacing() const | - | ||||||||||||||||||||||||
| 1500 | { | - | ||||||||||||||||||||||||
| 1501 | return d->wordSpacing.toReal(); | - | ||||||||||||||||||||||||
| 1502 | } | - | ||||||||||||||||||||||||
| 1503 | - | |||||||||||||||||||||||||
| 1504 | /*! | - | ||||||||||||||||||||||||
| 1505 | \since 4.4 | - | ||||||||||||||||||||||||
| 1506 | Sets the word spacing for the font to \a spacing. | - | ||||||||||||||||||||||||
| 1507 | - | |||||||||||||||||||||||||
| 1508 | Word spacing changes the default spacing between individual | - | ||||||||||||||||||||||||
| 1509 | words. A positive value increases the word spacing | - | ||||||||||||||||||||||||
| 1510 | by a corresponding amount of pixels, while a negative value | - | ||||||||||||||||||||||||
| 1511 | decreases the inter-word spacing accordingly. | - | ||||||||||||||||||||||||
| 1512 | - | |||||||||||||||||||||||||
| 1513 | Word spacing will not apply to writing systems, where indiviaul | - | ||||||||||||||||||||||||
| 1514 | words are not separated by white space. | - | ||||||||||||||||||||||||
| 1515 | - | |||||||||||||||||||||||||
| 1516 | \sa wordSpacing(), setLetterSpacing() | - | ||||||||||||||||||||||||
| 1517 | */ | - | ||||||||||||||||||||||||
| 1518 | void QFont::setWordSpacing(qreal spacing) | - | ||||||||||||||||||||||||
| 1519 | { | - | ||||||||||||||||||||||||
| 1520 | const QFixed newSpacing = QFixed::fromReal(spacing); | - | ||||||||||||||||||||||||
| 1521 | if ((resolve_mask & QFont::WordSpacingResolved) && | - | ||||||||||||||||||||||||
| 1522 | d->wordSpacing == newSpacing) | - | ||||||||||||||||||||||||
| 1523 | return; | - | ||||||||||||||||||||||||
| 1524 | - | |||||||||||||||||||||||||
| 1525 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1526 | - | |||||||||||||||||||||||||
| 1527 | d->wordSpacing = newSpacing; | - | ||||||||||||||||||||||||
| 1528 | resolve_mask |= QFont::WordSpacingResolved; | - | ||||||||||||||||||||||||
| 1529 | } | - | ||||||||||||||||||||||||
| 1530 | - | |||||||||||||||||||||||||
| 1531 | /*! | - | ||||||||||||||||||||||||
| 1532 | \enum QFont::Capitalization | - | ||||||||||||||||||||||||
| 1533 | \since 4.4 | - | ||||||||||||||||||||||||
| 1534 | - | |||||||||||||||||||||||||
| 1535 | Rendering option for text this font applies to. | - | ||||||||||||||||||||||||
| 1536 | - | |||||||||||||||||||||||||
| 1537 | - | |||||||||||||||||||||||||
| 1538 | \value MixedCase This is the normal text rendering option where no capitalization change is applied. | - | ||||||||||||||||||||||||
| 1539 | \value AllUppercase This alters the text to be rendered in all uppercase type. | - | ||||||||||||||||||||||||
| 1540 | \value AllLowercase This alters the text to be rendered in all lowercase type. | - | ||||||||||||||||||||||||
| 1541 | \value SmallCaps This alters the text to be rendered in small-caps type. | - | ||||||||||||||||||||||||
| 1542 | \value Capitalize This alters the text to be rendered with the first character of each word as an uppercase character. | - | ||||||||||||||||||||||||
| 1543 | */ | - | ||||||||||||||||||||||||
| 1544 | - | |||||||||||||||||||||||||
| 1545 | /*! | - | ||||||||||||||||||||||||
| 1546 | \since 4.4 | - | ||||||||||||||||||||||||
| 1547 | Sets the capitalization of the text in this font to \a caps. | - | ||||||||||||||||||||||||
| 1548 | - | |||||||||||||||||||||||||
| 1549 | A font's capitalization makes the text appear in the selected capitalization mode. | - | ||||||||||||||||||||||||
| 1550 | - | |||||||||||||||||||||||||
| 1551 | \sa capitalization() | - | ||||||||||||||||||||||||
| 1552 | */ | - | ||||||||||||||||||||||||
| 1553 | void QFont::setCapitalization(Capitalization caps) | - | ||||||||||||||||||||||||
| 1554 | { | - | ||||||||||||||||||||||||
| 1555 | if ((resolve_mask & QFont::CapitalizationResolved) && | - | ||||||||||||||||||||||||
| 1556 | capitalization() == caps) | - | ||||||||||||||||||||||||
| 1557 | return; | - | ||||||||||||||||||||||||
| 1558 | - | |||||||||||||||||||||||||
| 1559 | QFontPrivate::detachButKeepEngineData(this); | - | ||||||||||||||||||||||||
| 1560 | - | |||||||||||||||||||||||||
| 1561 | d->capital = caps; | - | ||||||||||||||||||||||||
| 1562 | resolve_mask |= QFont::CapitalizationResolved; | - | ||||||||||||||||||||||||
| 1563 | } | - | ||||||||||||||||||||||||
| 1564 | - | |||||||||||||||||||||||||
| 1565 | /*! | - | ||||||||||||||||||||||||
| 1566 | \since 4.4 | - | ||||||||||||||||||||||||
| 1567 | Returns the current capitalization type of the font. | - | ||||||||||||||||||||||||
| 1568 | - | |||||||||||||||||||||||||
| 1569 | \sa setCapitalization() | - | ||||||||||||||||||||||||
| 1570 | */ | - | ||||||||||||||||||||||||
| 1571 | QFont::Capitalization QFont::capitalization() const | - | ||||||||||||||||||||||||
| 1572 | { | - | ||||||||||||||||||||||||
| 1573 | return static_cast<QFont::Capitalization> (d->capital); | - | ||||||||||||||||||||||||
| 1574 | } | - | ||||||||||||||||||||||||
| 1575 | - | |||||||||||||||||||||||||
| 1576 | #if QT_DEPRECATED_SINCE(5, 5) | - | ||||||||||||||||||||||||
| 1577 | /*! | - | ||||||||||||||||||||||||
| 1578 | \fn void QFont::setRawMode(bool enable) | - | ||||||||||||||||||||||||
| 1579 | \deprecated | - | ||||||||||||||||||||||||
| 1580 | - | |||||||||||||||||||||||||
| 1581 | If \a enable is true, turns raw mode on; otherwise turns raw mode | - | ||||||||||||||||||||||||
| 1582 | off. This function only has an effect under X11. | - | ||||||||||||||||||||||||
| 1583 | - | |||||||||||||||||||||||||
| 1584 | If raw mode is enabled, Qt will search for an X font with a | - | ||||||||||||||||||||||||
| 1585 | complete font name matching the family name, ignoring all other | - | ||||||||||||||||||||||||
| 1586 | values set for the QFont. If the font name matches several fonts, | - | ||||||||||||||||||||||||
| 1587 | Qt will use the first font returned by X. QFontInfo \e cannot be | - | ||||||||||||||||||||||||
| 1588 | used to fetch information about a QFont using raw mode (it will | - | ||||||||||||||||||||||||
| 1589 | return the values set in the QFont for all parameters, including | - | ||||||||||||||||||||||||
| 1590 | the family name). | - | ||||||||||||||||||||||||
| 1591 | - | |||||||||||||||||||||||||
| 1592 | \warning Enabling raw mode has no effect since Qt 5.0. | - | ||||||||||||||||||||||||
| 1593 | - | |||||||||||||||||||||||||
| 1594 | \sa rawMode() | - | ||||||||||||||||||||||||
| 1595 | */ | - | ||||||||||||||||||||||||
| 1596 | void QFont::setRawMode(bool) | - | ||||||||||||||||||||||||
| 1597 | { | - | ||||||||||||||||||||||||
| 1598 | } | - | ||||||||||||||||||||||||
| 1599 | #endif | - | ||||||||||||||||||||||||
| 1600 | - | |||||||||||||||||||||||||
| 1601 | /*! | - | ||||||||||||||||||||||||
| 1602 | Returns \c true if a window system font exactly matching the settings | - | ||||||||||||||||||||||||
| 1603 | of this font is available. | - | ||||||||||||||||||||||||
| 1604 | - | |||||||||||||||||||||||||
| 1605 | \sa QFontInfo | - | ||||||||||||||||||||||||
| 1606 | */ | - | ||||||||||||||||||||||||
| 1607 | bool QFont::exactMatch() const | - | ||||||||||||||||||||||||
| 1608 | { | - | ||||||||||||||||||||||||
| 1609 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 1610 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 1611 | return d->request.exactMatch(engine->fontDef); | - | ||||||||||||||||||||||||
| 1612 | } | - | ||||||||||||||||||||||||
| 1613 | - | |||||||||||||||||||||||||
| 1614 | /*! | - | ||||||||||||||||||||||||
| 1615 | Returns \c true if this font is equal to \a f; otherwise returns | - | ||||||||||||||||||||||||
| 1616 | false. | - | ||||||||||||||||||||||||
| 1617 | - | |||||||||||||||||||||||||
| 1618 | Two QFonts are considered equal if their font attributes are | - | ||||||||||||||||||||||||
| 1619 | equal. | - | ||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||
| 1621 | \sa operator!=(), isCopyOf() | - | ||||||||||||||||||||||||
| 1622 | */ | - | ||||||||||||||||||||||||
| 1623 | bool QFont::operator==(const QFont &f) const | - | ||||||||||||||||||||||||
| 1624 | { | - | ||||||||||||||||||||||||
| 1625 | return (f.d == d | - | ||||||||||||||||||||||||
| 1626 | || (f.d->request == d->request | - | ||||||||||||||||||||||||
| 1627 | && f.d->request.pointSize == d->request.pointSize | - | ||||||||||||||||||||||||
| 1628 | && f.d->underline == d->underline | - | ||||||||||||||||||||||||
| 1629 | && f.d->overline == d->overline | - | ||||||||||||||||||||||||
| 1630 | && f.d->strikeOut == d->strikeOut | - | ||||||||||||||||||||||||
| 1631 | && f.d->kerning == d->kerning | - | ||||||||||||||||||||||||
| 1632 | && f.d->capital == d->capital | - | ||||||||||||||||||||||||
| 1633 | && f.d->letterSpacingIsAbsolute == d->letterSpacingIsAbsolute | - | ||||||||||||||||||||||||
| 1634 | && f.d->letterSpacing == d->letterSpacing | - | ||||||||||||||||||||||||
| 1635 | && f.d->wordSpacing == d->wordSpacing | - | ||||||||||||||||||||||||
| 1636 | )); | - | ||||||||||||||||||||||||
| 1637 | } | - | ||||||||||||||||||||||||
| 1638 | - | |||||||||||||||||||||||||
| 1639 | - | |||||||||||||||||||||||||
| 1640 | /*! | - | ||||||||||||||||||||||||
| 1641 | Provides an arbitrary comparison of this font and font \a f. | - | ||||||||||||||||||||||||
| 1642 | All that is guaranteed is that the operator returns \c false if both | - | ||||||||||||||||||||||||
| 1643 | fonts are equal and that (f1 \< f2) == !(f2 \< f1) if the fonts | - | ||||||||||||||||||||||||
| 1644 | are not equal. | - | ||||||||||||||||||||||||
| 1645 | - | |||||||||||||||||||||||||
| 1646 | This function is useful in some circumstances, for example if you | - | ||||||||||||||||||||||||
| 1647 | want to use QFont objects as keys in a QMap. | - | ||||||||||||||||||||||||
| 1648 | - | |||||||||||||||||||||||||
| 1649 | \sa operator==(), operator!=(), isCopyOf() | - | ||||||||||||||||||||||||
| 1650 | */ | - | ||||||||||||||||||||||||
| 1651 | bool QFont::operator<(const QFont &f) const | - | ||||||||||||||||||||||||
| 1652 | { | - | ||||||||||||||||||||||||
| 1653 | if (f.d == d) return false; never executed: return false;
| 0 | ||||||||||||||||||||||||
| 1654 | // the < operator for fontdefs ignores point sizes. | - | ||||||||||||||||||||||||
| 1655 | const QFontDef &r1 = f.d->request; | - | ||||||||||||||||||||||||
| 1656 | const QFontDef &r2 = d->request; | - | ||||||||||||||||||||||||
| 1657 | if (r1.pointSize != r2.pointSize) return r1.pointSize < r2.pointSize; never executed: return r1.pointSize < r2.pointSize;
| 0 | ||||||||||||||||||||||||
| 1658 | if (r1.pixelSize != r2.pixelSize) return r1.pixelSize < r2.pixelSize; never executed: return r1.pixelSize < r2.pixelSize;
| 0 | ||||||||||||||||||||||||
| 1659 | if (r1.weight != r2.weight) return r1.weight < r2.weight; never executed: return r1.weight < r2.weight;
| 0 | ||||||||||||||||||||||||
| 1660 | if (r1.style != r2.style) return r1.style < r2.style; never executed: return r1.style < r2.style;
| 0 | ||||||||||||||||||||||||
| 1661 | if (r1.stretch != r2.stretch) return r1.stretch < r2.stretch; never executed: return r1.stretch < r2.stretch;
| 0 | ||||||||||||||||||||||||
| 1662 | if (r1.styleHint != r2.styleHint) return r1.styleHint < r2.styleHint; never executed: return r1.styleHint < r2.styleHint;
| 0 | ||||||||||||||||||||||||
| 1663 | if (r1.styleStrategy != r2.styleStrategy) return r1.styleStrategy < r2.styleStrategy; never executed: return r1.styleStrategy < r2.styleStrategy;
| 0 | ||||||||||||||||||||||||
| 1664 | if (r1.family != r2.family) return r1.family < r2.family; never executed: return r1.family < r2.family;
| 0 | ||||||||||||||||||||||||
| 1665 | if (f.d->capital != d->capital) return f.d->capital < d->capital; never executed: return f.d->capital < d->capital;
| 0 | ||||||||||||||||||||||||
| 1666 | - | |||||||||||||||||||||||||
| 1667 | if (f.d->letterSpacingIsAbsolute != d->letterSpacingIsAbsolute) return f.d->letterSpacingIsAbsolute < d->letterSpacingIsAbsolute; never executed: return f.d->letterSpacingIsAbsolute < d->letterSpacingIsAbsolute;
| 0 | ||||||||||||||||||||||||
| 1668 | if (f.d->letterSpacing != d->letterSpacing) return f.d->letterSpacing < d->letterSpacing; never executed: return f.d->letterSpacing < d->letterSpacing;
| 0 | ||||||||||||||||||||||||
| 1669 | if (f.d->wordSpacing != d->wordSpacing) return f.d->wordSpacing < d->wordSpacing; never executed: return f.d->wordSpacing < d->wordSpacing;
| 0 | ||||||||||||||||||||||||
| 1670 | - | |||||||||||||||||||||||||
| 1671 | int f1attrs = (f.d->underline << 3) + (f.d->overline << 2) + (f.d->strikeOut<<1) + f.d->kerning; | - | ||||||||||||||||||||||||
| 1672 | int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning; | - | ||||||||||||||||||||||||
| 1673 | return f1attrs < f2attrs; never executed: return f1attrs < f2attrs; | 0 | ||||||||||||||||||||||||
| 1674 | } | - | ||||||||||||||||||||||||
| 1675 | - | |||||||||||||||||||||||||
| 1676 | - | |||||||||||||||||||||||||
| 1677 | /*! | - | ||||||||||||||||||||||||
| 1678 | Returns \c true if this font is different from \a f; otherwise | - | ||||||||||||||||||||||||
| 1679 | returns \c false. | - | ||||||||||||||||||||||||
| 1680 | - | |||||||||||||||||||||||||
| 1681 | Two QFonts are considered to be different if their font attributes | - | ||||||||||||||||||||||||
| 1682 | are different. | - | ||||||||||||||||||||||||
| 1683 | - | |||||||||||||||||||||||||
| 1684 | \sa operator==() | - | ||||||||||||||||||||||||
| 1685 | */ | - | ||||||||||||||||||||||||
| 1686 | bool QFont::operator!=(const QFont &f) const | - | ||||||||||||||||||||||||
| 1687 | { | - | ||||||||||||||||||||||||
| 1688 | return !(operator==(f)); | - | ||||||||||||||||||||||||
| 1689 | } | - | ||||||||||||||||||||||||
| 1690 | - | |||||||||||||||||||||||||
| 1691 | /*! | - | ||||||||||||||||||||||||
| 1692 | Returns the font as a QVariant | - | ||||||||||||||||||||||||
| 1693 | */ | - | ||||||||||||||||||||||||
| 1694 | QFont::operator QVariant() const | - | ||||||||||||||||||||||||
| 1695 | { | - | ||||||||||||||||||||||||
| 1696 | return QVariant(QVariant::Font, this); | - | ||||||||||||||||||||||||
| 1697 | } | - | ||||||||||||||||||||||||
| 1698 | - | |||||||||||||||||||||||||
| 1699 | /*! | - | ||||||||||||||||||||||||
| 1700 | Returns \c true if this font and \a f are copies of each other, i.e. | - | ||||||||||||||||||||||||
| 1701 | one of them was created as a copy of the other and neither has | - | ||||||||||||||||||||||||
| 1702 | been modified since. This is much stricter than equality. | - | ||||||||||||||||||||||||
| 1703 | - | |||||||||||||||||||||||||
| 1704 | \sa operator=(), operator==() | - | ||||||||||||||||||||||||
| 1705 | */ | - | ||||||||||||||||||||||||
| 1706 | bool QFont::isCopyOf(const QFont & f) const | - | ||||||||||||||||||||||||
| 1707 | { | - | ||||||||||||||||||||||||
| 1708 | return d == f.d; | - | ||||||||||||||||||||||||
| 1709 | } | - | ||||||||||||||||||||||||
| 1710 | - | |||||||||||||||||||||||||
| 1711 | #if QT_DEPRECATED_SINCE(5, 5) | - | ||||||||||||||||||||||||
| 1712 | /*! | - | ||||||||||||||||||||||||
| 1713 | \deprecated | - | ||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | Returns \c true if raw mode is used for font name matching; otherwise | - | ||||||||||||||||||||||||
| 1716 | returns \c false. | - | ||||||||||||||||||||||||
| 1717 | - | |||||||||||||||||||||||||
| 1718 | \sa setRawMode() | - | ||||||||||||||||||||||||
| 1719 | */ | - | ||||||||||||||||||||||||
| 1720 | bool QFont::rawMode() const | - | ||||||||||||||||||||||||
| 1721 | { | - | ||||||||||||||||||||||||
| 1722 | return false; | - | ||||||||||||||||||||||||
| 1723 | } | - | ||||||||||||||||||||||||
| 1724 | #endif | - | ||||||||||||||||||||||||
| 1725 | - | |||||||||||||||||||||||||
| 1726 | /*! | - | ||||||||||||||||||||||||
| 1727 | Returns a new QFont that has attributes copied from \a other that | - | ||||||||||||||||||||||||
| 1728 | have not been previously set on this font. | - | ||||||||||||||||||||||||
| 1729 | */ | - | ||||||||||||||||||||||||
| 1730 | QFont QFont::resolve(const QFont &other) const | - | ||||||||||||||||||||||||
| 1731 | { | - | ||||||||||||||||||||||||
| 1732 | if (resolve_mask == 0 || (resolve_mask == other.resolve_mask && *this == other)) { | - | ||||||||||||||||||||||||
| 1733 | QFont o(other); | - | ||||||||||||||||||||||||
| 1734 | o.resolve_mask = resolve_mask; | - | ||||||||||||||||||||||||
| 1735 | return o; | - | ||||||||||||||||||||||||
| 1736 | } | - | ||||||||||||||||||||||||
| 1737 | - | |||||||||||||||||||||||||
| 1738 | QFont font(*this); | - | ||||||||||||||||||||||||
| 1739 | font.detach(); | - | ||||||||||||||||||||||||
| 1740 | font.d->resolve(resolve_mask, other.d.data()); | - | ||||||||||||||||||||||||
| 1741 | - | |||||||||||||||||||||||||
| 1742 | return font; | - | ||||||||||||||||||||||||
| 1743 | } | - | ||||||||||||||||||||||||
| 1744 | - | |||||||||||||||||||||||||
| 1745 | /*! | - | ||||||||||||||||||||||||
| 1746 | \fn uint QFont::resolve() const | - | ||||||||||||||||||||||||
| 1747 | \internal | - | ||||||||||||||||||||||||
| 1748 | */ | - | ||||||||||||||||||||||||
| 1749 | - | |||||||||||||||||||||||||
| 1750 | /*! | - | ||||||||||||||||||||||||
| 1751 | \fn void QFont::resolve(uint mask) | - | ||||||||||||||||||||||||
| 1752 | \internal | - | ||||||||||||||||||||||||
| 1753 | */ | - | ||||||||||||||||||||||||
| 1754 | - | |||||||||||||||||||||||||
| 1755 | - | |||||||||||||||||||||||||
| 1756 | /***************************************************************************** | - | ||||||||||||||||||||||||
| 1757 | QFont substitution management | - | ||||||||||||||||||||||||
| 1758 | *****************************************************************************/ | - | ||||||||||||||||||||||||
| 1759 | - | |||||||||||||||||||||||||
| 1760 | typedef QHash<QString, QStringList> QFontSubst; | - | ||||||||||||||||||||||||
| 1761 | Q_GLOBAL_STATIC(QFontSubst, globalFontSubst) | - | ||||||||||||||||||||||||
| 1762 | - | |||||||||||||||||||||||||
| 1763 | /*! | - | ||||||||||||||||||||||||
| 1764 | Returns the first family name to be used whenever \a familyName is | - | ||||||||||||||||||||||||
| 1765 | specified. The lookup is case insensitive. | - | ||||||||||||||||||||||||
| 1766 | - | |||||||||||||||||||||||||
| 1767 | If there is no substitution for \a familyName, \a familyName is | - | ||||||||||||||||||||||||
| 1768 | returned. | - | ||||||||||||||||||||||||
| 1769 | - | |||||||||||||||||||||||||
| 1770 | To obtain a list of substitutions use substitutes(). | - | ||||||||||||||||||||||||
| 1771 | - | |||||||||||||||||||||||||
| 1772 | \sa setFamily(), insertSubstitutions(), insertSubstitution(), removeSubstitutions() | - | ||||||||||||||||||||||||
| 1773 | */ | - | ||||||||||||||||||||||||
| 1774 | QString QFont::substitute(const QString &familyName) | - | ||||||||||||||||||||||||
| 1775 | { | - | ||||||||||||||||||||||||
| 1776 | QFontSubst *fontSubst = globalFontSubst(); | - | ||||||||||||||||||||||||
| 1777 | Q_ASSERT(fontSubst != 0); | - | ||||||||||||||||||||||||
| 1778 | QFontSubst::ConstIterator it = fontSubst->constFind(familyName.toLower()); | - | ||||||||||||||||||||||||
| 1779 | if (it != fontSubst->constEnd() && !(*it).isEmpty()) | - | ||||||||||||||||||||||||
| 1780 | return (*it).first(); | - | ||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||
| 1782 | return familyName; | - | ||||||||||||||||||||||||
| 1783 | } | - | ||||||||||||||||||||||||
| 1784 | - | |||||||||||||||||||||||||
| 1785 | - | |||||||||||||||||||||||||
| 1786 | /*! | - | ||||||||||||||||||||||||
| 1787 | Returns a list of family names to be used whenever \a familyName | - | ||||||||||||||||||||||||
| 1788 | is specified. The lookup is case insensitive. | - | ||||||||||||||||||||||||
| 1789 | - | |||||||||||||||||||||||||
| 1790 | If there is no substitution for \a familyName, an empty list is | - | ||||||||||||||||||||||||
| 1791 | returned. | - | ||||||||||||||||||||||||
| 1792 | - | |||||||||||||||||||||||||
| 1793 | \sa substitute(), insertSubstitutions(), insertSubstitution(), removeSubstitutions() | - | ||||||||||||||||||||||||
| 1794 | */ | - | ||||||||||||||||||||||||
| 1795 | QStringList QFont::substitutes(const QString &familyName) | - | ||||||||||||||||||||||||
| 1796 | { | - | ||||||||||||||||||||||||
| 1797 | QFontSubst *fontSubst = globalFontSubst(); | - | ||||||||||||||||||||||||
| 1798 | Q_ASSERT(fontSubst != 0); | - | ||||||||||||||||||||||||
| 1799 | return fontSubst->value(familyName.toLower(), QStringList()); | - | ||||||||||||||||||||||||
| 1800 | } | - | ||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||
| 1802 | - | |||||||||||||||||||||||||
| 1803 | /*! | - | ||||||||||||||||||||||||
| 1804 | Inserts \a substituteName into the substitution | - | ||||||||||||||||||||||||
| 1805 | table for the family \a familyName. | - | ||||||||||||||||||||||||
| 1806 | - | |||||||||||||||||||||||||
| 1807 | \sa insertSubstitutions(), removeSubstitutions(), substitutions(), substitute(), substitutes() | - | ||||||||||||||||||||||||
| 1808 | */ | - | ||||||||||||||||||||||||
| 1809 | void QFont::insertSubstitution(const QString &familyName, | - | ||||||||||||||||||||||||
| 1810 | const QString &substituteName) | - | ||||||||||||||||||||||||
| 1811 | { | - | ||||||||||||||||||||||||
| 1812 | QFontSubst *fontSubst = globalFontSubst(); | - | ||||||||||||||||||||||||
| 1813 | Q_ASSERT(fontSubst != 0); | - | ||||||||||||||||||||||||
| 1814 | QStringList &list = (*fontSubst)[familyName.toLower()]; | - | ||||||||||||||||||||||||
| 1815 | QString s = substituteName.toLower(); | - | ||||||||||||||||||||||||
| 1816 | if (!list.contains(s)) | - | ||||||||||||||||||||||||
| 1817 | list.append(s); | - | ||||||||||||||||||||||||
| 1818 | } | - | ||||||||||||||||||||||||
| 1819 | - | |||||||||||||||||||||||||
| 1820 | - | |||||||||||||||||||||||||
| 1821 | /*! | - | ||||||||||||||||||||||||
| 1822 | Inserts the list of families \a substituteNames into the | - | ||||||||||||||||||||||||
| 1823 | substitution list for \a familyName. | - | ||||||||||||||||||||||||
| 1824 | - | |||||||||||||||||||||||||
| 1825 | \sa insertSubstitution(), removeSubstitutions(), substitutions(), substitute() | - | ||||||||||||||||||||||||
| 1826 | */ | - | ||||||||||||||||||||||||
| 1827 | void QFont::insertSubstitutions(const QString &familyName, | - | ||||||||||||||||||||||||
| 1828 | const QStringList &substituteNames) | - | ||||||||||||||||||||||||
| 1829 | { | - | ||||||||||||||||||||||||
| 1830 | QFontSubst *fontSubst = globalFontSubst(); | - | ||||||||||||||||||||||||
| 1831 | Q_ASSERT(fontSubst != 0); | - | ||||||||||||||||||||||||
| 1832 | QStringList &list = (*fontSubst)[familyName.toLower()]; | - | ||||||||||||||||||||||||
| 1833 | foreachfor (const QString &substituteName ,: substituteNames) { | - | ||||||||||||||||||||||||
| 1834 | const QString lowerSubstituteName = substituteName.toLower(); | - | ||||||||||||||||||||||||
| 1835 | if (!list.contains(lowerSubstituteName))
| 0 | ||||||||||||||||||||||||
| 1836 | list.append(lowerSubstituteName); never executed: list.append(lowerSubstituteName); | 0 | ||||||||||||||||||||||||
| 1837 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1838 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1839 | - | |||||||||||||||||||||||||
| 1840 | /*! | - | ||||||||||||||||||||||||
| 1841 | Removes all the substitutions for \a familyName. | - | ||||||||||||||||||||||||
| 1842 | - | |||||||||||||||||||||||||
| 1843 | \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute() | - | ||||||||||||||||||||||||
| 1844 | \since 5.0 | - | ||||||||||||||||||||||||
| 1845 | */ | - | ||||||||||||||||||||||||
| 1846 | void QFont::removeSubstitutions(const QString &familyName) | - | ||||||||||||||||||||||||
| 1847 | { | - | ||||||||||||||||||||||||
| 1848 | QFontSubst *fontSubst = globalFontSubst(); | - | ||||||||||||||||||||||||
| 1849 | Q_ASSERT(fontSubst != 0); | - | ||||||||||||||||||||||||
| 1850 | fontSubst->remove(familyName.toLower()); | - | ||||||||||||||||||||||||
| 1851 | } | - | ||||||||||||||||||||||||
| 1852 | - | |||||||||||||||||||||||||
| 1853 | /*! | - | ||||||||||||||||||||||||
| 1854 | \fn void QFont::removeSubstitution(const QString &familyName) | - | ||||||||||||||||||||||||
| 1855 | - | |||||||||||||||||||||||||
| 1856 | \obsolete | - | ||||||||||||||||||||||||
| 1857 | - | |||||||||||||||||||||||||
| 1858 | This function is deprecated. Use removeSubstitutions() instead. | - | ||||||||||||||||||||||||
| 1859 | */ | - | ||||||||||||||||||||||||
| 1860 | - | |||||||||||||||||||||||||
| 1861 | /*! | - | ||||||||||||||||||||||||
| 1862 | Returns a sorted list of substituted family names. | - | ||||||||||||||||||||||||
| 1863 | - | |||||||||||||||||||||||||
| 1864 | \sa insertSubstitution(), removeSubstitution(), substitute() | - | ||||||||||||||||||||||||
| 1865 | */ | - | ||||||||||||||||||||||||
| 1866 | QStringList QFont::substitutions() | - | ||||||||||||||||||||||||
| 1867 | { | - | ||||||||||||||||||||||||
| 1868 | QFontSubst *fontSubst = globalFontSubst(); | - | ||||||||||||||||||||||||
| 1869 | Q_ASSERT(fontSubst != 0); | - | ||||||||||||||||||||||||
| 1870 | QStringList ret = fontSubst->keys(); | - | ||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||
| 1872 | ret.sort(); | - | ||||||||||||||||||||||||
| 1873 | return ret; | - | ||||||||||||||||||||||||
| 1874 | } | - | ||||||||||||||||||||||||
| 1875 | - | |||||||||||||||||||||||||
| 1876 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 1877 | /* \internal | - | ||||||||||||||||||||||||
| 1878 | Internal function. Converts boolean font settings to an unsigned | - | ||||||||||||||||||||||||
| 1879 | 8-bit number. Used for serialization etc. | - | ||||||||||||||||||||||||
| 1880 | */ | - | ||||||||||||||||||||||||
| 1881 | static quint8 get_font_bits(int version, const QFontPrivate *f) | - | ||||||||||||||||||||||||
| 1882 | { | - | ||||||||||||||||||||||||
| 1883 | Q_ASSERT(f != 0); | - | ||||||||||||||||||||||||
| 1884 | quint8 bits = 0; | - | ||||||||||||||||||||||||
| 1885 | if (f->request.style) | - | ||||||||||||||||||||||||
| 1886 | bits |= 0x01; | - | ||||||||||||||||||||||||
| 1887 | if (f->underline) | - | ||||||||||||||||||||||||
| 1888 | bits |= 0x02; | - | ||||||||||||||||||||||||
| 1889 | if (f->overline) | - | ||||||||||||||||||||||||
| 1890 | bits |= 0x40; | - | ||||||||||||||||||||||||
| 1891 | if (f->strikeOut) | - | ||||||||||||||||||||||||
| 1892 | bits |= 0x04; | - | ||||||||||||||||||||||||
| 1893 | if (f->request.fixedPitch) | - | ||||||||||||||||||||||||
| 1894 | bits |= 0x08; | - | ||||||||||||||||||||||||
| 1895 | // if (f.hintSetByUser) | - | ||||||||||||||||||||||||
| 1896 | // bits |= 0x10; | - | ||||||||||||||||||||||||
| 1897 | if (version >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
| 1898 | if (f->kerning) | - | ||||||||||||||||||||||||
| 1899 | bits |= 0x10; | - | ||||||||||||||||||||||||
| 1900 | } | - | ||||||||||||||||||||||||
| 1901 | if (f->request.style == QFont::StyleOblique) | - | ||||||||||||||||||||||||
| 1902 | bits |= 0x80; | - | ||||||||||||||||||||||||
| 1903 | return bits; | - | ||||||||||||||||||||||||
| 1904 | } | - | ||||||||||||||||||||||||
| 1905 | - | |||||||||||||||||||||||||
| 1906 | static quint8 get_extended_font_bits(const QFontPrivate *f) | - | ||||||||||||||||||||||||
| 1907 | { | - | ||||||||||||||||||||||||
| 1908 | Q_ASSERT(f != 0); | - | ||||||||||||||||||||||||
| 1909 | quint8 bits = 0; | - | ||||||||||||||||||||||||
| 1910 | if (f->request.ignorePitch) | - | ||||||||||||||||||||||||
| 1911 | bits |= 0x01; | - | ||||||||||||||||||||||||
| 1912 | if (f->letterSpacingIsAbsolute) | - | ||||||||||||||||||||||||
| 1913 | bits |= 0x02; | - | ||||||||||||||||||||||||
| 1914 | return bits; | - | ||||||||||||||||||||||||
| 1915 | } | - | ||||||||||||||||||||||||
| 1916 | - | |||||||||||||||||||||||||
| 1917 | /* \internal | - | ||||||||||||||||||||||||
| 1918 | Internal function. Sets boolean font settings from an unsigned | - | ||||||||||||||||||||||||
| 1919 | 8-bit number. Used for serialization etc. | - | ||||||||||||||||||||||||
| 1920 | */ | - | ||||||||||||||||||||||||
| 1921 | static void set_font_bits(int version, quint8 bits, QFontPrivate *f) | - | ||||||||||||||||||||||||
| 1922 | { | - | ||||||||||||||||||||||||
| 1923 | Q_ASSERT(f != 0); | - | ||||||||||||||||||||||||
| 1924 | f->request.style = (bits & 0x01) != 0 ? QFont::StyleItalic : QFont::StyleNormal; | - | ||||||||||||||||||||||||
| 1925 | f->underline = (bits & 0x02) != 0; | - | ||||||||||||||||||||||||
| 1926 | f->overline = (bits & 0x40) != 0; | - | ||||||||||||||||||||||||
| 1927 | f->strikeOut = (bits & 0x04) != 0; | - | ||||||||||||||||||||||||
| 1928 | f->request.fixedPitch = (bits & 0x08) != 0; | - | ||||||||||||||||||||||||
| 1929 | // f->hintSetByUser = (bits & 0x10) != 0; | - | ||||||||||||||||||||||||
| 1930 | if (version >= QDataStream::Qt_4_0) | - | ||||||||||||||||||||||||
| 1931 | f->kerning = (bits & 0x10) != 0; | - | ||||||||||||||||||||||||
| 1932 | if ((bits & 0x80) != 0) | - | ||||||||||||||||||||||||
| 1933 | f->request.style = QFont::StyleOblique; | - | ||||||||||||||||||||||||
| 1934 | } | - | ||||||||||||||||||||||||
| 1935 | - | |||||||||||||||||||||||||
| 1936 | static void set_extended_font_bits(quint8 bits, QFontPrivate *f) | - | ||||||||||||||||||||||||
| 1937 | { | - | ||||||||||||||||||||||||
| 1938 | Q_ASSERT(f != 0); | - | ||||||||||||||||||||||||
| 1939 | f->request.ignorePitch = (bits & 0x01) != 0; | - | ||||||||||||||||||||||||
| 1940 | f->letterSpacingIsAbsolute = (bits & 0x02) != 0; | - | ||||||||||||||||||||||||
| 1941 | } | - | ||||||||||||||||||||||||
| 1942 | #endif | - | ||||||||||||||||||||||||
| 1943 | - | |||||||||||||||||||||||||
| 1944 | #if QT_DEPRECATED_SINCE(5, 3) | - | ||||||||||||||||||||||||
| 1945 | /*! | - | ||||||||||||||||||||||||
| 1946 | \fn QString QFont::rawName() const | - | ||||||||||||||||||||||||
| 1947 | \deprecated | - | ||||||||||||||||||||||||
| 1948 | - | |||||||||||||||||||||||||
| 1949 | Returns the name of the font within the underlying window system. | - | ||||||||||||||||||||||||
| 1950 | - | |||||||||||||||||||||||||
| 1951 | On X11, this function will return an empty string. | - | ||||||||||||||||||||||||
| 1952 | - | |||||||||||||||||||||||||
| 1953 | Using the return value of this function is usually \e not \e | - | ||||||||||||||||||||||||
| 1954 | portable. | - | ||||||||||||||||||||||||
| 1955 | - | |||||||||||||||||||||||||
| 1956 | \sa setRawName() | - | ||||||||||||||||||||||||
| 1957 | */ | - | ||||||||||||||||||||||||
| 1958 | QString QFont::rawName() const | - | ||||||||||||||||||||||||
| 1959 | { | - | ||||||||||||||||||||||||
| 1960 | return QLatin1String("unknown"); | - | ||||||||||||||||||||||||
| 1961 | } | - | ||||||||||||||||||||||||
| 1962 | - | |||||||||||||||||||||||||
| 1963 | /*! | - | ||||||||||||||||||||||||
| 1964 | \fn void QFont::setRawName(const QString &name) | - | ||||||||||||||||||||||||
| 1965 | \deprecated | - | ||||||||||||||||||||||||
| 1966 | - | |||||||||||||||||||||||||
| 1967 | Sets a font by its system specific name. | - | ||||||||||||||||||||||||
| 1968 | - | |||||||||||||||||||||||||
| 1969 | A font set with setRawName() is still a full-featured QFont. It can | - | ||||||||||||||||||||||||
| 1970 | be queried (for example with italic()) or modified (for example with | - | ||||||||||||||||||||||||
| 1971 | setItalic()) and is therefore also suitable for rendering rich text. | - | ||||||||||||||||||||||||
| 1972 | - | |||||||||||||||||||||||||
| 1973 | If Qt's internal font database cannot resolve the raw name, the | - | ||||||||||||||||||||||||
| 1974 | font becomes a raw font with \a name as its family. | - | ||||||||||||||||||||||||
| 1975 | - | |||||||||||||||||||||||||
| 1976 | \sa rawName(), setFamily() | - | ||||||||||||||||||||||||
| 1977 | */ | - | ||||||||||||||||||||||||
| 1978 | void QFont::setRawName(const QString &) | - | ||||||||||||||||||||||||
| 1979 | { | - | ||||||||||||||||||||||||
| 1980 | } | - | ||||||||||||||||||||||||
| 1981 | #endif | - | ||||||||||||||||||||||||
| 1982 | - | |||||||||||||||||||||||||
| 1983 | /*! | - | ||||||||||||||||||||||||
| 1984 | Returns the font's key, a textual representation of a font. It is | - | ||||||||||||||||||||||||
| 1985 | typically used as the key for a cache or dictionary of fonts. | - | ||||||||||||||||||||||||
| 1986 | - | |||||||||||||||||||||||||
| 1987 | \sa QMap | - | ||||||||||||||||||||||||
| 1988 | */ | - | ||||||||||||||||||||||||
| 1989 | QString QFont::key() const | - | ||||||||||||||||||||||||
| 1990 | { | - | ||||||||||||||||||||||||
| 1991 | return toString(); | - | ||||||||||||||||||||||||
| 1992 | } | - | ||||||||||||||||||||||||
| 1993 | - | |||||||||||||||||||||||||
| 1994 | /*! | - | ||||||||||||||||||||||||
| 1995 | Returns a description of the font. The description is a | - | ||||||||||||||||||||||||
| 1996 | comma-separated list of the attributes, perfectly suited for use | - | ||||||||||||||||||||||||
| 1997 | in QSettings. | - | ||||||||||||||||||||||||
| 1998 | - | |||||||||||||||||||||||||
| 1999 | \sa fromString() | - | ||||||||||||||||||||||||
| 2000 | */ | - | ||||||||||||||||||||||||
| 2001 | QString QFont::toString() const | - | ||||||||||||||||||||||||
| 2002 | { | - | ||||||||||||||||||||||||
| 2003 | const QChar comma(QLatin1Char(',')); | - | ||||||||||||||||||||||||
| 2004 | return family() + comma + | - | ||||||||||||||||||||||||
| 2005 | QString::number( pointSizeF()) + comma + | - | ||||||||||||||||||||||||
| 2006 | QString::number( pixelSize()) + comma + | - | ||||||||||||||||||||||||
| 2007 | QString::number((int) styleHint()) + comma + | - | ||||||||||||||||||||||||
| 2008 | QString::number( weight()) + comma + | - | ||||||||||||||||||||||||
| 2009 | QString::number((int) style()) + comma + | - | ||||||||||||||||||||||||
| 2010 | QString::number((int) underline()) + comma + | - | ||||||||||||||||||||||||
| 2011 | QString::number((int) strikeOut()) + comma + | - | ||||||||||||||||||||||||
| 2012 | QString::number((int)fixedPitch()) + comma + | - | ||||||||||||||||||||||||
| 2013 | QString::number((int) false); | - | ||||||||||||||||||||||||
| 2014 | } | - | ||||||||||||||||||||||||
| 2015 | - | |||||||||||||||||||||||||
| 2016 | /*! | - | ||||||||||||||||||||||||
| 2017 | Returns the hash value for \a font. If specified, \a seed is used | - | ||||||||||||||||||||||||
| 2018 | to initialize the hash. | - | ||||||||||||||||||||||||
| 2019 | - | |||||||||||||||||||||||||
| 2020 | \relates QFont | - | ||||||||||||||||||||||||
| 2021 | \since 5.3 | - | ||||||||||||||||||||||||
| 2022 | */ | - | ||||||||||||||||||||||||
| 2023 | uint qHash(const QFont &font, uint seed) Q_DECL_NOTHROW | - | ||||||||||||||||||||||||
| 2024 | { | - | ||||||||||||||||||||||||
| 2025 | return qHash(QFontPrivate::get(font)->request, seed); never executed: return qHash(QFontPrivate::get(font)->request, seed); | 0 | ||||||||||||||||||||||||
| 2026 | } | - | ||||||||||||||||||||||||
| 2027 | - | |||||||||||||||||||||||||
| 2028 | - | |||||||||||||||||||||||||
| 2029 | /*! | - | ||||||||||||||||||||||||
| 2030 | Sets this font to match the description \a descrip. The description | - | ||||||||||||||||||||||||
| 2031 | is a comma-separated list of the font attributes, as returned by | - | ||||||||||||||||||||||||
| 2032 | toString(). | - | ||||||||||||||||||||||||
| 2033 | - | |||||||||||||||||||||||||
| 2034 | \sa toString() | - | ||||||||||||||||||||||||
| 2035 | */ | - | ||||||||||||||||||||||||
| 2036 | bool QFont::fromString(const QString &descrip) | - | ||||||||||||||||||||||||
| 2037 | { | - | ||||||||||||||||||||||||
| 2038 | QStringListconst auto l (= descrip.splitsplitRef(QLatin1Char(',')));)); | - | ||||||||||||||||||||||||
| 2039 | - | |||||||||||||||||||||||||
| 2040 | int count = l.count(); | - | ||||||||||||||||||||||||
| 2041 | if (!count || (count > 2 && count < 9) || count > 11) {
| 0 | ||||||||||||||||||||||||
| 2042 | qWarning("QFont::fromString: Invalid description '%s'", | - | ||||||||||||||||||||||||
| 2043 | descrip.isEmpty() ? "(empty)" : descrip.toLatin1().data()); | - | ||||||||||||||||||||||||
| 2044 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2045 | } | - | ||||||||||||||||||||||||
| 2046 | - | |||||||||||||||||||||||||
| 2047 | setFamily(l[0]);].toString()); | - | ||||||||||||||||||||||||
| 2048 | if (count > 1 && l[1].toDouble() > 0.0)
| 0 | ||||||||||||||||||||||||
| 2049 | setPointSizeF(l[1].toDouble()); never executed: setPointSizeF(l[1].toDouble()); | 0 | ||||||||||||||||||||||||
| 2050 | if (count == 9) {
| 0 | ||||||||||||||||||||||||
| 2051 | setStyleHint((StyleHint) l[2].toInt()); | - | ||||||||||||||||||||||||
| 2052 | setWeight(qMax(qMin(99, l[3].toInt()), 0)); | - | ||||||||||||||||||||||||
| 2053 | setItalic(l[4].toInt()); | - | ||||||||||||||||||||||||
| 2054 | setUnderline(l[5].toInt()); | - | ||||||||||||||||||||||||
| 2055 | setStrikeOut(l[6].toInt()); | - | ||||||||||||||||||||||||
| 2056 | setFixedPitch(l[7].toInt()); | - | ||||||||||||||||||||||||
| 2057 | } else if (count == 10) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 2058 | if (l[2].toInt() > 0)
| 0 | ||||||||||||||||||||||||
| 2059 | setPixelSize(l[2].toInt()); never executed: setPixelSize(l[2].toInt()); | 0 | ||||||||||||||||||||||||
| 2060 | setStyleHint((StyleHint) l[3].toInt()); | - | ||||||||||||||||||||||||
| 2061 | setWeight(qMax(qMin(99, l[4].toInt()), 0)); | - | ||||||||||||||||||||||||
| 2062 | setStyle((QFont::Style)l[5].toInt()); | - | ||||||||||||||||||||||||
| 2063 | setUnderline(l[6].toInt()); | - | ||||||||||||||||||||||||
| 2064 | setStrikeOut(l[7].toInt()); | - | ||||||||||||||||||||||||
| 2065 | setFixedPitch(l[8].toInt()); | - | ||||||||||||||||||||||||
| 2066 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2067 | if (count >= 9 && !d->request.fixedPitch) // assume 'false' fixedPitch equals default
| 0 | ||||||||||||||||||||||||
| 2068 | d->request.ignorePitch = true; never executed: d->request.ignorePitch = true; | 0 | ||||||||||||||||||||||||
| 2069 | - | |||||||||||||||||||||||||
| 2070 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 2071 | } | - | ||||||||||||||||||||||||
| 2072 | - | |||||||||||||||||||||||||
| 2073 | /*! \fn void QFont::initialize() | - | ||||||||||||||||||||||||
| 2074 | \internal | - | ||||||||||||||||||||||||
| 2075 | - | |||||||||||||||||||||||||
| 2076 | Internal function that initializes the font system. The font cache | - | ||||||||||||||||||||||||
| 2077 | and font dict do not alloc the keys. The key is a QString which is | - | ||||||||||||||||||||||||
| 2078 | shared between QFontPrivate and QXFontName. | - | ||||||||||||||||||||||||
| 2079 | */ | - | ||||||||||||||||||||||||
| 2080 | void QFont::initialize() | - | ||||||||||||||||||||||||
| 2081 | { | - | ||||||||||||||||||||||||
| 2082 | } | - | ||||||||||||||||||||||||
| 2083 | - | |||||||||||||||||||||||||
| 2084 | /*! \fn void QFont::cleanup() | - | ||||||||||||||||||||||||
| 2085 | \internal | - | ||||||||||||||||||||||||
| 2086 | - | |||||||||||||||||||||||||
| 2087 | Internal function that cleans up the font system. | - | ||||||||||||||||||||||||
| 2088 | */ | - | ||||||||||||||||||||||||
| 2089 | void QFont::cleanup() | - | ||||||||||||||||||||||||
| 2090 | { | - | ||||||||||||||||||||||||
| 2091 | QFontCache::cleanup(); | - | ||||||||||||||||||||||||
| 2092 | } | - | ||||||||||||||||||||||||
| 2093 | - | |||||||||||||||||||||||||
| 2094 | /*! \internal | - | ||||||||||||||||||||||||
| 2095 | - | |||||||||||||||||||||||||
| 2096 | Internal function that dumps font cache statistics. | - | ||||||||||||||||||||||||
| 2097 | */ | - | ||||||||||||||||||||||||
| 2098 | void QFont::cacheStatistics() | - | ||||||||||||||||||||||||
| 2099 | { | - | ||||||||||||||||||||||||
| 2100 | } | - | ||||||||||||||||||||||||
| 2101 | - | |||||||||||||||||||||||||
| 2102 | /*! | - | ||||||||||||||||||||||||
| 2103 | \fn QString QFont::lastResortFamily() const | - | ||||||||||||||||||||||||
| 2104 | - | |||||||||||||||||||||||||
| 2105 | Returns the "last resort" font family name. | - | ||||||||||||||||||||||||
| 2106 | - | |||||||||||||||||||||||||
| 2107 | The current implementation tries a wide variety of common fonts, | - | ||||||||||||||||||||||||
| 2108 | returning the first one it finds. Is is possible that no family is | - | ||||||||||||||||||||||||
| 2109 | found in which case an empty string is returned. | - | ||||||||||||||||||||||||
| 2110 | - | |||||||||||||||||||||||||
| 2111 | \sa lastResortFont() | - | ||||||||||||||||||||||||
| 2112 | */ | - | ||||||||||||||||||||||||
| 2113 | QString QFont::lastResortFamily() const | - | ||||||||||||||||||||||||
| 2114 | { | - | ||||||||||||||||||||||||
| 2115 | return QString::fromLatin1("helvetica"); | - | ||||||||||||||||||||||||
| 2116 | } | - | ||||||||||||||||||||||||
| 2117 | - | |||||||||||||||||||||||||
| 2118 | extern QStringList qt_fallbacksForFamily(const QString &family, QFont::Style style, | - | ||||||||||||||||||||||||
| 2119 | QFont::StyleHint styleHint, QChar::Script script); | - | ||||||||||||||||||||||||
| 2120 | - | |||||||||||||||||||||||||
| 2121 | /*! | - | ||||||||||||||||||||||||
| 2122 | \fn QString QFont::defaultFamily() const | - | ||||||||||||||||||||||||
| 2123 | - | |||||||||||||||||||||||||
| 2124 | Returns the family name that corresponds to the current style | - | ||||||||||||||||||||||||
| 2125 | hint. | - | ||||||||||||||||||||||||
| 2126 | - | |||||||||||||||||||||||||
| 2127 | \sa StyleHint, styleHint(), setStyleHint() | - | ||||||||||||||||||||||||
| 2128 | */ | - | ||||||||||||||||||||||||
| 2129 | QString QFont::defaultFamily() const | - | ||||||||||||||||||||||||
| 2130 | { | - | ||||||||||||||||||||||||
| 2131 | const QStringList fallbacks = qt_fallbacksForFamily(QString(), QFont::StyleNormal | - | ||||||||||||||||||||||||
| 2132 | , QFont::StyleHint(d->request.styleHint), QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2133 | if (!fallbacks.isEmpty()) | - | ||||||||||||||||||||||||
| 2134 | return fallbacks.first(); | - | ||||||||||||||||||||||||
| 2135 | return QString(); | - | ||||||||||||||||||||||||
| 2136 | } | - | ||||||||||||||||||||||||
| 2137 | - | |||||||||||||||||||||||||
| 2138 | /*! | - | ||||||||||||||||||||||||
| 2139 | \fn QString QFont::lastResortFont() const | - | ||||||||||||||||||||||||
| 2140 | - | |||||||||||||||||||||||||
| 2141 | Returns a "last resort" font name for the font matching algorithm. | - | ||||||||||||||||||||||||
| 2142 | This is used if the last resort family is not available. It will | - | ||||||||||||||||||||||||
| 2143 | always return a name, if necessary returning something like | - | ||||||||||||||||||||||||
| 2144 | "fixed" or "system". | - | ||||||||||||||||||||||||
| 2145 | - | |||||||||||||||||||||||||
| 2146 | The current implementation tries a wide variety of common fonts, | - | ||||||||||||||||||||||||
| 2147 | returning the first one it finds. The implementation may change | - | ||||||||||||||||||||||||
| 2148 | at any time, but this function will always return a string | - | ||||||||||||||||||||||||
| 2149 | containing something. | - | ||||||||||||||||||||||||
| 2150 | - | |||||||||||||||||||||||||
| 2151 | It is theoretically possible that there really isn't a | - | ||||||||||||||||||||||||
| 2152 | lastResortFont() in which case Qt will abort with an error | - | ||||||||||||||||||||||||
| 2153 | message. We have not been able to identify a case where this | - | ||||||||||||||||||||||||
| 2154 | happens. Please \l{bughowto.html}{report it as a bug} if | - | ||||||||||||||||||||||||
| 2155 | it does, preferably with a list of the fonts you have installed. | - | ||||||||||||||||||||||||
| 2156 | - | |||||||||||||||||||||||||
| 2157 | \sa lastResortFamily() | - | ||||||||||||||||||||||||
| 2158 | */ | - | ||||||||||||||||||||||||
| 2159 | QString QFont::lastResortFont() const | - | ||||||||||||||||||||||||
| 2160 | { | - | ||||||||||||||||||||||||
| 2161 | qFatal("QFont::lastResortFont: Cannot find any reasonable font"); | - | ||||||||||||||||||||||||
| 2162 | // Shut compiler up | - | ||||||||||||||||||||||||
| 2163 | return QString(); | - | ||||||||||||||||||||||||
| 2164 | } | - | ||||||||||||||||||||||||
| 2165 | - | |||||||||||||||||||||||||
| 2166 | /***************************************************************************** | - | ||||||||||||||||||||||||
| 2167 | QFont stream functions | - | ||||||||||||||||||||||||
| 2168 | *****************************************************************************/ | - | ||||||||||||||||||||||||
| 2169 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 2170 | - | |||||||||||||||||||||||||
| 2171 | /*! | - | ||||||||||||||||||||||||
| 2172 | \relates QFont | - | ||||||||||||||||||||||||
| 2173 | - | |||||||||||||||||||||||||
| 2174 | Writes the font \a font to the data stream \a s. (toString() | - | ||||||||||||||||||||||||
| 2175 | writes to a text stream.) | - | ||||||||||||||||||||||||
| 2176 | - | |||||||||||||||||||||||||
| 2177 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||||||||
| 2178 | */ | - | ||||||||||||||||||||||||
| 2179 | QDataStream &operator<<(QDataStream &s, const QFont &font) | - | ||||||||||||||||||||||||
| 2180 | { | - | ||||||||||||||||||||||||
| 2181 | if (s.version() == 1) { | - | ||||||||||||||||||||||||
| 2182 | s << font.d->request.family.toLatin1(); | - | ||||||||||||||||||||||||
| 2183 | } else { | - | ||||||||||||||||||||||||
| 2184 | s << font.d->request.family; | - | ||||||||||||||||||||||||
| 2185 | if (s.version() >= QDataStream::Qt_5_4) | - | ||||||||||||||||||||||||
| 2186 | s << font.d->request.styleName; | - | ||||||||||||||||||||||||
| 2187 | } | - | ||||||||||||||||||||||||
| 2188 | - | |||||||||||||||||||||||||
| 2189 | if (s.version() >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
| 2190 | // 4.0 | - | ||||||||||||||||||||||||
| 2191 | double pointSize = font.d->request.pointSize; | - | ||||||||||||||||||||||||
| 2192 | qint32 pixelSize = font.d->request.pixelSize; | - | ||||||||||||||||||||||||
| 2193 | s << pointSize; | - | ||||||||||||||||||||||||
| 2194 | s << pixelSize; | - | ||||||||||||||||||||||||
| 2195 | } else if (s.version() <= 3) { | - | ||||||||||||||||||||||||
| 2196 | qint16 pointSize = (qint16) (font.d->request.pointSize * 10); | - | ||||||||||||||||||||||||
| 2197 | if (pointSize < 0) { | - | ||||||||||||||||||||||||
| 2198 | pointSize = (qint16)QFontInfo(font).pointSize() * 10; | - | ||||||||||||||||||||||||
| 2199 | } | - | ||||||||||||||||||||||||
| 2200 | s << pointSize; | - | ||||||||||||||||||||||||
| 2201 | } else { | - | ||||||||||||||||||||||||
| 2202 | s << (qint16) (font.d->request.pointSize * 10); | - | ||||||||||||||||||||||||
| 2203 | s << (qint16) font.d->request.pixelSize; | - | ||||||||||||||||||||||||
| 2204 | } | - | ||||||||||||||||||||||||
| 2205 | - | |||||||||||||||||||||||||
| 2206 | s << (quint8) font.d->request.styleHint; | - | ||||||||||||||||||||||||
| 2207 | if (s.version() >= QDataStream::Qt_3_1) { | - | ||||||||||||||||||||||||
| 2208 | // Continue writing 8 bits for versions < 5.4 so that we don't write too much, | - | ||||||||||||||||||||||||
| 2209 | // even though we need 16 to store styleStrategy, so there is some data loss. | - | ||||||||||||||||||||||||
| 2210 | if (s.version() >= QDataStream::Qt_5_4) | - | ||||||||||||||||||||||||
| 2211 | s << (quint16) font.d->request.styleStrategy; | - | ||||||||||||||||||||||||
| 2212 | else | - | ||||||||||||||||||||||||
| 2213 | s << (quint8) font.d->request.styleStrategy; | - | ||||||||||||||||||||||||
| 2214 | } | - | ||||||||||||||||||||||||
| 2215 | s << (quint8) 0 | - | ||||||||||||||||||||||||
| 2216 | << (quint8) font.d->request.weight | - | ||||||||||||||||||||||||
| 2217 | << get_font_bits(s.version(), font.d.data()); | - | ||||||||||||||||||||||||
| 2218 | if (s.version() >= QDataStream::Qt_4_3) | - | ||||||||||||||||||||||||
| 2219 | s << (quint16)font.d->request.stretch; | - | ||||||||||||||||||||||||
| 2220 | if (s.version() >= QDataStream::Qt_4_4) | - | ||||||||||||||||||||||||
| 2221 | s << get_extended_font_bits(font.d.data()); | - | ||||||||||||||||||||||||
| 2222 | if (s.version() >= QDataStream::Qt_4_5) { | - | ||||||||||||||||||||||||
| 2223 | s << font.d->letterSpacing.value(); | - | ||||||||||||||||||||||||
| 2224 | s << font.d->wordSpacing.value(); | - | ||||||||||||||||||||||||
| 2225 | } | - | ||||||||||||||||||||||||
| 2226 | if (s.version() >= QDataStream::Qt_5_4) | - | ||||||||||||||||||||||||
| 2227 | s << (quint8)font.d->request.hintingPreference; | - | ||||||||||||||||||||||||
| 2228 | if (s.version() >= QDataStream::Qt_5_6) | - | ||||||||||||||||||||||||
| 2229 | s << (quint8)font.d->capital; | - | ||||||||||||||||||||||||
| 2230 | return s; | - | ||||||||||||||||||||||||
| 2231 | } | - | ||||||||||||||||||||||||
| 2232 | - | |||||||||||||||||||||||||
| 2233 | - | |||||||||||||||||||||||||
| 2234 | /*! | - | ||||||||||||||||||||||||
| 2235 | \relates QFont | - | ||||||||||||||||||||||||
| 2236 | - | |||||||||||||||||||||||||
| 2237 | Reads the font \a font from the data stream \a s. (fromString() | - | ||||||||||||||||||||||||
| 2238 | reads from a text stream.) | - | ||||||||||||||||||||||||
| 2239 | - | |||||||||||||||||||||||||
| 2240 | \sa{Serializing Qt Data Types}{Format of the QDataStream operators} | - | ||||||||||||||||||||||||
| 2241 | */ | - | ||||||||||||||||||||||||
| 2242 | QDataStream &operator>>(QDataStream &s, QFont &font) | - | ||||||||||||||||||||||||
| 2243 | { | - | ||||||||||||||||||||||||
| 2244 | font.d = new QFontPrivate; | - | ||||||||||||||||||||||||
| 2245 | font.resolve_mask = QFont::AllPropertiesResolved; | - | ||||||||||||||||||||||||
| 2246 | - | |||||||||||||||||||||||||
| 2247 | quint8 styleHint, charSet, weight, bits; | - | ||||||||||||||||||||||||
| 2248 | quint16 styleStrategy = QFont::PreferDefault; | - | ||||||||||||||||||||||||
| 2249 | - | |||||||||||||||||||||||||
| 2250 | if (s.version() == 1) { | - | ||||||||||||||||||||||||
| 2251 | QByteArray fam; | - | ||||||||||||||||||||||||
| 2252 | s >> fam; | - | ||||||||||||||||||||||||
| 2253 | font.d->request.family = QString::fromLatin1(fam); | - | ||||||||||||||||||||||||
| 2254 | } else { | - | ||||||||||||||||||||||||
| 2255 | s >> font.d->request.family; | - | ||||||||||||||||||||||||
| 2256 | if (s.version() >= QDataStream::Qt_5_4) | - | ||||||||||||||||||||||||
| 2257 | s >> font.d->request.styleName; | - | ||||||||||||||||||||||||
| 2258 | } | - | ||||||||||||||||||||||||
| 2259 | - | |||||||||||||||||||||||||
| 2260 | if (s.version() >= QDataStream::Qt_4_0) { | - | ||||||||||||||||||||||||
| 2261 | // 4.0 | - | ||||||||||||||||||||||||
| 2262 | double pointSize; | - | ||||||||||||||||||||||||
| 2263 | qint32 pixelSize; | - | ||||||||||||||||||||||||
| 2264 | s >> pointSize; | - | ||||||||||||||||||||||||
| 2265 | s >> pixelSize; | - | ||||||||||||||||||||||||
| 2266 | font.d->request.pointSize = qreal(pointSize); | - | ||||||||||||||||||||||||
| 2267 | font.d->request.pixelSize = pixelSize; | - | ||||||||||||||||||||||||
| 2268 | } else { | - | ||||||||||||||||||||||||
| 2269 | qint16 pointSize, pixelSize = -1; | - | ||||||||||||||||||||||||
| 2270 | s >> pointSize; | - | ||||||||||||||||||||||||
| 2271 | if (s.version() >= 4) | - | ||||||||||||||||||||||||
| 2272 | s >> pixelSize; | - | ||||||||||||||||||||||||
| 2273 | font.d->request.pointSize = qreal(pointSize / 10.); | - | ||||||||||||||||||||||||
| 2274 | font.d->request.pixelSize = pixelSize; | - | ||||||||||||||||||||||||
| 2275 | } | - | ||||||||||||||||||||||||
| 2276 | s >> styleHint; | - | ||||||||||||||||||||||||
| 2277 | if (s.version() >= QDataStream::Qt_3_1) { | - | ||||||||||||||||||||||||
| 2278 | if (s.version() >= QDataStream::Qt_5_4) { | - | ||||||||||||||||||||||||
| 2279 | s >> styleStrategy; | - | ||||||||||||||||||||||||
| 2280 | } else { | - | ||||||||||||||||||||||||
| 2281 | quint8 tempStyleStrategy; | - | ||||||||||||||||||||||||
| 2282 | s >> tempStyleStrategy; | - | ||||||||||||||||||||||||
| 2283 | styleStrategy = tempStyleStrategy; | - | ||||||||||||||||||||||||
| 2284 | } | - | ||||||||||||||||||||||||
| 2285 | } | - | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | s >> charSet; | - | ||||||||||||||||||||||||
| 2288 | s >> weight; | - | ||||||||||||||||||||||||
| 2289 | s >> bits; | - | ||||||||||||||||||||||||
| 2290 | - | |||||||||||||||||||||||||
| 2291 | font.d->request.styleHint = styleHint; | - | ||||||||||||||||||||||||
| 2292 | font.d->request.styleStrategy = styleStrategy; | - | ||||||||||||||||||||||||
| 2293 | font.d->request.weight = weight; | - | ||||||||||||||||||||||||
| 2294 | - | |||||||||||||||||||||||||
| 2295 | set_font_bits(s.version(), bits, font.d.data()); | - | ||||||||||||||||||||||||
| 2296 | - | |||||||||||||||||||||||||
| 2297 | if (s.version() >= QDataStream::Qt_4_3) { | - | ||||||||||||||||||||||||
| 2298 | quint16 stretch; | - | ||||||||||||||||||||||||
| 2299 | s >> stretch; | - | ||||||||||||||||||||||||
| 2300 | font.d->request.stretch = stretch; | - | ||||||||||||||||||||||||
| 2301 | } | - | ||||||||||||||||||||||||
| 2302 | - | |||||||||||||||||||||||||
| 2303 | if (s.version() >= QDataStream::Qt_4_4) { | - | ||||||||||||||||||||||||
| 2304 | quint8 extendedBits; | - | ||||||||||||||||||||||||
| 2305 | s >> extendedBits; | - | ||||||||||||||||||||||||
| 2306 | set_extended_font_bits(extendedBits, font.d.data()); | - | ||||||||||||||||||||||||
| 2307 | } | - | ||||||||||||||||||||||||
| 2308 | if (s.version() >= QDataStream::Qt_4_5) { | - | ||||||||||||||||||||||||
| 2309 | int value; | - | ||||||||||||||||||||||||
| 2310 | s >> value; | - | ||||||||||||||||||||||||
| 2311 | font.d->letterSpacing.setValue(value); | - | ||||||||||||||||||||||||
| 2312 | s >> value; | - | ||||||||||||||||||||||||
| 2313 | font.d->wordSpacing.setValue(value); | - | ||||||||||||||||||||||||
| 2314 | } | - | ||||||||||||||||||||||||
| 2315 | if (s.version() >= QDataStream::Qt_5_4) { | - | ||||||||||||||||||||||||
| 2316 | quint8 value; | - | ||||||||||||||||||||||||
| 2317 | s >> value; | - | ||||||||||||||||||||||||
| 2318 | font.d->request.hintingPreference = QFont::HintingPreference(value); | - | ||||||||||||||||||||||||
| 2319 | } | - | ||||||||||||||||||||||||
| 2320 | if (s.version() >= QDataStream::Qt_5_6) { | - | ||||||||||||||||||||||||
| 2321 | quint8 value; | - | ||||||||||||||||||||||||
| 2322 | s >> value; | - | ||||||||||||||||||||||||
| 2323 | font.d->capital = QFont::Capitalization(value); | - | ||||||||||||||||||||||||
| 2324 | } | - | ||||||||||||||||||||||||
| 2325 | return s; | - | ||||||||||||||||||||||||
| 2326 | } | - | ||||||||||||||||||||||||
| 2327 | - | |||||||||||||||||||||||||
| 2328 | #endif // QT_NO_DATASTREAM | - | ||||||||||||||||||||||||
| 2329 | - | |||||||||||||||||||||||||
| 2330 | - | |||||||||||||||||||||||||
| 2331 | /***************************************************************************** | - | ||||||||||||||||||||||||
| 2332 | QFontInfo member functions | - | ||||||||||||||||||||||||
| 2333 | *****************************************************************************/ | - | ||||||||||||||||||||||||
| 2334 | - | |||||||||||||||||||||||||
| 2335 | /*! | - | ||||||||||||||||||||||||
| 2336 | \class QFontInfo | - | ||||||||||||||||||||||||
| 2337 | \reentrant | - | ||||||||||||||||||||||||
| 2338 | - | |||||||||||||||||||||||||
| 2339 | \brief The QFontInfo class provides general information about fonts. | - | ||||||||||||||||||||||||
| 2340 | \inmodule QtGui | - | ||||||||||||||||||||||||
| 2341 | - | |||||||||||||||||||||||||
| 2342 | \ingroup appearance | - | ||||||||||||||||||||||||
| 2343 | \ingroup shared | - | ||||||||||||||||||||||||
| 2344 | - | |||||||||||||||||||||||||
| 2345 | The QFontInfo class provides the same access functions as QFont, | - | ||||||||||||||||||||||||
| 2346 | e.g. family(), pointSize(), italic(), weight(), fixedPitch(), | - | ||||||||||||||||||||||||
| 2347 | styleHint() etc. But whilst the QFont access functions return the | - | ||||||||||||||||||||||||
| 2348 | values that were set, a QFontInfo object returns the values that | - | ||||||||||||||||||||||||
| 2349 | apply to the font that will actually be used to draw the text. | - | ||||||||||||||||||||||||
| 2350 | - | |||||||||||||||||||||||||
| 2351 | For example, when the program asks for a 25pt Courier font on a | - | ||||||||||||||||||||||||
| 2352 | machine that has a non-scalable 24pt Courier font, QFont will | - | ||||||||||||||||||||||||
| 2353 | (normally) use the 24pt Courier for rendering. In this case, | - | ||||||||||||||||||||||||
| 2354 | QFont::pointSize() returns 25 and QFontInfo::pointSize() returns | - | ||||||||||||||||||||||||
| 2355 | 24. | - | ||||||||||||||||||||||||
| 2356 | - | |||||||||||||||||||||||||
| 2357 | There are three ways to create a QFontInfo object. | - | ||||||||||||||||||||||||
| 2358 | \list 1 | - | ||||||||||||||||||||||||
| 2359 | \li Calling the QFontInfo constructor with a QFont creates a font | - | ||||||||||||||||||||||||
| 2360 | info object for a screen-compatible font, i.e. the font cannot be | - | ||||||||||||||||||||||||
| 2361 | a printer font. If the font is changed later, the font | - | ||||||||||||||||||||||||
| 2362 | info object is \e not updated. | - | ||||||||||||||||||||||||
| 2363 | - | |||||||||||||||||||||||||
| 2364 | (Note: If you use a printer font the values returned may be | - | ||||||||||||||||||||||||
| 2365 | inaccurate. Printer fonts are not always accessible so the nearest | - | ||||||||||||||||||||||||
| 2366 | screen font is used if a printer font is supplied.) | - | ||||||||||||||||||||||||
| 2367 | - | |||||||||||||||||||||||||
| 2368 | \li QWidget::fontInfo() returns the font info for a widget's font. | - | ||||||||||||||||||||||||
| 2369 | This is equivalent to calling QFontInfo(widget->font()). If the | - | ||||||||||||||||||||||||
| 2370 | widget's font is changed later, the font info object is \e not | - | ||||||||||||||||||||||||
| 2371 | updated. | - | ||||||||||||||||||||||||
| 2372 | - | |||||||||||||||||||||||||
| 2373 | \li QPainter::fontInfo() returns the font info for a painter's | - | ||||||||||||||||||||||||
| 2374 | current font. If the painter's font is changed later, the font | - | ||||||||||||||||||||||||
| 2375 | info object is \e not updated. | - | ||||||||||||||||||||||||
| 2376 | \endlist | - | ||||||||||||||||||||||||
| 2377 | - | |||||||||||||||||||||||||
| 2378 | \sa QFont, QFontMetrics, QFontDatabase | - | ||||||||||||||||||||||||
| 2379 | */ | - | ||||||||||||||||||||||||
| 2380 | - | |||||||||||||||||||||||||
| 2381 | /*! | - | ||||||||||||||||||||||||
| 2382 | Constructs a font info object for \a font. | - | ||||||||||||||||||||||||
| 2383 | - | |||||||||||||||||||||||||
| 2384 | The font must be screen-compatible, i.e. a font you use when | - | ||||||||||||||||||||||||
| 2385 | drawing text in \l{QWidget}{widgets} or \l{QPixmap}{pixmaps}, not QPicture or QPrinter. | - | ||||||||||||||||||||||||
| 2386 | - | |||||||||||||||||||||||||
| 2387 | The font info object holds the information for the font that is | - | ||||||||||||||||||||||||
| 2388 | passed in the constructor at the time it is created, and is not | - | ||||||||||||||||||||||||
| 2389 | updated if the font's attributes are changed later. | - | ||||||||||||||||||||||||
| 2390 | - | |||||||||||||||||||||||||
| 2391 | Use QPainter::fontInfo() to get the font info when painting. | - | ||||||||||||||||||||||||
| 2392 | This will give correct results also when painting on paint device | - | ||||||||||||||||||||||||
| 2393 | that is not screen-compatible. | - | ||||||||||||||||||||||||
| 2394 | */ | - | ||||||||||||||||||||||||
| 2395 | QFontInfo::QFontInfo(const QFont &font) | - | ||||||||||||||||||||||||
| 2396 | : d(font.d.data())) | - | ||||||||||||||||||||||||
| 2397 | { | - | ||||||||||||||||||||||||
| 2398 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2399 | - | |||||||||||||||||||||||||
| 2400 | /*! | - | ||||||||||||||||||||||||
| 2401 | Constructs a copy of \a fi. | - | ||||||||||||||||||||||||
| 2402 | */ | - | ||||||||||||||||||||||||
| 2403 | QFontInfo::QFontInfo(const QFontInfo &fi) | - | ||||||||||||||||||||||||
| 2404 | : d(fi.d.data())) | - | ||||||||||||||||||||||||
| 2405 | { | - | ||||||||||||||||||||||||
| 2406 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2407 | - | |||||||||||||||||||||||||
| 2408 | /*! | - | ||||||||||||||||||||||||
| 2409 | Destroys the font info object. | - | ||||||||||||||||||||||||
| 2410 | */ | - | ||||||||||||||||||||||||
| 2411 | QFontInfo::~QFontInfo() | - | ||||||||||||||||||||||||
| 2412 | { | - | ||||||||||||||||||||||||
| 2413 | } | - | ||||||||||||||||||||||||
| 2414 | - | |||||||||||||||||||||||||
| 2415 | /*! | - | ||||||||||||||||||||||||
| 2416 | Assigns the font info in \a fi. | - | ||||||||||||||||||||||||
| 2417 | */ | - | ||||||||||||||||||||||||
| 2418 | QFontInfo &QFontInfo::operator=(const QFontInfo &fi) | - | ||||||||||||||||||||||||
| 2419 | { | - | ||||||||||||||||||||||||
| 2420 | d = fi.d.data();; | - | ||||||||||||||||||||||||
| 2421 | return *this; never executed: return *this; | 0 | ||||||||||||||||||||||||
| 2422 | } | - | ||||||||||||||||||||||||
| 2423 | - | |||||||||||||||||||||||||
| 2424 | /*! | - | ||||||||||||||||||||||||
| 2425 | \fn void QFontInfo::swap(QFontInfo &other) | - | ||||||||||||||||||||||||
| 2426 | \since 5.0 | - | ||||||||||||||||||||||||
| 2427 | - | |||||||||||||||||||||||||
| 2428 | Swaps this font info instance with \a other. This function is very | - | ||||||||||||||||||||||||
| 2429 | fast and never fails. | - | ||||||||||||||||||||||||
| 2430 | */ | - | ||||||||||||||||||||||||
| 2431 | - | |||||||||||||||||||||||||
| 2432 | /*! | - | ||||||||||||||||||||||||
| 2433 | Returns the family name of the matched window system font. | - | ||||||||||||||||||||||||
| 2434 | - | |||||||||||||||||||||||||
| 2435 | \sa QFont::family() | - | ||||||||||||||||||||||||
| 2436 | */ | - | ||||||||||||||||||||||||
| 2437 | QString QFontInfo::family() const | - | ||||||||||||||||||||||||
| 2438 | { | - | ||||||||||||||||||||||||
| 2439 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2440 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2441 | return engine->fontDef.family; | - | ||||||||||||||||||||||||
| 2442 | } | - | ||||||||||||||||||||||||
| 2443 | - | |||||||||||||||||||||||||
| 2444 | /*! | - | ||||||||||||||||||||||||
| 2445 | \since 4.8 | - | ||||||||||||||||||||||||
| 2446 | - | |||||||||||||||||||||||||
| 2447 | Returns the style name of the matched window system font on | - | ||||||||||||||||||||||||
| 2448 | systems that support it. | - | ||||||||||||||||||||||||
| 2449 | - | |||||||||||||||||||||||||
| 2450 | \sa QFont::styleName() | - | ||||||||||||||||||||||||
| 2451 | */ | - | ||||||||||||||||||||||||
| 2452 | QString QFontInfo::styleName() const | - | ||||||||||||||||||||||||
| 2453 | { | - | ||||||||||||||||||||||||
| 2454 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2455 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2456 | return engine->fontDef.styleName; | - | ||||||||||||||||||||||||
| 2457 | } | - | ||||||||||||||||||||||||
| 2458 | - | |||||||||||||||||||||||||
| 2459 | /*! | - | ||||||||||||||||||||||||
| 2460 | Returns the point size of the matched window system font. | - | ||||||||||||||||||||||||
| 2461 | - | |||||||||||||||||||||||||
| 2462 | \sa pointSizeF(), QFont::pointSize() | - | ||||||||||||||||||||||||
| 2463 | */ | - | ||||||||||||||||||||||||
| 2464 | int QFontInfo::pointSize() const | - | ||||||||||||||||||||||||
| 2465 | { | - | ||||||||||||||||||||||||
| 2466 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2467 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2468 | return qRound(engine->fontDef.pointSize); | - | ||||||||||||||||||||||||
| 2469 | } | - | ||||||||||||||||||||||||
| 2470 | - | |||||||||||||||||||||||||
| 2471 | /*! | - | ||||||||||||||||||||||||
| 2472 | Returns the point size of the matched window system font. | - | ||||||||||||||||||||||||
| 2473 | - | |||||||||||||||||||||||||
| 2474 | \sa QFont::pointSizeF() | - | ||||||||||||||||||||||||
| 2475 | */ | - | ||||||||||||||||||||||||
| 2476 | qreal QFontInfo::pointSizeF() const | - | ||||||||||||||||||||||||
| 2477 | { | - | ||||||||||||||||||||||||
| 2478 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2479 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2480 | return engine->fontDef.pointSize; | - | ||||||||||||||||||||||||
| 2481 | } | - | ||||||||||||||||||||||||
| 2482 | - | |||||||||||||||||||||||||
| 2483 | /*! | - | ||||||||||||||||||||||||
| 2484 | Returns the pixel size of the matched window system font. | - | ||||||||||||||||||||||||
| 2485 | - | |||||||||||||||||||||||||
| 2486 | \sa QFont::pointSize() | - | ||||||||||||||||||||||||
| 2487 | */ | - | ||||||||||||||||||||||||
| 2488 | int QFontInfo::pixelSize() const | - | ||||||||||||||||||||||||
| 2489 | { | - | ||||||||||||||||||||||||
| 2490 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2491 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2492 | return engine->fontDef.pixelSize; | - | ||||||||||||||||||||||||
| 2493 | } | - | ||||||||||||||||||||||||
| 2494 | - | |||||||||||||||||||||||||
| 2495 | /*! | - | ||||||||||||||||||||||||
| 2496 | Returns the italic value of the matched window system font. | - | ||||||||||||||||||||||||
| 2497 | - | |||||||||||||||||||||||||
| 2498 | \sa QFont::italic() | - | ||||||||||||||||||||||||
| 2499 | */ | - | ||||||||||||||||||||||||
| 2500 | bool QFontInfo::italic() const | - | ||||||||||||||||||||||||
| 2501 | { | - | ||||||||||||||||||||||||
| 2502 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2503 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2504 | return engine->fontDef.style != QFont::StyleNormal; | - | ||||||||||||||||||||||||
| 2505 | } | - | ||||||||||||||||||||||||
| 2506 | - | |||||||||||||||||||||||||
| 2507 | /*! | - | ||||||||||||||||||||||||
| 2508 | Returns the style value of the matched window system font. | - | ||||||||||||||||||||||||
| 2509 | - | |||||||||||||||||||||||||
| 2510 | \sa QFont::style() | - | ||||||||||||||||||||||||
| 2511 | */ | - | ||||||||||||||||||||||||
| 2512 | QFont::Style QFontInfo::style() const | - | ||||||||||||||||||||||||
| 2513 | { | - | ||||||||||||||||||||||||
| 2514 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2515 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2516 | return (QFont::Style)engine->fontDef.style; | - | ||||||||||||||||||||||||
| 2517 | } | - | ||||||||||||||||||||||||
| 2518 | - | |||||||||||||||||||||||||
| 2519 | /*! | - | ||||||||||||||||||||||||
| 2520 | Returns the weight of the matched window system font. | - | ||||||||||||||||||||||||
| 2521 | - | |||||||||||||||||||||||||
| 2522 | \sa QFont::weight(), bold() | - | ||||||||||||||||||||||||
| 2523 | */ | - | ||||||||||||||||||||||||
| 2524 | int QFontInfo::weight() const | - | ||||||||||||||||||||||||
| 2525 | { | - | ||||||||||||||||||||||||
| 2526 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2527 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2528 | return engine->fontDef.weight; | - | ||||||||||||||||||||||||
| 2529 | - | |||||||||||||||||||||||||
| 2530 | } | - | ||||||||||||||||||||||||
| 2531 | - | |||||||||||||||||||||||||
| 2532 | /*! | - | ||||||||||||||||||||||||
| 2533 | \fn bool QFontInfo::bold() const | - | ||||||||||||||||||||||||
| 2534 | - | |||||||||||||||||||||||||
| 2535 | Returns \c true if weight() would return a value greater than | - | ||||||||||||||||||||||||
| 2536 | QFont::Normal; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 2537 | - | |||||||||||||||||||||||||
| 2538 | \sa weight(), QFont::bold() | - | ||||||||||||||||||||||||
| 2539 | */ | - | ||||||||||||||||||||||||
| 2540 | - | |||||||||||||||||||||||||
| 2541 | /*! | - | ||||||||||||||||||||||||
| 2542 | Returns the underline value of the matched window system font. | - | ||||||||||||||||||||||||
| 2543 | - | |||||||||||||||||||||||||
| 2544 | \sa QFont::underline() | - | ||||||||||||||||||||||||
| 2545 | - | |||||||||||||||||||||||||
| 2546 | \internal | - | ||||||||||||||||||||||||
| 2547 | - | |||||||||||||||||||||||||
| 2548 | Here we read the underline flag directly from the QFont. | - | ||||||||||||||||||||||||
| 2549 | This is OK for X11 and for Windows because we always get what we want. | - | ||||||||||||||||||||||||
| 2550 | */ | - | ||||||||||||||||||||||||
| 2551 | bool QFontInfo::underline() const | - | ||||||||||||||||||||||||
| 2552 | { | - | ||||||||||||||||||||||||
| 2553 | return d->underline; | - | ||||||||||||||||||||||||
| 2554 | } | - | ||||||||||||||||||||||||
| 2555 | - | |||||||||||||||||||||||||
| 2556 | /*! | - | ||||||||||||||||||||||||
| 2557 | Returns the overline value of the matched window system font. | - | ||||||||||||||||||||||||
| 2558 | - | |||||||||||||||||||||||||
| 2559 | \sa QFont::overline() | - | ||||||||||||||||||||||||
| 2560 | - | |||||||||||||||||||||||||
| 2561 | \internal | - | ||||||||||||||||||||||||
| 2562 | - | |||||||||||||||||||||||||
| 2563 | Here we read the overline flag directly from the QFont. | - | ||||||||||||||||||||||||
| 2564 | This is OK for X11 and for Windows because we always get what we want. | - | ||||||||||||||||||||||||
| 2565 | */ | - | ||||||||||||||||||||||||
| 2566 | bool QFontInfo::overline() const | - | ||||||||||||||||||||||||
| 2567 | { | - | ||||||||||||||||||||||||
| 2568 | return d->overline; | - | ||||||||||||||||||||||||
| 2569 | } | - | ||||||||||||||||||||||||
| 2570 | - | |||||||||||||||||||||||||
| 2571 | /*! | - | ||||||||||||||||||||||||
| 2572 | Returns the strikeout value of the matched window system font. | - | ||||||||||||||||||||||||
| 2573 | - | |||||||||||||||||||||||||
| 2574 | \sa QFont::strikeOut() | - | ||||||||||||||||||||||||
| 2575 | - | |||||||||||||||||||||||||
| 2576 | \internal Here we read the strikeOut flag directly from the QFont. | - | ||||||||||||||||||||||||
| 2577 | This is OK for X11 and for Windows because we always get what we want. | - | ||||||||||||||||||||||||
| 2578 | */ | - | ||||||||||||||||||||||||
| 2579 | bool QFontInfo::strikeOut() const | - | ||||||||||||||||||||||||
| 2580 | { | - | ||||||||||||||||||||||||
| 2581 | return d->strikeOut; | - | ||||||||||||||||||||||||
| 2582 | } | - | ||||||||||||||||||||||||
| 2583 | - | |||||||||||||||||||||||||
| 2584 | /*! | - | ||||||||||||||||||||||||
| 2585 | Returns the fixed pitch value of the matched window system font. | - | ||||||||||||||||||||||||
| 2586 | - | |||||||||||||||||||||||||
| 2587 | \sa QFont::fixedPitch() | - | ||||||||||||||||||||||||
| 2588 | */ | - | ||||||||||||||||||||||||
| 2589 | bool QFontInfo::fixedPitch() const | - | ||||||||||||||||||||||||
| 2590 | { | - | ||||||||||||||||||||||||
| 2591 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2592 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2593 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
| 2594 | if (!engine->fontDef.fixedPitchComputed) { | - | ||||||||||||||||||||||||
| 2595 | QChar ch[2] = { QLatin1Char('i'), QLatin1Char('m') }; | - | ||||||||||||||||||||||||
| 2596 | QGlyphLayoutArray<2> g; | - | ||||||||||||||||||||||||
| 2597 | int l = 2; | - | ||||||||||||||||||||||||
| 2598 | if (!engine->stringToCMap(ch, 2, &g, &l, 0)) | - | ||||||||||||||||||||||||
| 2599 | Q_UNREACHABLE(); | - | ||||||||||||||||||||||||
| 2600 | Q_ASSERT(l == 2); | - | ||||||||||||||||||||||||
| 2601 | engine->fontDef.fixedPitch = g.advances[0] == g.advances[1]; | - | ||||||||||||||||||||||||
| 2602 | engine->fontDef.fixedPitchComputed = true; | - | ||||||||||||||||||||||||
| 2603 | } | - | ||||||||||||||||||||||||
| 2604 | #endif | - | ||||||||||||||||||||||||
| 2605 | return engine->fontDef.fixedPitch; | - | ||||||||||||||||||||||||
| 2606 | } | - | ||||||||||||||||||||||||
| 2607 | - | |||||||||||||||||||||||||
| 2608 | /*! | - | ||||||||||||||||||||||||
| 2609 | Returns the style of the matched window system font. | - | ||||||||||||||||||||||||
| 2610 | - | |||||||||||||||||||||||||
| 2611 | Currently only returns the style hint set in QFont. | - | ||||||||||||||||||||||||
| 2612 | - | |||||||||||||||||||||||||
| 2613 | \sa QFont::styleHint(), QFont::StyleHint | - | ||||||||||||||||||||||||
| 2614 | */ | - | ||||||||||||||||||||||||
| 2615 | QFont::StyleHint QFontInfo::styleHint() const | - | ||||||||||||||||||||||||
| 2616 | { | - | ||||||||||||||||||||||||
| 2617 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2618 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2619 | return (QFont::StyleHint) engine->fontDef.styleHint; | - | ||||||||||||||||||||||||
| 2620 | } | - | ||||||||||||||||||||||||
| 2621 | - | |||||||||||||||||||||||||
| 2622 | #if QT_DEPRECATED_SINCE(5, 5) | - | ||||||||||||||||||||||||
| 2623 | /*! | - | ||||||||||||||||||||||||
| 2624 | \deprecated | - | ||||||||||||||||||||||||
| 2625 | - | |||||||||||||||||||||||||
| 2626 | Returns \c true if the font is a raw mode font; otherwise returns | - | ||||||||||||||||||||||||
| 2627 | false. | - | ||||||||||||||||||||||||
| 2628 | - | |||||||||||||||||||||||||
| 2629 | If it is a raw mode font, all other functions in QFontInfo will | - | ||||||||||||||||||||||||
| 2630 | return the same values set in the QFont, regardless of the font | - | ||||||||||||||||||||||||
| 2631 | actually used. | - | ||||||||||||||||||||||||
| 2632 | - | |||||||||||||||||||||||||
| 2633 | \sa QFont::rawMode() | - | ||||||||||||||||||||||||
| 2634 | */ | - | ||||||||||||||||||||||||
| 2635 | bool QFontInfo::rawMode() const | - | ||||||||||||||||||||||||
| 2636 | { | - | ||||||||||||||||||||||||
| 2637 | return false; | - | ||||||||||||||||||||||||
| 2638 | } | - | ||||||||||||||||||||||||
| 2639 | #endif | - | ||||||||||||||||||||||||
| 2640 | - | |||||||||||||||||||||||||
| 2641 | /*! | - | ||||||||||||||||||||||||
| 2642 | Returns \c true if the matched window system font is exactly the same | - | ||||||||||||||||||||||||
| 2643 | as the one specified by the font; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 2644 | - | |||||||||||||||||||||||||
| 2645 | \sa QFont::exactMatch() | - | ||||||||||||||||||||||||
| 2646 | */ | - | ||||||||||||||||||||||||
| 2647 | bool QFontInfo::exactMatch() const | - | ||||||||||||||||||||||||
| 2648 | { | - | ||||||||||||||||||||||||
| 2649 | QFontEngine *engine = d->engineForScript(QChar::Script_Common); | - | ||||||||||||||||||||||||
| 2650 | Q_ASSERT(engine != 0); | - | ||||||||||||||||||||||||
| 2651 | return d->request.exactMatch(engine->fontDef); | - | ||||||||||||||||||||||||
| 2652 | } | - | ||||||||||||||||||||||||
| 2653 | - | |||||||||||||||||||||||||
| 2654 | - | |||||||||||||||||||||||||
| 2655 | - | |||||||||||||||||||||||||
| 2656 | - | |||||||||||||||||||||||||
| 2657 | // ********************************************************************** | - | ||||||||||||||||||||||||
| 2658 | // QFontCache | - | ||||||||||||||||||||||||
| 2659 | // ********************************************************************** | - | ||||||||||||||||||||||||
| 2660 | - | |||||||||||||||||||||||||
| 2661 | #ifdef QFONTCACHE_DEBUG | - | ||||||||||||||||||||||||
| 2662 | // fast timeouts for debugging | - | ||||||||||||||||||||||||
| 2663 | static const int fast_timeout = 1000; // 1s | - | ||||||||||||||||||||||||
| 2664 | static const int slow_timeout = 5000; // 5s | - | ||||||||||||||||||||||||
| 2665 | #else | - | ||||||||||||||||||||||||
| 2666 | static const int fast_timeout = 10000; // 10s | - | ||||||||||||||||||||||||
| 2667 | static const int slow_timeout = 300000; // 5m | - | ||||||||||||||||||||||||
| 2668 | #endif // QFONTCACHE_DEBUG | - | ||||||||||||||||||||||||
| 2669 | - | |||||||||||||||||||||||||
| 2670 | const uint QFontCache::min_cost = 4*1024; // 4mb | - | ||||||||||||||||||||||||
| 2671 | - | |||||||||||||||||||||||||
| 2672 | #ifdef QT_NO_THREAD | - | ||||||||||||||||||||||||
| 2673 | Q_GLOBAL_STATIC(QFontCache, theFontCache) | - | ||||||||||||||||||||||||
| 2674 | - | |||||||||||||||||||||||||
| 2675 | QFontCache *QFontCache::instance() | - | ||||||||||||||||||||||||
| 2676 | { | - | ||||||||||||||||||||||||
| 2677 | return theFontCache(); | - | ||||||||||||||||||||||||
| 2678 | } | - | ||||||||||||||||||||||||
| 2679 | - | |||||||||||||||||||||||||
| 2680 | void QFontCache::cleanup() | - | ||||||||||||||||||||||||
| 2681 | { | - | ||||||||||||||||||||||||
| 2682 | } | - | ||||||||||||||||||||||||
| 2683 | #else | - | ||||||||||||||||||||||||
| 2684 | Q_GLOBAL_STATIC(QThreadStorage<QFontCache *>, theFontCache) | - | ||||||||||||||||||||||||
| 2685 | - | |||||||||||||||||||||||||
| 2686 | QFontCache *QFontCache::instance() | - | ||||||||||||||||||||||||
| 2687 | { | - | ||||||||||||||||||||||||
| 2688 | QFontCache *&fontCache = theFontCache()->localData(); | - | ||||||||||||||||||||||||
| 2689 | if (!fontCache) | - | ||||||||||||||||||||||||
| 2690 | fontCache = new QFontCache; | - | ||||||||||||||||||||||||
| 2691 | return fontCache; | - | ||||||||||||||||||||||||
| 2692 | } | - | ||||||||||||||||||||||||
| 2693 | - | |||||||||||||||||||||||||
| 2694 | void QFontCache::cleanup() | - | ||||||||||||||||||||||||
| 2695 | { | - | ||||||||||||||||||||||||
| 2696 | QThreadStorage<QFontCache *> *cache = 0; | - | ||||||||||||||||||||||||
| 2697 | QT_TRY { | - | ||||||||||||||||||||||||
| 2698 | cache = theFontCache(); | - | ||||||||||||||||||||||||
| 2699 | } QT_CATCH (const std::bad_alloc &) { dead code: { } | - | ||||||||||||||||||||||||
| 2700 | // no cache - just ignore dead code: { } | - | ||||||||||||||||||||||||
| 2701 | } dead code: { } | - | ||||||||||||||||||||||||
| 2702 | if (cache && cache->hasLocalData()) | - | ||||||||||||||||||||||||
| 2703 | cache->setLocalData(0); | - | ||||||||||||||||||||||||
| 2704 | } | - | ||||||||||||||||||||||||
| 2705 | #endif // QT_NO_THREAD | - | ||||||||||||||||||||||||
| 2706 | - | |||||||||||||||||||||||||
| 2707 | QBasicAtomicInt font_cache_id = Q_BASIC_ATOMIC_INITIALIZER(1); | - | ||||||||||||||||||||||||
| 2708 | - | |||||||||||||||||||||||||
| 2709 | QFontCache::QFontCache() | - | ||||||||||||||||||||||||
| 2710 | : QObject(), total_cost(0), max_cost(min_cost), | - | ||||||||||||||||||||||||
| 2711 | current_timestamp(0), fast(false), timer_id(-1), | - | ||||||||||||||||||||||||
| 2712 | m_id(font_cache_id.fetchAndAddRelaxed(1)) | - | ||||||||||||||||||||||||
| 2713 | { | - | ||||||||||||||||||||||||
| 2714 | } | - | ||||||||||||||||||||||||
| 2715 | - | |||||||||||||||||||||||||
| 2716 | QFontCache::~QFontCache() | - | ||||||||||||||||||||||||
| 2717 | { | - | ||||||||||||||||||||||||
| 2718 | clear(); | - | ||||||||||||||||||||||||
| 2719 | } | - | ||||||||||||||||||||||||
| 2720 | - | |||||||||||||||||||||||||
| 2721 | void QFontCache::clear() | - | ||||||||||||||||||||||||
| 2722 | { | - | ||||||||||||||||||||||||
| 2723 | { | - | ||||||||||||||||||||||||
| 2724 | EngineDataCache::Iterator it = engineDataCache.begin(), | - | ||||||||||||||||||||||||
| 2725 | end = engineDataCache.end(); | - | ||||||||||||||||||||||||
| 2726 | while (it != end) { | - | ||||||||||||||||||||||||
| 2727 | QFontEngineData *data = it.value(); | - | ||||||||||||||||||||||||
| 2728 | for (int i = 0; i < QChar::ScriptCount; ++i) { | - | ||||||||||||||||||||||||
| 2729 | if (data->engines[i]) { | - | ||||||||||||||||||||||||
| 2730 | if (!data->engines[i]->ref.deref()) { | - | ||||||||||||||||||||||||
| 2731 | Q_ASSERT(engineCacheCount.value(data->engines[i]) == 0); | - | ||||||||||||||||||||||||
| 2732 | delete data->engines[i]; | - | ||||||||||||||||||||||||
| 2733 | } | - | ||||||||||||||||||||||||
| 2734 | data->engines[i] = 0; | - | ||||||||||||||||||||||||
| 2735 | } | - | ||||||||||||||||||||||||
| 2736 | } | - | ||||||||||||||||||||||||
| 2737 | if (!data->ref.deref()) { | - | ||||||||||||||||||||||||
| 2738 | delete data; | - | ||||||||||||||||||||||||
| 2739 | } else { | - | ||||||||||||||||||||||||
| 2740 | FC_DEBUG("QFontCache::clear: engineData %p still has refcount %d", dead code: QMessageLogger(__FILE__, 2740, __PRETTY_FUNCTION__).debug("QFontCache::clear: engineData %p still has refcount %d", data, data->ref.load()); | - | ||||||||||||||||||||||||
| 2741 | data, data->ref.load()); dead code: QMessageLogger(__FILE__, 2740, __PRETTY_FUNCTION__).debug("QFontCache::clear: engineData %p still has refcount %d", data, data->ref.load()); | - | ||||||||||||||||||||||||
| 2742 | } | - | ||||||||||||||||||||||||
| 2743 | ++it; | - | ||||||||||||||||||||||||
| 2744 | } | - | ||||||||||||||||||||||||
| 2745 | } | - | ||||||||||||||||||||||||
| 2746 | - | |||||||||||||||||||||||||
| 2747 | engineDataCache.clear(); | - | ||||||||||||||||||||||||
| 2748 | - | |||||||||||||||||||||||||
| 2749 | - | |||||||||||||||||||||||||
| 2750 | bool mightHaveEnginesLeftForCleanup; | - | ||||||||||||||||||||||||
| 2751 | do { | - | ||||||||||||||||||||||||
| 2752 | mightHaveEnginesLeftForCleanup = false; | - | ||||||||||||||||||||||||
| 2753 | for (EngineCache::Iterator it = engineCache.begin(), end = engineCache.end(); | - | ||||||||||||||||||||||||
| 2754 | it != end; ++it) { | - | ||||||||||||||||||||||||
| 2755 | QFontEngine *engine = it.value().data; | - | ||||||||||||||||||||||||
| 2756 | if (engine) { | - | ||||||||||||||||||||||||
| 2757 | const int cacheCount = --engineCacheCount[engine]; | - | ||||||||||||||||||||||||
| 2758 | Q_ASSERT(cacheCount >= 0); | - | ||||||||||||||||||||||||
| 2759 | if (!engine->ref.deref()) { | - | ||||||||||||||||||||||||
| 2760 | Q_ASSERT(cacheCount == 0); | - | ||||||||||||||||||||||||
| 2761 | mightHaveEnginesLeftForCleanup = engine->type() == QFontEngine::Multi; | - | ||||||||||||||||||||||||
| 2762 | delete engine; | - | ||||||||||||||||||||||||
| 2763 | } else if (cacheCount == 0) { | - | ||||||||||||||||||||||||
| 2764 | FC_DEBUG("QFontCache::clear: engine %p still has refcount %d", dead code: QMessageLogger(__FILE__, 2764, __PRETTY_FUNCTION__).debug("QFontCache::clear: engine %p still has refcount %d", engine, engine->ref.load()); | - | ||||||||||||||||||||||||
| 2765 | engine, engine->ref.load()); dead code: QMessageLogger(__FILE__, 2764, __PRETTY_FUNCTION__).debug("QFontCache::clear: engine %p still has refcount %d", engine, engine->ref.load()); | - | ||||||||||||||||||||||||
| 2766 | } | - | ||||||||||||||||||||||||
| 2767 | it.value().data = 0; | - | ||||||||||||||||||||||||
| 2768 | } | - | ||||||||||||||||||||||||
| 2769 | } | - | ||||||||||||||||||||||||
| 2770 | } while (mightHaveEnginesLeftForCleanup); | - | ||||||||||||||||||||||||
| 2771 | - | |||||||||||||||||||||||||
| 2772 | engineCache.clear(); | - | ||||||||||||||||||||||||
| 2773 | engineCacheCount.clear(); | - | ||||||||||||||||||||||||
| 2774 | - | |||||||||||||||||||||||||
| 2775 | - | |||||||||||||||||||||||||
| 2776 | total_cost = 0; | - | ||||||||||||||||||||||||
| 2777 | max_cost = min_cost; | - | ||||||||||||||||||||||||
| 2778 | } | - | ||||||||||||||||||||||||
| 2779 | - | |||||||||||||||||||||||||
| 2780 | - | |||||||||||||||||||||||||
| 2781 | QFontEngineData *QFontCache::findEngineData(const QFontDef &def) const | - | ||||||||||||||||||||||||
| 2782 | { | - | ||||||||||||||||||||||||
| 2783 | EngineDataCache::ConstIterator it = engineDataCache.constFind(def); | - | ||||||||||||||||||||||||
| 2784 | if (it == engineDataCache.constEnd()) | - | ||||||||||||||||||||||||
| 2785 | return 0; | - | ||||||||||||||||||||||||
| 2786 | - | |||||||||||||||||||||||||
| 2787 | // found | - | ||||||||||||||||||||||||
| 2788 | return it.value(); | - | ||||||||||||||||||||||||
| 2789 | } | - | ||||||||||||||||||||||||
| 2790 | - | |||||||||||||||||||||||||
| 2791 | void QFontCache::insertEngineData(const QFontDef &def, QFontEngineData *engineData) | - | ||||||||||||||||||||||||
| 2792 | { | - | ||||||||||||||||||||||||
| 2793 | #ifdef QFONTCACHE_DEBUG | - | ||||||||||||||||||||||||
| 2794 | FC_DEBUG("QFontCache: inserting new engine data %p", engineData); | - | ||||||||||||||||||||||||
| 2795 | if (engineDataCache.contains(def)) { | - | ||||||||||||||||||||||||
| 2796 | FC_DEBUG(" QFontCache already contains engine data %p for key=(%g %g %d %d %d)", | - | ||||||||||||||||||||||||
| 2797 | engineDataCache.value(def), def.pointSize, | - | ||||||||||||||||||||||||
| 2798 | def.pixelSize, def.weight, def.style, def.fixedPitch); | - | ||||||||||||||||||||||||
| 2799 | } | - | ||||||||||||||||||||||||
| 2800 | #endif | - | ||||||||||||||||||||||||
| 2801 | Q_ASSERT(!engineDataCache.contains(def)); | - | ||||||||||||||||||||||||
| 2802 | - | |||||||||||||||||||||||||
| 2803 | engineData->ref.ref(); | - | ||||||||||||||||||||||||
| 2804 | // Decrease now rather than waiting | - | ||||||||||||||||||||||||
| 2805 | if (total_cost > min_cost * 2 && engineDataCache.size() >= QFONTCACHE_DECREASE_TRIGGER_LIMIT) | - | ||||||||||||||||||||||||
| 2806 | decreaseCache(); | - | ||||||||||||||||||||||||
| 2807 | - | |||||||||||||||||||||||||
| 2808 | engineDataCache.insert(def, engineData); | - | ||||||||||||||||||||||||
| 2809 | increaseCost(sizeof(QFontEngineData)); | - | ||||||||||||||||||||||||
| 2810 | } | - | ||||||||||||||||||||||||
| 2811 | - | |||||||||||||||||||||||||
| 2812 | QFontEngine *QFontCache::findEngine(const Key &key) | - | ||||||||||||||||||||||||
| 2813 | { | - | ||||||||||||||||||||||||
| 2814 | EngineCache::Iterator it = engineCache.find(key), | - | ||||||||||||||||||||||||
| 2815 | end = engineCache.end(); | - | ||||||||||||||||||||||||
| 2816 | if (it == end) return 0; | - | ||||||||||||||||||||||||
| 2817 | - | |||||||||||||||||||||||||
| 2818 | Q_ASSERT(it.value().data != Q_NULLPTR); | - | ||||||||||||||||||||||||
| 2819 | Q_ASSERT(key.multi == (it.value().data->type() == QFontEngine::Multi)); | - | ||||||||||||||||||||||||
| 2820 | - | |||||||||||||||||||||||||
| 2821 | // found... update the hitcount and timestamp | - | ||||||||||||||||||||||||
| 2822 | updateHitCountAndTimeStamp(it.value()); | - | ||||||||||||||||||||||||
| 2823 | - | |||||||||||||||||||||||||
| 2824 | return it.value().data; | - | ||||||||||||||||||||||||
| 2825 | } | - | ||||||||||||||||||||||||
| 2826 | - | |||||||||||||||||||||||||
| 2827 | void QFontCache::updateHitCountAndTimeStamp(Engine &value) | - | ||||||||||||||||||||||||
| 2828 | { | - | ||||||||||||||||||||||||
| 2829 | value.hits++; | - | ||||||||||||||||||||||||
| 2830 | value.timestamp = ++current_timestamp; | - | ||||||||||||||||||||||||
| 2831 | - | |||||||||||||||||||||||||
| 2832 | FC_DEBUG("QFontCache: found font engine\n" dead code: QMessageLogger(__FILE__, 2832, __PRETTY_FUNCTION__).debug("QFontCache: found font engine\n" " %p: timestamp %4u hits %3u ref %2d/%2d, type %d", value.data, value.timestamp, value.hits, value.data->ref.load(), engineCacheCount.value(value.data), value.data->type()); | - | ||||||||||||||||||||||||
| 2833 | " %p: timestamp %4u hits %3u ref %2d/%2d, type %d", dead code: QMessageLogger(__FILE__, 2832, __PRETTY_FUNCTION__).debug("QFontCache: found font engine\n" " %p: timestamp %4u hits %3u ref %2d/%2d, type %d", value.data, value.timestamp, value.hits, value.data->ref.load(), engineCacheCount.value(value.data), value.data->type()); | - | ||||||||||||||||||||||||
| 2834 | value.data, value.timestamp, value.hits, dead code: QMessageLogger(__FILE__, 2832, __PRETTY_FUNCTION__).debug("QFontCache: found font engine\n" " %p: timestamp %4u hits %3u ref %2d/%2d, type %d", value.data, value.timestamp, value.hits, value.data->ref.load(), engineCacheCount.value(value.data), value.data->type()); | - | ||||||||||||||||||||||||
| 2835 | value.data->ref.load(), engineCacheCount.value(value.data), dead code: QMessageLogger(__FILE__, 2832, __PRETTY_FUNCTION__).debug("QFontCache: found font engine\n" " %p: timestamp %4u hits %3u ref %2d/%2d, type %d", value.data, value.timestamp, value.hits, value.data->ref.load(), engineCacheCount.value(value.data), value.data->type()); | - | ||||||||||||||||||||||||
| 2836 | value.data->type()); dead code: QMessageLogger(__FILE__, 2832, __PRETTY_FUNCTION__).debug("QFontCache: found font engine\n" " %p: timestamp %4u hits %3u ref %2d/%2d, type %d", value.data, value.timestamp, value.hits, value.data->ref.load(), engineCacheCount.value(value.data), value.data->type()); | - | ||||||||||||||||||||||||
| 2837 | } | - | ||||||||||||||||||||||||
| 2838 | - | |||||||||||||||||||||||||
| 2839 | void QFontCache::insertEngine(const Key &key, QFontEngine *engine, bool insertMulti) | - | ||||||||||||||||||||||||
| 2840 | { | - | ||||||||||||||||||||||||
| 2841 | Q_ASSERT(engine != Q_NULLPTR); | - | ||||||||||||||||||||||||
| 2842 | Q_ASSERT(key.multi == (engine->type() == QFontEngine::Multi)); | - | ||||||||||||||||||||||||
| 2843 | - | |||||||||||||||||||||||||
| 2844 | #ifdef QFONTCACHE_DEBUG | - | ||||||||||||||||||||||||
| 2845 | FC_DEBUG("QFontCache: inserting new engine %p, refcount %d", engine, engine->ref.load()); | - | ||||||||||||||||||||||||
| 2846 | if (!insertMulti && engineCache.contains(key)) { | - | ||||||||||||||||||||||||
| 2847 | FC_DEBUG(" QFontCache already contains engine %p for key=(%g %g %d %d %d)", | - | ||||||||||||||||||||||||
| 2848 | engineCache.value(key).data, key.def.pointSize, | - | ||||||||||||||||||||||||
| 2849 | key.def.pixelSize, key.def.weight, key.def.style, key.def.fixedPitch); | - | ||||||||||||||||||||||||
| 2850 | } | - | ||||||||||||||||||||||||
| 2851 | #endif | - | ||||||||||||||||||||||||
| 2852 | engine->ref.ref(); | - | ||||||||||||||||||||||||
| 2853 | // Decrease now rather than waiting | - | ||||||||||||||||||||||||
| 2854 | if (total_cost > min_cost * 2 && engineCache.size() >= QFONTCACHE_DECREASE_TRIGGER_LIMIT) | - | ||||||||||||||||||||||||
| 2855 | decreaseCache(); | - | ||||||||||||||||||||||||
| 2856 | - | |||||||||||||||||||||||||
| 2857 | Engine data(engine); | - | ||||||||||||||||||||||||
| 2858 | data.timestamp = ++current_timestamp; | - | ||||||||||||||||||||||||
| 2859 | - | |||||||||||||||||||||||||
| 2860 | if (insertMulti) | - | ||||||||||||||||||||||||
| 2861 | engineCache.insertMulti(key, data); | - | ||||||||||||||||||||||||
| 2862 | else | - | ||||||||||||||||||||||||
| 2863 | engineCache.insert(key, data); | - | ||||||||||||||||||||||||
| 2864 | // only increase the cost if this is the first time we insert the engine | - | ||||||||||||||||||||||||
| 2865 | if (++engineCacheCount[engine] == 1) | - | ||||||||||||||||||||||||
| 2866 | increaseCost(engine->cache_cost); | - | ||||||||||||||||||||||||
| 2867 | } | - | ||||||||||||||||||||||||
| 2868 | - | |||||||||||||||||||||||||
| 2869 | void QFontCache::increaseCost(uint cost) | - | ||||||||||||||||||||||||
| 2870 | { | - | ||||||||||||||||||||||||
| 2871 | cost = (cost + 512) / 1024; // store cost in kb | - | ||||||||||||||||||||||||
| 2872 | cost = cost > 0 ? cost : 1; | - | ||||||||||||||||||||||||
| 2873 | total_cost += cost; | - | ||||||||||||||||||||||||
| 2874 | - | |||||||||||||||||||||||||
| 2875 | FC_DEBUG(" COST: increased %u kb, total_cost %u kb, max_cost %u kb", dead code: QMessageLogger(__FILE__, 2875, __PRETTY_FUNCTION__).debug(" COST: increased %u kb, total_cost %u kb, max_cost %u kb", cost, total_cost, max_cost); | - | ||||||||||||||||||||||||
| 2876 | cost, total_cost, max_cost); dead code: QMessageLogger(__FILE__, 2875, __PRETTY_FUNCTION__).debug(" COST: increased %u kb, total_cost %u kb, max_cost %u kb", cost, total_cost, max_cost); | - | ||||||||||||||||||||||||
| 2877 | - | |||||||||||||||||||||||||
| 2878 | if (total_cost > max_cost) { | - | ||||||||||||||||||||||||
| 2879 | max_cost = total_cost; | - | ||||||||||||||||||||||||
| 2880 | - | |||||||||||||||||||||||||
| 2881 | if (timer_id == -1 || ! fast) { | - | ||||||||||||||||||||||||
| 2882 | FC_DEBUG(" TIMER: starting fast timer (%d ms)", fast_timeout); dead code: QMessageLogger(__FILE__, 2882, __PRETTY_FUNCTION__).debug(" TIMER: starting fast timer (%d ms)", fast_timeout); | - | ||||||||||||||||||||||||
| 2883 | - | |||||||||||||||||||||||||
| 2884 | if (timer_id != -1) killTimer(timer_id); | - | ||||||||||||||||||||||||
| 2885 | timer_id = startTimer(fast_timeout); | - | ||||||||||||||||||||||||
| 2886 | fast = true; | - | ||||||||||||||||||||||||
| 2887 | } | - | ||||||||||||||||||||||||
| 2888 | } | - | ||||||||||||||||||||||||
| 2889 | } | - | ||||||||||||||||||||||||
| 2890 | - | |||||||||||||||||||||||||
| 2891 | void QFontCache::decreaseCost(uint cost) | - | ||||||||||||||||||||||||
| 2892 | { | - | ||||||||||||||||||||||||
| 2893 | cost = (cost + 512) / 1024; // cost is stored in kb | - | ||||||||||||||||||||||||
| 2894 | cost = cost > 0 ? cost : 1; | - | ||||||||||||||||||||||||
| 2895 | Q_ASSERT(cost <= total_cost); | - | ||||||||||||||||||||||||
| 2896 | total_cost -= cost; | - | ||||||||||||||||||||||||
| 2897 | - | |||||||||||||||||||||||||
| 2898 | FC_DEBUG(" COST: decreased %u kb, total_cost %u kb, max_cost %u kb", dead code: QMessageLogger(__FILE__, 2898, __PRETTY_FUNCTION__).debug(" COST: decreased %u kb, total_cost %u kb, max_cost %u kb", cost, total_cost, max_cost); | - | ||||||||||||||||||||||||
| 2899 | cost, total_cost, max_cost); dead code: QMessageLogger(__FILE__, 2898, __PRETTY_FUNCTION__).debug(" COST: decreased %u kb, total_cost %u kb, max_cost %u kb", cost, total_cost, max_cost); | - | ||||||||||||||||||||||||
| 2900 | } | - | ||||||||||||||||||||||||
| 2901 | - | |||||||||||||||||||||||||
| 2902 | void QFontCache::timerEvent(QTimerEvent *) | - | ||||||||||||||||||||||||
| 2903 | { | - | ||||||||||||||||||||||||
| 2904 | FC_DEBUG("QFontCache::timerEvent: performing cache maintenance (timestamp %u)", dead code: QMessageLogger(__FILE__, 2904, __PRETTY_FUNCTION__).debug("QFontCache::timerEvent: performing cache maintenance (timestamp %u)", current_timestamp); | - | ||||||||||||||||||||||||
| 2905 | current_timestamp); dead code: QMessageLogger(__FILE__, 2904, __PRETTY_FUNCTION__).debug("QFontCache::timerEvent: performing cache maintenance (timestamp %u)", current_timestamp); | - | ||||||||||||||||||||||||
| 2906 | - | |||||||||||||||||||||||||
| 2907 | if (total_cost <= max_cost && max_cost <= min_cost) { | - | ||||||||||||||||||||||||
| 2908 | FC_DEBUG(" cache redused sufficiently, stopping timer"); dead code: QMessageLogger(__FILE__, 2908, __PRETTY_FUNCTION__).debug(" cache redused sufficiently, stopping timer"); | - | ||||||||||||||||||||||||
| 2909 | - | |||||||||||||||||||||||||
| 2910 | killTimer(timer_id); | - | ||||||||||||||||||||||||
| 2911 | timer_id = -1; | - | ||||||||||||||||||||||||
| 2912 | fast = false; | - | ||||||||||||||||||||||||
| 2913 | - | |||||||||||||||||||||||||
| 2914 | return; | - | ||||||||||||||||||||||||
| 2915 | } | - | ||||||||||||||||||||||||
| 2916 | decreaseCache(); | - | ||||||||||||||||||||||||
| 2917 | } | - | ||||||||||||||||||||||||
| 2918 | - | |||||||||||||||||||||||||
| 2919 | void QFontCache::decreaseCache() | - | ||||||||||||||||||||||||
| 2920 | { | - | ||||||||||||||||||||||||
| 2921 | // go through the cache and count up everything in use | - | ||||||||||||||||||||||||
| 2922 | uint in_use_cost = 0; | - | ||||||||||||||||||||||||
| 2923 | - | |||||||||||||||||||||||||
| 2924 | { | - | ||||||||||||||||||||||||
| 2925 | FC_DEBUG(" SWEEP engine data:"); dead code: QMessageLogger(__FILE__, 2925, __PRETTY_FUNCTION__).debug(" SWEEP engine data:"); | - | ||||||||||||||||||||||||
| 2926 | - | |||||||||||||||||||||||||
| 2927 | // make sure the cost of each engine data is at least 1kb | - | ||||||||||||||||||||||||
| 2928 | const uint engine_data_cost = | - | ||||||||||||||||||||||||
| 2929 | sizeof(QFontEngineData) > 1024 ? sizeof(QFontEngineData) : 1024; | - | ||||||||||||||||||||||||
| 2930 | - | |||||||||||||||||||||||||
| 2931 | EngineDataCache::ConstIterator it = engineDataCache.constBegin(), | - | ||||||||||||||||||||||||
| 2932 | end = engineDataCache.constEnd(); | - | ||||||||||||||||||||||||
| 2933 | for (; it != end; ++it) { | - | ||||||||||||||||||||||||
| 2934 | FC_DEBUG(" %p: ref %2d", it.value(), int(it.value()->ref.load())); dead code: QMessageLogger(__FILE__, 2934, __PRETTY_FUNCTION__).debug(" %p: ref %2d", it.value(), int(it.value()->ref.load())); | - | ||||||||||||||||||||||||
| 2935 | - | |||||||||||||||||||||||||
| 2936 | if (it.value()->ref.load() != 1) | - | ||||||||||||||||||||||||
| 2937 | in_use_cost += engine_data_cost; | - | ||||||||||||||||||||||||
| 2938 | } | - | ||||||||||||||||||||||||
| 2939 | } | - | ||||||||||||||||||||||||
| 2940 | - | |||||||||||||||||||||||||
| 2941 | { | - | ||||||||||||||||||||||||
| 2942 | FC_DEBUG(" SWEEP engine:"); dead code: QMessageLogger(__FILE__, 2942, __PRETTY_FUNCTION__).debug(" SWEEP engine:"); | - | ||||||||||||||||||||||||
| 2943 | - | |||||||||||||||||||||||||
| 2944 | EngineCache::ConstIterator it = engineCache.constBegin(), | - | ||||||||||||||||||||||||
| 2945 | end = engineCache.constEnd(); | - | ||||||||||||||||||||||||
| 2946 | for (; it != end; ++it) { | - | ||||||||||||||||||||||||
| 2947 | FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", dead code: QMessageLogger(__FILE__, 2947, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->cache_cost); | - | ||||||||||||||||||||||||
| 2948 | it.value().data, it.value().timestamp, it.value().hits, dead code: QMessageLogger(__FILE__, 2947, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->cache_cost); | - | ||||||||||||||||||||||||
| 2949 | it.value().data->ref.load(), engineCacheCount.value(it.value().data), dead code: QMessageLogger(__FILE__, 2947, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->cache_cost); | - | ||||||||||||||||||||||||
| 2950 | it.value().data->cache_cost); dead code: QMessageLogger(__FILE__, 2947, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->cache_cost); | - | ||||||||||||||||||||||||
| 2951 | - | |||||||||||||||||||||||||
| 2952 | if (it.value().data->ref.load() != 0) | - | ||||||||||||||||||||||||
| 2953 | in_use_cost += it.value().data->cache_cost / engineCacheCount.value(it.value().data); | - | ||||||||||||||||||||||||
| 2954 | } | - | ||||||||||||||||||||||||
| 2955 | - | |||||||||||||||||||||||||
| 2956 | // attempt to make up for rounding errors | - | ||||||||||||||||||||||||
| 2957 | in_use_cost += engineCache.size(); | - | ||||||||||||||||||||||||
| 2958 | } | - | ||||||||||||||||||||||||
| 2959 | - | |||||||||||||||||||||||||
| 2960 | in_use_cost = (in_use_cost + 512) / 1024; // cost is stored in kb | - | ||||||||||||||||||||||||
| 2961 | - | |||||||||||||||||||||||||
| 2962 | /* | - | ||||||||||||||||||||||||
| 2963 | calculate the new maximum cost for the cache | - | ||||||||||||||||||||||||
| 2964 | - | |||||||||||||||||||||||||
| 2965 | NOTE: in_use_cost is *not* correct due to rounding errors in the | - | ||||||||||||||||||||||||
| 2966 | above algorithm. instead of worrying about getting the | - | ||||||||||||||||||||||||
| 2967 | calculation correct, we are more interested in speed, and use | - | ||||||||||||||||||||||||
| 2968 | in_use_cost as a floor for new_max_cost | - | ||||||||||||||||||||||||
| 2969 | */ | - | ||||||||||||||||||||||||
| 2970 | uint new_max_cost = qMax(qMax(max_cost / 2, in_use_cost), min_cost); | - | ||||||||||||||||||||||||
| 2971 | - | |||||||||||||||||||||||||
| 2972 | FC_DEBUG(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", dead code: QMessageLogger(__FILE__, 2972, __PRETTY_FUNCTION__).debug(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", in_use_cost, total_cost, max_cost, new_max_cost); | - | ||||||||||||||||||||||||
| 2973 | in_use_cost, total_cost, max_cost, new_max_cost); dead code: QMessageLogger(__FILE__, 2972, __PRETTY_FUNCTION__).debug(" after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", in_use_cost, total_cost, max_cost, new_max_cost); | - | ||||||||||||||||||||||||
| 2974 | - | |||||||||||||||||||||||||
| 2975 | if (new_max_cost == max_cost) { | - | ||||||||||||||||||||||||
| 2976 | if (fast) { | - | ||||||||||||||||||||||||
| 2977 | FC_DEBUG(" cannot shrink cache, slowing timer"); dead code: QMessageLogger(__FILE__, 2977, __PRETTY_FUNCTION__).debug(" cannot shrink cache, slowing timer"); | - | ||||||||||||||||||||||||
| 2978 | - | |||||||||||||||||||||||||
| 2979 | killTimer(timer_id); | - | ||||||||||||||||||||||||
| 2980 | timer_id = startTimer(slow_timeout); | - | ||||||||||||||||||||||||
| 2981 | fast = false; | - | ||||||||||||||||||||||||
| 2982 | } | - | ||||||||||||||||||||||||
| 2983 | - | |||||||||||||||||||||||||
| 2984 | return; | - | ||||||||||||||||||||||||
| 2985 | } else if (! fast) { | - | ||||||||||||||||||||||||
| 2986 | FC_DEBUG(" dropping into passing gear"); dead code: QMessageLogger(__FILE__, 2986, __PRETTY_FUNCTION__).debug(" dropping into passing gear"); | - | ||||||||||||||||||||||||
| 2987 | - | |||||||||||||||||||||||||
| 2988 | killTimer(timer_id); | - | ||||||||||||||||||||||||
| 2989 | timer_id = startTimer(fast_timeout); | - | ||||||||||||||||||||||||
| 2990 | fast = true; | - | ||||||||||||||||||||||||
| 2991 | } | - | ||||||||||||||||||||||||
| 2992 | - | |||||||||||||||||||||||||
| 2993 | max_cost = new_max_cost; | - | ||||||||||||||||||||||||
| 2994 | - | |||||||||||||||||||||||||
| 2995 | { | - | ||||||||||||||||||||||||
| 2996 | FC_DEBUG(" CLEAN engine data:"); dead code: QMessageLogger(__FILE__, 2996, __PRETTY_FUNCTION__).debug(" CLEAN engine data:"); | - | ||||||||||||||||||||||||
| 2997 | - | |||||||||||||||||||||||||
| 2998 | // clean out all unused engine data | - | ||||||||||||||||||||||||
| 2999 | EngineDataCache::Iterator it = engineDataCache.begin(); | - | ||||||||||||||||||||||||
| 3000 | while (it != engineDataCache.end()) { | - | ||||||||||||||||||||||||
| 3001 | if (it.value()->ref.load() == 1) { | - | ||||||||||||||||||||||||
| 3002 | FC_DEBUG(" %p", it.value()); dead code: QMessageLogger(__FILE__, 3002, __PRETTY_FUNCTION__).debug(" %p", it.value()); | - | ||||||||||||||||||||||||
| 3003 | decreaseCost(sizeof(QFontEngineData)); | - | ||||||||||||||||||||||||
| 3004 | it.value()->ref.deref(); | - | ||||||||||||||||||||||||
| 3005 | delete it.value(); | - | ||||||||||||||||||||||||
| 3006 | it = engineDataCache.erase(it); | - | ||||||||||||||||||||||||
| 3007 | } else { | - | ||||||||||||||||||||||||
| 3008 | ++it; | - | ||||||||||||||||||||||||
| 3009 | } | - | ||||||||||||||||||||||||
| 3010 | } | - | ||||||||||||||||||||||||
| 3011 | } | - | ||||||||||||||||||||||||
| 3012 | - | |||||||||||||||||||||||||
| 3013 | FC_DEBUG(" CLEAN engine:"); dead code: QMessageLogger(__FILE__, 3013, __PRETTY_FUNCTION__).debug(" CLEAN engine:"); | - | ||||||||||||||||||||||||
| 3014 | - | |||||||||||||||||||||||||
| 3015 | // clean out the engine cache just enough to get below our new max cost | - | ||||||||||||||||||||||||
| 3016 | bool cost_decreased; | - | ||||||||||||||||||||||||
| 3017 | do { | - | ||||||||||||||||||||||||
| 3018 | cost_decreased = false; | - | ||||||||||||||||||||||||
| 3019 | - | |||||||||||||||||||||||||
| 3020 | EngineCache::Iterator it = engineCache.begin(), | - | ||||||||||||||||||||||||
| 3021 | end = engineCache.end(); | - | ||||||||||||||||||||||||
| 3022 | // determine the oldest and least popular of the unused engines | - | ||||||||||||||||||||||||
| 3023 | uint oldest = ~0u; | - | ||||||||||||||||||||||||
| 3024 | uint least_popular = ~0u; | - | ||||||||||||||||||||||||
| 3025 | - | |||||||||||||||||||||||||
| 3026 | EngineCache::Iterator jt = end; | - | ||||||||||||||||||||||||
| 3027 | - | |||||||||||||||||||||||||
| 3028 | for ( ; it != end; ++it) { | - | ||||||||||||||||||||||||
| 3029 | if (it.value().data->ref.load() != engineCacheCount.value(it.value().data)) | - | ||||||||||||||||||||||||
| 3030 | continue; | - | ||||||||||||||||||||||||
| 3031 | - | |||||||||||||||||||||||||
| 3032 | if (it.value().timestamp < oldest && it.value().hits <= least_popular) { | - | ||||||||||||||||||||||||
| 3033 | oldest = it.value().timestamp; | - | ||||||||||||||||||||||||
| 3034 | least_popular = it.value().hits; | - | ||||||||||||||||||||||||
| 3035 | jt = it; | - | ||||||||||||||||||||||||
| 3036 | } | - | ||||||||||||||||||||||||
| 3037 | } | - | ||||||||||||||||||||||||
| 3038 | - | |||||||||||||||||||||||||
| 3039 | it = jt; | - | ||||||||||||||||||||||||
| 3040 | if (it != end) { | - | ||||||||||||||||||||||||
| 3041 | FC_DEBUG(" %p: timestamp %4u hits %2u ref %2d/%2d, type %d", dead code: QMessageLogger(__FILE__, 3041, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, type %d", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->type()); | - | ||||||||||||||||||||||||
| 3042 | it.value().data, it.value().timestamp, it.value().hits, dead code: QMessageLogger(__FILE__, 3041, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, type %d", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->type()); | - | ||||||||||||||||||||||||
| 3043 | it.value().data->ref.load(), engineCacheCount.value(it.value().data), dead code: QMessageLogger(__FILE__, 3041, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, type %d", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->type()); | - | ||||||||||||||||||||||||
| 3044 | it.value().data->type()); dead code: QMessageLogger(__FILE__, 3041, __PRETTY_FUNCTION__).debug(" %p: timestamp %4u hits %2u ref %2d/%2d, type %d", it.value().data, it.value().timestamp, it.value().hits, it.value().data->ref.load(), engineCacheCount.value(it.value().data), it.value().data->type()); | - | ||||||||||||||||||||||||
| 3045 | - | |||||||||||||||||||||||||
| 3046 | QFontEngine *fontEngine = it.value().data; | - | ||||||||||||||||||||||||
| 3047 | // get rid of all occurrences | - | ||||||||||||||||||||||||
| 3048 | it = engineCache.begin(); | - | ||||||||||||||||||||||||
| 3049 | while (it != engineCache.end()) { | - | ||||||||||||||||||||||||
| 3050 | if (it.value().data == fontEngine) { | - | ||||||||||||||||||||||||
| 3051 | fontEngine->ref.deref(); | - | ||||||||||||||||||||||||
| 3052 | it = engineCache.erase(it); | - | ||||||||||||||||||||||||
| 3053 | } else { | - | ||||||||||||||||||||||||
| 3054 | ++it; | - | ||||||||||||||||||||||||
| 3055 | } | - | ||||||||||||||||||||||||
| 3056 | } | - | ||||||||||||||||||||||||
| 3057 | // and delete the last occurrence | - | ||||||||||||||||||||||||
| 3058 | Q_ASSERT(fontEngine->ref.load() == 0); | - | ||||||||||||||||||||||||
| 3059 | decreaseCost(fontEngine->cache_cost); | - | ||||||||||||||||||||||||
| 3060 | delete fontEngine; | - | ||||||||||||||||||||||||
| 3061 | engineCacheCount.remove(fontEngine); | - | ||||||||||||||||||||||||
| 3062 | - | |||||||||||||||||||||||||
| 3063 | cost_decreased = true; | - | ||||||||||||||||||||||||
| 3064 | } | - | ||||||||||||||||||||||||
| 3065 | } while (cost_decreased && total_cost > max_cost); | - | ||||||||||||||||||||||||
| 3066 | } | - | ||||||||||||||||||||||||
| 3067 | - | |||||||||||||||||||||||||
| 3068 | - | |||||||||||||||||||||||||
| 3069 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
| 3070 | QDebug operator<<(QDebug stream, const QFont &font) | - | ||||||||||||||||||||||||
| 3071 | { | - | ||||||||||||||||||||||||
| 3072 | return stream << "QFont(" << font.toString() << ')'; | - | ||||||||||||||||||||||||
| 3073 | } | - | ||||||||||||||||||||||||
| 3074 | #endif | - | ||||||||||||||||||||||||
| 3075 | - | |||||||||||||||||||||||||
| 3076 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |